Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Zend_Pdf_Parser Class Reference

Public Member Functions

 getPDFLength ()
 
 getPDFString ()
 
 getPDFVersion ()
 
 getTrailer ()
 
 __construct ($source, Zend_Pdf_ElementFactory_Interface $factory, $load)
 
 __destruct ()
 

Detailed Description

Definition at line 38 of file Parser.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $source,
Zend_Pdf_ElementFactory_Interface  $factory,
  $load 
)

Object constructor

Note: PHP duplicates string, which is sent by value, only of it's updated. Thus we don't need to care about overhead

Parameters
mixed$source
Zend_Pdf_ElementFactory_Interface$factory
boolean$load
Exceptions
Zend_Exception
Todo:
To support PDF versions 1.5 (Acrobat 6) and PDF version 1.7 (Acrobat 7) Stream compression filter must be implemented (for compressed object streams). Cross reference streams must be implemented

Go to end of cross-reference table offset

Go to the start of cross-reference table offset

Go to the end of 'startxref' keyword

Go to the white space (eol marker) before 'startxref' keyword

Definition at line 362 of file Parser.php.

363  {
364  if ($load) {
365  if (($pdfFile = @fopen($source, 'rb')) === false ) {
366  #require_once 'Zend/Pdf/Exception.php';
367  throw new Zend_Pdf_Exception( "Can not open '$source' file for reading." );
368  }
369 
370  $data = '';
371  $byteCount = filesize($source);
372  while ($byteCount > 0 && !feof($pdfFile)) {
373  $nextBlock = fread($pdfFile, $byteCount);
374  if ($nextBlock === false) {
375  #require_once 'Zend/Pdf/Exception.php';
376  throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
377  }
378 
379  $data .= $nextBlock;
380  $byteCount -= strlen($nextBlock);
381  }
382  if ($byteCount != 0) {
383  #require_once 'Zend/Pdf/Exception.php';
384  throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
385  }
386  fclose($pdfFile);
387 
388  $this->_stringParser = new Zend_Pdf_StringParser($data, $factory);
389  } else {
390  $this->_stringParser = new Zend_Pdf_StringParser($source, $factory);
391  }
392 
393  $pdfVersionComment = $this->_stringParser->readComment();
394  if (substr($pdfVersionComment, 0, 5) != '%PDF-') {
395  #require_once 'Zend/Pdf/Exception.php';
396  throw new Zend_Pdf_Exception('File is not a PDF.');
397  }
398 
399  $pdfVersion = substr($pdfVersionComment, 5);
400  if (version_compare($pdfVersion, '0.9', '<') ||
401  version_compare($pdfVersion, '1.61', '>=')
402  ) {
409  #require_once 'Zend/Pdf/Exception.php';
410  throw new Zend_Pdf_Exception(sprintf('Unsupported PDF version. Zend_Pdf supports PDF 1.0-1.4. Current version - \'%f\'', $pdfVersion));
411  }
412  $this->_pdfVersion = $pdfVersion;
413 
414  $this->_stringParser->offset = strrpos($this->_stringParser->data, '%%EOF');
415  if ($this->_stringParser->offset === false ||
416  strlen($this->_stringParser->data) - $this->_stringParser->offset > 7) {
417  #require_once 'Zend/Pdf/Exception.php';
418  throw new Zend_Pdf_Exception('Pdf file syntax error. End-of-fle marker expected at the end of file.');
419  }
420 
421  $this->_stringParser->offset--;
425  while (Zend_Pdf_StringParser::isWhiteSpace( ord($this->_stringParser->data[$this->_stringParser->offset]) )&&
426  ($this->_stringParser->offset > 0)) {
427  $this->_stringParser->offset--;
428  }
432  while ( (!Zend_Pdf_StringParser::isWhiteSpace( ord($this->_stringParser->data[$this->_stringParser->offset]) ))&&
433  ($this->_stringParser->offset > 0)) {
434  $this->_stringParser->offset--;
435  }
439  while (Zend_Pdf_StringParser::isWhiteSpace( ord($this->_stringParser->data[$this->_stringParser->offset]) )&&
440  ($this->_stringParser->offset > 0)) {
441  $this->_stringParser->offset--;
442  }
446  $this->_stringParser->offset -= 9;
447 
448  $nextLexeme = $this->_stringParser->readLexeme();
449  if ($nextLexeme != 'startxref') {
450  #require_once 'Zend/Pdf/Exception.php';
451  throw new Zend_Pdf_Exception(sprintf('Pdf file syntax error. \'startxref\' keyword expected. Offset - 0x%X.', $this->_stringParser->offset-strlen($nextLexeme)));
452  }
453 
454  $startXref = $this->_stringParser->readLexeme();
455  if (!ctype_digit($startXref)) {
456  #require_once 'Zend/Pdf/Exception.php';
457  throw new Zend_Pdf_Exception(sprintf('Pdf file syntax error. Cross-reference table offset must contain only digits. Offset - 0x%X.', $this->_stringParser->offset-strlen($nextLexeme)));
458  }
459 
460  $this->_trailer = $this->_loadXRefTable($startXref);
461  $factory->setObjectCount($this->_trailer->Size->value);
462  }
$source
Definition: source.php:23
static isWhiteSpace($chCode)

◆ __destruct()

__destruct ( )

Object destructor

Definition at line 468 of file Parser.php.

469  {
470  $this->_stringParser->cleanUp();
471  }

Member Function Documentation

◆ getPDFLength()

getPDFLength ( )

Get length of source PDF

Returns
integer

Definition at line 67 of file Parser.php.

68  {
69  return strlen($this->_stringParser->data);
70  }

◆ getPDFString()

getPDFString ( )

Get PDF String

Returns
string

Definition at line 77 of file Parser.php.

78  {
79  return $this->_stringParser->data;
80  }

◆ getPDFVersion()

getPDFVersion ( )

PDF version specified in the file header

Returns
string

Definition at line 87 of file Parser.php.

88  {
89  return $this->_pdfVersion;
90  }

◆ getTrailer()

getTrailer ( )

Get Trailer object

Returns
Zend_Pdf_Trailer_Keeper

Definition at line 346 of file Parser.php.

347  {
348  return $this->_trailer;
349  }

The documentation for this class was generated from the following file: