Пример #1
0
 /**
  * Rollback document $steps number of revisions.
  * This method must be invoked before any changes, applied to the document.
  * Otherwise behavior is undefined.
  *
  * @param integer $steps
  */
 public function rollback($steps)
 {
     for ($count = 0; $count < $steps; $count++) {
         if ($this->_trailer->getPrev() !== null && $this->_trailer->getPrev()->Root !== null) {
             $this->_trailer = $this->_trailer->getPrev();
         } else {
             break;
         }
     }
     $this->_objFactory->setObjectCount($this->_trailer->Size->value);
     // Mark content as modified to force new trailer generation at render time
     $this->_trailer->Root->touch();
     $this->pages = array();
     $this->_loadPages($this->_trailer->Root->Pages);
 }
Пример #2
0
 /**
  * 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
  *
  * @param mixed $source
  * @param Zend_Pdf_ElementFactory $factory
  * @param boolean $load
  * @throws Zend_Exception
  */
 public function __construct($source, Zend_Pdf_ElementFactory $factory, $load)
 {
     if ($load) {
         if (($pdfFile = @fopen($source, 'rb')) === false) {
             throw new Zend_Pdf_Exception("Can not open '{$source}' file for reading.");
         }
         $byteCount = filesize($source);
         $data = '';
         while ($byteCount > 0 && ($nextBlock = fread($pdfFile, $byteCount)) != false) {
             $data .= $nextBlock;
             $byteCount -= strlen($nextBlock);
         }
         fclose($pdfFile);
         $this->_stringParser = new Zend_Pdf_StringParser($data, $factory);
     } else {
         $this->_stringParser = new Zend_Pdf_StringParser($source, $factory);
     }
     $pdfVersionComment = $this->_stringParser->readComment();
     if (substr($pdfVersionComment, 0, 5) != '%PDF-') {
         throw new Zend_Pdf_Exception('File is not a PDF.');
     }
     $pdfVersion = (double) substr($pdfVersionComment, 5);
     if ($pdfVersion < 0.9 || $pdfVersion >= 1.61) {
         /**
          * @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
          */
         throw new Zend_Pdf_Exception(sprintf('Unsupported PDF version. Zend_Pdf supports PDF 1.0-1.4. Current version - \'%f\'', $pdfVersion));
     }
     $this->_stringParser->offset = strrpos($this->_stringParser->data, '%%EOF');
     if ($this->_stringParser->offset === false || strlen($this->_stringParser->data) - $this->_stringParser->offset > 7) {
         throw new Zend_Pdf_Exception('Pdf file syntax error. End-of-fle marker expected at the end of file.');
     }
     $this->_stringParser->offset--;
     /**
      * Go to end of cross-reference table offset
      */
     while (Zend_Pdf_StringParser::isWhiteSpace(ord($this->_stringParser->data[$this->_stringParser->offset])) && $this->_stringParser->offset > 0) {
         $this->_stringParser->offset--;
     }
     /**
      * Go to the start of cross-reference table offset
      */
     while (!Zend_Pdf_StringParser::isWhiteSpace(ord($this->_stringParser->data[$this->_stringParser->offset])) && $this->_stringParser->offset > 0) {
         $this->_stringParser->offset--;
     }
     /**
      * Go to the end of 'startxref' keyword
      */
     while (Zend_Pdf_StringParser::isWhiteSpace(ord($this->_stringParser->data[$this->_stringParser->offset])) && $this->_stringParser->offset > 0) {
         $this->_stringParser->offset--;
     }
     /**
      * Go to the white space (eol marker) before 'startxref' keyword
      */
     $this->_stringParser->offset -= 9;
     $nextLexeme = $this->_stringParser->readLexeme();
     if ($nextLexeme != 'startxref') {
         throw new Zend_Pdf_Exception(sprintf('Pdf file syntax error. \'startxref\' keyword expected. Offset - 0x%X.', $this->_stringParser->offset - strlen($nextLexeme)));
     }
     $startXref = $this->_stringParser->readLexeme();
     if (!ctype_digit($startXref)) {
         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)));
     }
     $this->_trailer = $this->_loadXRefTable($startXref);
     $factory->setObjectCount($this->_trailer->Size->value);
 }