📄 parser.php
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @package Zend_Pdf * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License *//** Zend_Pdf_Element */require_once 'Zend/Pdf/Element.php';/** Zend_Pdf_Element_Array */require_once 'Zend/Pdf/Element/Array.php';/** Zend_Pdf_Element_String_Binary */require_once 'Zend/Pdf/Element/String/Binary.php';/** Zend_Pdf_Element_Boolean */require_once 'Zend/Pdf/Element/Boolean.php';/** Zend_Pdf_Element_Dictionary */require_once 'Zend/Pdf/Element/Dictionary.php';/** Zend_Pdf_Element_Name */require_once 'Zend/Pdf/Element/Name.php';/** Zend_Pdf_Element_Numeric */require_once 'Zend/Pdf/Element/Numeric.php';/** Zend_Pdf_Element_Object */require_once 'Zend/Pdf/Element/Object.php';/** Zend_Pdf_Element_Reference */require_once 'Zend/Pdf/Element/Reference.php';/** Zend_Pdf_Element_Object_Stream */require_once 'Zend/Pdf/Element/Object/Stream.php';/** Zend_Pdf_Element_String */require_once 'Zend/Pdf/Element/String.php';/** Zend_Pdf_Element_Null */require_once 'Zend/Pdf/Element/Null.php';/** Zend_Pdf_Element_Reference_Context */require_once 'Zend/Pdf/Element/Reference/Context.php';/** Zend_Pdf_Element_Reference_Table */require_once 'Zend/Pdf/Element/Reference/Table.php';/** Zend_Pdf_Trailer_Keeper */require_once 'Zend/Pdf/Trailer/Keeper.php';/** Zend_Pdf_ElementFactory_Interface */require_once 'Zend/Pdf/ElementFactory/Interface.php';/** Zend_Pdf_PhpArray */require_once 'Zend/Pdf/PhpArray.php';/** Zend_Pdf_StringParser */require_once 'Zend/Pdf/StringParser.php';/** Zend_Pdf_Parser_Stream */require_once 'Zend/Pdf/Parser/Stream.php';/** * PDF file parser * * @package Zend_Pdf * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */class Zend_Pdf_Parser{ /** * String parser * * @var Zend_Pdf_StringParser */ private $_stringParser; /** * Last PDF file trailer * * @var Zend_Pdf_Trailer_Keeper */ private $_trailer; /** * Get length of source PDF * * @return integer */ public function getPDFLength() { return strlen($this->_stringParser->data); } /** * Get PDF String * * @return string */ public function getPDFString() { return $this->_stringParser->data; } /** * Load XReference table and referenced objects * * @param integer $offset * @throws Zend_Pdf_Exception * @return Zend_Pdf_Trailer_Keeper */ private function _loadXRefTable($offset) { $this->_stringParser->offset = $offset; $refTable = new Zend_Pdf_Element_Reference_Table(); $context = new Zend_Pdf_Element_Reference_Context($this->_stringParser, $refTable); $this->_stringParser->setContext($context); $nextLexeme = $this->_stringParser->readLexeme(); if ($nextLexeme == 'xref') { /** * Common cross-reference table */ $this->_stringParser->skipWhiteSpace(); while ( ($nextLexeme = $this->_stringParser->readLexeme()) != 'trailer' ) { if (!ctype_digit($nextLexeme)) { throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Cross-reference table subheader values must contain only digits.', $this->_stringParser->offset-strlen($nextLexeme))); } $objNum = (int)$nextLexeme; $refCount = $this->_stringParser->readLexeme(); if (!ctype_digit($refCount)) { throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Cross-reference table subheader values must contain only digits.', $this->_stringParser->offset-strlen($refCount))); } $this->_stringParser->skipWhiteSpace(); while ($refCount > 0) { $objectOffset = substr($this->_stringParser->data, $this->_stringParser->offset, 10); if (!ctype_digit($objectOffset)) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Offset must contain only digits.', $this->_stringParser->offset)); } // Force $objectOffset to be treated as decimal instead of octal number for ($numStart = 0; $numStart < strlen($objectOffset)-1; $numStart++) { if ($objectOffset[$numStart] != '0') { break; } } $objectOffset = substr($objectOffset, $numStart); $this->_stringParser->offset += 10; if ( !Zend_Pdf_StringParser::isWhiteSpace(ord( $this->_stringParser->data[$this->_stringParser->offset] )) ) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Value separator must be white space.', $this->_stringParser->offset)); } $this->_stringParser->offset++; $genNumber = substr($this->_stringParser->data, $this->_stringParser->offset, 5); if (!ctype_digit($objectOffset)) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Offset must contain only digits.', $this->_stringParser->offset)); } // Force $objectOffset to be treated as decimal instead of octal number for ($numStart = 0; $numStart < strlen($genNumber)-1; $numStart++) { if ($genNumber[$numStart] != '0') { break; } } $genNumber = substr($genNumber, $numStart); $this->_stringParser->offset += 5; if ( !Zend_Pdf_StringParser::isWhiteSpace(ord( $this->_stringParser->data[$this->_stringParser->offset] )) ) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Value separator must be white space.', $this->_stringParser->offset)); } $this->_stringParser->offset++; $inUseKey = $this->_stringParser->data[$this->_stringParser->offset]; $this->_stringParser->offset++; switch ($inUseKey) { case 'f': // free entry unset( $this->_refTable[$objNum . ' ' . $genNumber . ' R'] ); $refTable->addReference($objNum . ' ' . $genNumber . ' R', $objectOffset, false); break; case 'n': // in-use entry $refTable->addReference($objNum . ' ' . $genNumber . ' R', $objectOffset, true); } if ( !Zend_Pdf_StringParser::isWhiteSpace(ord( $this->_stringParser->data[$this->_stringParser->offset] )) ) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Value separator must be white space.', $this->_stringParser->offset)); } $this->_stringParser->offset++; if ( !Zend_Pdf_StringParser::isWhiteSpace(ord( $this->_stringParser->data[$this->_stringParser->offset] )) ) { throw new Zend_Pdf_Exception(sprintf('PDF file cross-reference table syntax error. Offset - 0x%X. Value separator must be white space.', $this->_stringParser->offset)); } $this->_stringParser->offset++; $refCount--; $objNum++; } } $trailerDictOffset = $this->_stringParser->offset; $trailerDict = $this->_stringParser->readElement(); if (!$trailerDict instanceof Zend_Pdf_Element_Dictionary) { throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Dictionary expected after \'trailer\' keyword.', $trailerDictOffset)); } } else { $xrefStream = $this->_stringParser->getObject($offset, $context); if (!$xrefStream instanceof Zend_Pdf_Element_Object_Stream) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -