24 #require_once 'Zend/Pdf/Element/Array.php'; 25 #require_once 'Zend/Pdf/Element/String/Binary.php'; 26 #require_once 'Zend/Pdf/Element/Boolean.php'; 27 #require_once 'Zend/Pdf/Element/Dictionary.php'; 28 #require_once 'Zend/Pdf/Element/Name.php'; 29 #require_once 'Zend/Pdf/Element/Null.php'; 30 #require_once 'Zend/Pdf/Element/Numeric.php'; 31 #require_once 'Zend/Pdf/Element/Object.php'; 32 #require_once 'Zend/Pdf/Element/Object/Stream.php'; 33 #require_once 'Zend/Pdf/Element/Reference.php'; 34 #require_once 'Zend/Pdf/Element/String.php'; 65 private $_context =
null;
72 private $_elements = array();
79 private $_objFactory =
null;
89 $this->_context =
null;
90 $this->_elements = array();
91 $this->_objFactory =
null;
102 if ($chCode == 0x00 ||
124 if ($chCode == 0x28 ||
151 $this->offset += strspn($this->data,
"\x00\t\n\f\r ", $this->offset);
153 if ($this->offset < strlen($this->data) && $this->data[$this->offset] ==
'%') {
155 $this->offset += strcspn($this->data,
"\r\n", $this->offset);
162 $this->offset += strspn($this->data,
"\x00\t\n\f\r ", $this->offset);
184 while ($this->offset < strlen($this->data))
186 if (ord($this->data[$this->offset]) != 0x0A ||
187 ord($this->data[$this->offset]) != 0x0d
207 if ($this->data[$this->offset] !=
'%') {
211 for (
$start = $this->offset;
212 $this->offset < strlen($this->data);
214 if (ord($this->data[$this->offset]) == 0x0A ||
215 ord($this->data[$this->offset]) == 0x0d
221 return substr($this->data,
$start, $this->offset-
$start);
234 $this->offset += strspn($this->data,
"\x00\t\n\f\r ", $this->offset);
236 if ($this->offset < strlen($this->data) && $this->data[$this->offset] ==
'%') {
237 $this->offset += strcspn($this->data,
"\r\n", $this->offset);
243 if ($this->offset >= strlen($this->data)) {
248 strpos(
'()<>[]{}/%', $this->data[$this->offset]) !==
false ) {
250 switch (substr($this->data, $this->offset, 2)) {
262 return $this->data[$this->offset++];
268 if( version_compare( phpversion(),
'5.2.5' ) >= 0) {
269 $compare =
"()<>[]{}/%\x00\t\n\f\r ";
271 $compare =
"()<>[]{}/%\x00\t\n\r ";
274 $this->offset += strcspn($this->data, $compare, $this->offset);
276 return substr($this->data,
$start, $this->offset -
$start);
289 if ($nextLexeme ===
null) {
298 switch ($nextLexeme) {
300 return ($this->_elements[] = $this->_readString());
303 return ($this->_elements[] = $this->_readBinaryString());
311 return ($this->_elements[] = $this->_readArray());
314 return ($this->_elements[] = $this->_readDictionary());
327 #require_once 'Zend/Pdf/Exception.php'; 332 if (strcasecmp($nextLexeme,
'true') == 0) {
334 }
else if (strcasecmp($nextLexeme,
'false') == 0) {
336 }
else if (strcasecmp($nextLexeme,
'null') == 0) {
340 $ref = $this->_readReference($nextLexeme);
342 return ($this->_elements[] = $ref);
345 return ($this->_elements[] = $this->_readNumeric($nextLexeme));
357 private function _readString()
362 $this->offset += strcspn($this->data,
'()\\', $this->offset);
364 while ($this->offset < strlen($this->data)) {
365 switch (ord( $this->data[$this->offset] )) {
380 if ($openedBrackets == 0) {
384 $this->offset += strcspn($this->data,
'()\\', $this->offset);
386 if ($openedBrackets != 0) {
387 #require_once 'Zend/Pdf/Exception.php'; 388 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Unexpected end of file while string reading. Offset - 0x%X. \')\' expected.',
$start));
393 $this->offset -
$start - 1) ));
404 private function _readBinaryString()
408 $this->offset += strspn($this->data,
"\x00\t\n\f\r 0123456789abcdefABCDEF", $this->offset);
410 if ($this->offset >= strlen($this->data) - 1) {
411 #require_once 'Zend/Pdf/Exception.php'; 412 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Unexpected end of file while reading binary string. Offset - 0x%X. \'>\' expected.',
$start));
415 if ($this->data[$this->offset++] !=
'>') {
416 #require_once 'Zend/Pdf/Exception.php'; 417 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Unexpected character while binary string reading. Offset - 0x%X.', $this->offset));
423 $this->offset -
$start - 1) ));
434 private function _readArray()
438 while ( strlen($nextLexeme = $this->
readLexeme()) != 0 ) {
439 if ($nextLexeme !=
']') {
446 #require_once 'Zend/Pdf/Exception.php'; 447 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Unexpected end of file while array reading. Offset - 0x%X. \']\' expected.', $this->offset));
458 private function _readDictionary()
462 while ( strlen($nextLexeme = $this->
readLexeme()) != 0 ) {
463 if ($nextLexeme !=
'>>') {
464 $nameStart = $this->offset - strlen($nextLexeme);
470 #require_once 'Zend/Pdf/Exception.php'; 471 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Name object expected while dictionary reading. Offset - 0x%X.', $nameStart));
480 #require_once 'Zend/Pdf/Exception.php'; 481 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Unexpected end of file while dictionary reading. Offset - 0x%X. \'>>\' expected.', $this->offset));
491 private function _readReference($nextLexeme =
null)
495 if ($nextLexeme ===
null) {
498 $objNum = $nextLexeme;
500 if (!ctype_digit($objNum)) {
506 if (!ctype_digit($genNum)) {
529 private function _readNumeric($nextLexeme =
null)
531 if ($nextLexeme ===
null) {
556 $this->_context = $context;
557 $this->_elements = array();
560 if (!ctype_digit($objNum)) {
561 #require_once 'Zend/Pdf/Exception.php'; 562 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. Object number expected.', $this->offset - strlen($objNum)));
566 if (!ctype_digit($genNum)) {
567 #require_once 'Zend/Pdf/Exception.php'; 568 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. Object generation number expected.', $this->offset - strlen($genNum)));
572 if ($objKeyword !=
'obj') {
573 #require_once 'Zend/Pdf/Exception.php'; 574 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. \'obj\' keyword expected.', $this->offset - strlen($objKeyword)));
581 if( $nextLexeme ==
'endobj' ) {
588 foreach ($this->_elements as
$element) {
593 $this->offset = $offsetSave;
601 if ($nextLexeme !=
'stream') {
602 #require_once 'Zend/Pdf/Exception.php'; 603 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. \'endobj\' or \'stream\' keywords expected.', $this->offset - strlen($nextLexeme)));
607 #require_once 'Zend/Pdf/Exception.php'; 608 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. Stream extent must be preceded by stream dictionary.', $this->offset - strlen($nextLexeme)));
614 $streamLength = $objValue->Length->value;
620 if ($this->data[$this->offset] ==
"\r" &&
621 $this->data[$this->offset + 1] ==
"\n" ) {
623 }
else if ($this->data[$this->offset] ==
"\n" ) {
626 #require_once 'Zend/Pdf/Exception.php'; 627 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. \'stream\' must be followed by either cr-lf sequence or lf character only.', $this->offset - strlen($nextLexeme)));
632 $this->offset += $streamLength;
635 if ($nextLexeme !=
'endstream') {
636 #require_once 'Zend/Pdf/Exception.php'; 637 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. \'endstream\' keyword expected.', $this->offset - strlen($nextLexeme)));
641 if ($nextLexeme !=
'endobj') {
642 #require_once 'Zend/Pdf/Exception.php'; 643 throw new Zend_Pdf_Exception(sprintf(
'PDF file syntax error. Offset - 0x%X. \'endobj\' keyword expected.', $this->offset - strlen($nextLexeme)));
651 $this->_objFactory->resolve(),
654 foreach ($this->_elements as
$element) {
659 $this->offset = $offsetSave;
672 return strlen($this->data);
714 $this->_context = $context;
getObject($offset, Zend_Pdf_Element_Reference_Context $context)
static isDelimiter($chCode)
__construct($source, Zend_Pdf_ElementFactory_Interface $factory)
readElement($nextLexeme=null)
skipWhiteSpace($skipComment=true)
static parseIntFromStream($stream, $offset, $size)
setContext(Zend_Pdf_Element_Reference_Context $context)
static isWhiteSpace($chCode)
if(!isset($_GET['name'])) $name