예제 #1
0
파일: Pdf.php 프로젝트: nhp/shopware-4
    /**
     * Creates or loads PDF document.
     *
     * If $source is null, then it creates a new document.
     *
     * If $source is a string and $load is false, then it loads document
     * from a binary string.
     *
     * If $source is a string and $load is true, then it loads document
     * from a file.

     * $revision used to roll back document to specified version
     * (0 - current version, 1 - previous version, 2 - ...)
     *
     * @param string  $source - PDF file to load
     * @param integer $revision
     * @throws Zend_Pdf_Exception
     * @return Zend_Pdf
     */
    public function __construct($source = null, $revision = null, $load = false)
    {
        require_once 'Zend/Pdf/ElementFactory.php';
        $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1);

        if ($source !== null) {
            require_once 'Zend/Pdf/Parser.php';
            $this->_parser           = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
            $this->_pdfHeaderVersion = $this->_parser->getPDFVersion();
            $this->_trailer          = $this->_parser->getTrailer();
            if ($this->_trailer->Encrypt !== null) {
                require_once 'Zend/Pdf/Exception.php';
                throw new Zend_Pdf_Exception('Encrypted document modification is not supported');
            }
            if ($revision !== null) {
                $this->rollback($revision);
            } else {
                $this->_loadPages($this->_trailer->Root->Pages);
            }

            $this->_loadNamedDestinations($this->_trailer->Root, $this->_parser->getPDFVersion());
            $this->_loadOutlines($this->_trailer->Root);

            if ($this->_trailer->Info !== null) {
                $this->properties = $this->_trailer->Info->toPhp();

                if (isset($this->properties['Trapped'])) {
                    switch ($this->properties['Trapped']) {
                        case 'True':
                            $this->properties['Trapped'] = true;
                            break;

                        case 'False':
                            $this->properties['Trapped'] = false;
                            break;

                        case 'Unknown':
                            $this->properties['Trapped'] = null;
                            break;

                        default:
                            // Wrong property value
                            // Do nothing
                            break;
                    }
                }

                $this->_originalProperties = $this->properties;
            }

            $this->_isNewDocument = false;
        } else {
            $this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;

            $trailerDictionary = new Zend_Pdf_Element_Dictionary();

            /**
             * Document id
             */
            $docId = md5(uniqid(rand(), true));   // 32 byte (128 bit) identifier
            $docIdLow  = substr($docId,  0, 16);  // first 16 bytes
            $docIdHigh = substr($docId, 16, 16);  // second 16 bytes

            $trailerDictionary->ID = new Zend_Pdf_Element_Array();
            $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdLow);
            $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdHigh);

            $trailerDictionary->Size = new Zend_Pdf_Element_Numeric(0);

            require_once 'Zend/Pdf/Trailer/Generator.php';
            $this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);

            /**
             * Document catalog indirect object.
             */
            $docCatalog = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
            $docCatalog->Type    = new Zend_Pdf_Element_Name('Catalog');
            $docCatalog->Version = new Zend_Pdf_Element_Name(Zend_Pdf::PDF_VERSION);
            $this->_trailer->Root = $docCatalog;

            /**
             * Pages container
             */
            $docPages = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
            $docPages->Type  = new Zend_Pdf_Element_Name('Pages');
            $docPages->Kids  = new Zend_Pdf_Element_Array();
            $docPages->Count = new Zend_Pdf_Element_Numeric(0);
            $docCatalog->Pages = $docPages;
        }
    }
예제 #2
0
 /**
  * Creates or loads PDF document.
  *
  * If $source is null, then it creates a new document.
  *
  * If $source is a string and $load is false, then it loads document
  * from a binary string.
  *
  * If $source is a string and $load is true, then it loads document
  * from a file.
  * $revision used to roll back document to specified version
  * (0 - currtent version, 1 - previous version, 2 - ...)
  *
  * @param string  $source - PDF file to load
  * @param integer $revision
  * @throws Zend_Pdf_Exception
  * @return Zend_Pdf
  */
 public function __construct(&$source = null, $revision = null, $load = false)
 {
     $this->_objFactory = new Zend_Pdf_ElementFactory(1);
     if ($source !== null) {
         $parser = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
         $this->_trailer = $parser->getTrailer();
         if ($revision !== null) {
             $this->rollback($revision);
         } else {
             $this->_loadPages($this->_trailer->Root->Pages);
         }
     } else {
         $trailerDictionary = new Zend_Pdf_Element_Dictionary();
         /**
          * Document id
          */
         $docId = md5(uniqid(rand(), true));
         // 32 byte (128 bit) identifier
         $docIdLow = substr($docId, 0, 16);
         // first 16 bytes
         $docIdHigh = substr($docId, 16, 16);
         // second 16 bytes
         $trailerDictionary->ID = new Zend_Pdf_Element_Array();
         $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdLow);
         $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdHigh);
         $trailerDictionary->Size = new Zend_Pdf_Element_Numeric(0);
         $this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);
         /**
          * Document catalog indirect object.
          */
         $docCatalog = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
         $docCatalog->Type = new Zend_Pdf_Element_Name('Catalog');
         $docCatalog->Version = new Zend_Pdf_Element_Name(Zend_Pdf::PDF_VERSION);
         $this->_trailer->Root = $docCatalog;
         /**
          * Pages container
          */
         $docPages = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
         $docPages->Type = new Zend_Pdf_Element_Name('Pages');
         $docPages->Kids = new Zend_Pdf_Element_Array();
         $docPages->Count = new Zend_Pdf_Element_Numeric(0);
         $docCatalog->Pages = $docPages;
     }
 }
예제 #3
0
 /**
  * Creates or loads PDF document.
  *
  * If $source is null, then it creates a new document.
  *
  * If $source is a string and $load is false, then it loads document
  * from a binary string.
  *
  * If $source is a string and $load is true, then it loads document
  * from a file.
  * $revision used to roll back document to specified version
  * (0 - currtent version, 1 - previous version, 2 - ...)
  *
  * @param string  $source - PDF file to load
  * @param integer $revision
  * @throws Zend_Pdf_Exception
  * @return Zend_Pdf
  */
 public function __construct($source = null, $revision = null, $load = false)
 {
     $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1);
     if ($source !== null) {
         $this->_parser = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
         $this->_trailer = $this->_parser->getTrailer();
         if ($revision !== null) {
             $this->rollback($revision);
         } else {
             $this->_loadPages($this->_trailer->Root->Pages);
         }
         if ($this->_trailer->Info !== null) {
             foreach ($this->_trailer->Info->getKeys() as $key) {
                 $this->properties[$key] = $this->_trailer->Info->{$key}->value;
             }
             if (isset($this->properties['Trapped'])) {
                 switch ($this->properties['Trapped']) {
                     case 'True':
                         $this->properties['Trapped'] = true;
                         break;
                     case 'False':
                         $this->properties['Trapped'] = false;
                         break;
                     case 'Unknown':
                         $this->properties['Trapped'] = null;
                         break;
                     default:
                         // Wrong property value
                         // Do nothing
                         break;
                 }
             }
             $this->_originalProperties = $this->properties;
         }
     } else {
         $trailerDictionary = new Zend_Pdf_Element_Dictionary();
         /**
          * Document id
          */
         $docId = md5(uniqid(rand(), true));
         // 32 byte (128 bit) identifier
         $docIdLow = substr($docId, 0, 16);
         // first 16 bytes
         $docIdHigh = substr($docId, 16, 16);
         // second 16 bytes
         $trailerDictionary->ID = new Zend_Pdf_Element_Array();
         $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdLow);
         $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdHigh);
         $trailerDictionary->Size = new Zend_Pdf_Element_Numeric(0);
         $this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);
         /**
          * Document catalog indirect object.
          */
         $docCatalog = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
         $docCatalog->Type = new Zend_Pdf_Element_Name('Catalog');
         $docCatalog->Version = new Zend_Pdf_Element_Name(Zend_Pdf::PDF_VERSION);
         $this->_trailer->Root = $docCatalog;
         /**
          * Pages container
          */
         $docPages = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
         $docPages->Type = new Zend_Pdf_Element_Name('Pages');
         $docPages->Kids = new Zend_Pdf_Element_Array();
         $docPages->Count = new Zend_Pdf_Element_Numeric(0);
         $docCatalog->Pages = $docPages;
     }
 }