/**
  * Object constructor
  *
  * @param Zend_Pdf_Element $rootDictionary root of name dictionary
  */
 public function __construct(Zend_Pdf_Element $rootDictionary)
 {
     if ($rootDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Name tree root must be a dictionary.');
     }
     $intermediateNodes = array();
     $leafNodes = array();
     if ($rootDictionary->Kids !== null) {
         $intermediateNodes[] = $rootDictionary;
     } else {
         $leafNodes[] = $rootDictionary;
     }
     while (count($intermediateNodes) != 0) {
         $newIntermediateNodes = array();
         foreach ($intermediateNodes as $node) {
             foreach ($node->Kids->items as $childNode) {
                 if ($childNode->Kids !== null) {
                     $newIntermediateNodes[] = $childNode;
                 } else {
                     $leafNodes[] = $childNode;
                 }
             }
         }
         $intermediateNodes = $newIntermediateNodes;
     }
     foreach ($leafNodes as $leafNode) {
         $destinationsCount = count($leafNode->Names->items) / 2;
         for ($count = 0; $count < $destinationsCount; $count++) {
             $this->_items[$leafNode->Names->items[$count * 2]->value] = $leafNode->Names->items[$count * 2 + 1];
         }
     }
 }
Beispiel #2
0
 /**
  * Explicit destination object constructor
  *
  * @param Zend_Pdf_Element $destinationArray
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $destinationArray)
 {
     if ($destinationArray->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Explicit destination resource Array must be a direct or an indirect array object.');
     }
     $this->_destinationArray = $destinationArray;
     switch (count($this->_destinationArray->items)) {
         case 0:
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Destination array must contain a page reference.');
             break;
         case 1:
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Destination array must contain a destination type name.');
             break;
         default:
             // Do nothing
             break;
     }
     switch ($this->_destinationArray->items[0]->getType()) {
         case Zend_Pdf_Element::TYPE_NUMERIC:
             $this->_isRemote = true;
             break;
         case Zend_Pdf_Element::TYPE_DICTIONARY:
             $this->_isRemote = false;
             break;
         default:
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Destination target must be a page number or page dictionary object.');
             break;
     }
 }
Beispiel #3
0
 /**
  * Parse resource and return it as an Action or Explicit Destination
  *
  * $param Zend_Pdf_Element $resource
  * @return Zend_Pdf_Destination|
  * @throws Zend_Pdf_Exception
  */
 public static function load(Zend_Pdf_Element $resource)
 {
     require_once 'Zend/Pdf/Element.php';
     if ($resource->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
         if (($resource->Type === null || $resource->Type->value == 'Action') && $resource->S !== null) {
             // It's a well-formed action, load it
             require_once 'Zend/Pdf/Action.php';
             return Zend_Pdf_Action::load($resource);
         } else {
             if ($resource->D !== null) {
                 // It's a destination
                 $resource = $resource->D;
             } else {
                 require_once 'Zend/Pdf/Exception.php';
                 throw new Zend_Pdf_Exception('Wrong resource type.');
             }
         }
     }
     if ($resource->getType() == Zend_Pdf_Element::TYPE_ARRAY || $resource->getType() == Zend_Pdf_Element::TYPE_NAME || $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
         // Resource is an array, just treat it as an explicit destination array
         require_once 'Zend/Pdf/Destination.php';
         return Zend_Pdf_Destination::load($resource);
     } else {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Wrong resource type.');
     }
 }
Beispiel #4
0
 /**
  * Named destination object constructor
  *
  * @param Zend_Pdf_Element $resource
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $resource)
 {
     if ($resource->getType() != Zend_Pdf_Element::TYPE_NAME && $resource->getType() != Zend_Pdf_Element::TYPE_STRING) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Named destination resource must be a PDF name or a PDF string.');
     }
     $this->_nameElement = $resource;
 }
 /**
  * Load Destination object from a specified resource
  *
  * @internal
  * @param Zend_Pdf_Element $resource
  * @return Zend_Pdf_Destination
  */
 public static function load(Zend_Pdf_Element $resource)
 {
     require_once 'Zend/Pdf/Element.php';
     if ($resource->getType() == Zend_Pdf_Element::TYPE_NAME || $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
         require_once 'Zend/Pdf/Destination/Named.php';
         return new Zend_Pdf_Destination_Named($resource);
     }
     if ($resource->getType() != Zend_Pdf_Element::TYPE_ARRAY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('An explicit destination must be a direct or an indirect array object.');
     }
     if (count($resource->items) < 2) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('An explicit destination array must contain at least two elements.');
     }
     switch ($resource->items[1]->value) {
         case 'XYZ':
             require_once 'Zend/Pdf/Destination/Zoom.php';
             return new Zend_Pdf_Destination_Zoom($resource);
             break;
         case 'Fit':
             require_once 'Zend/Pdf/Destination/Fit.php';
             return new Zend_Pdf_Destination_Fit($resource);
             break;
         case 'FitH':
             require_once 'Zend/Pdf/Destination/FitHorizontally.php';
             return new Zend_Pdf_Destination_FitHorizontally($resource);
             break;
         case 'FitV':
             require_once 'Zend/Pdf/Destination/FitVertically.php';
             return new Zend_Pdf_Destination_FitVertically($resource);
             break;
         case 'FitR':
             require_once 'Zend/Pdf/Destination/FitRectangle.php';
             return new Zend_Pdf_Destination_FitRectangle($resource);
             break;
         case 'FitB':
             require_once 'Zend/Pdf/Destination/FitBoundingBox.php';
             return new Zend_Pdf_Destination_FitBoundingBox($resource);
             break;
         case 'FitBH':
             require_once 'Zend/Pdf/Destination/FitBoundingBoxHorizontally.php';
             return new Zend_Pdf_Destination_FitBoundingBoxHorizontally($resource);
             break;
         case 'FitBV':
             require_once 'Zend/Pdf/Destination/FitBoundingBoxVertically.php';
             return new Zend_Pdf_Destination_FitBoundingBoxVertically($resource);
             break;
         default:
             require_once 'Zend/Pdf/Destination/Unknown.php';
             return new Zend_Pdf_Destination_Unknown($resource);
             break;
     }
 }
 /**
  * Annotation object constructor
  *
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $annotationDictionary)
 {
     if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
     }
     if ($annotationDictionary->Subtype === null || $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || !in_array($annotationDictionary->Subtype->value, array(self::SUBTYPE_HIGHLIGHT, self::SUBTYPE_UNDERLINE, self::SUBTYPE_SQUIGGLY, self::SUBTYPE_STRIKEOUT))) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Subtype => Markup entry is omitted or has wrong value.');
     }
     parent::__construct($annotationDictionary);
 }
Beispiel #7
0
 /**
  * Annotation object constructor
  *
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $annotationDictionary)
 {
     if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         //$1 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
     }
     if ($annotationDictionary->Subtype === null || $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || $annotationDictionary->Subtype->value != 'Link') {
         //$1 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Subtype => Link entry is requires');
     }
     parent::__construct($annotationDictionary);
 }
Beispiel #8
0
 /**
  * Annotation object constructor
  *
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $annotationDictionary)
 {
     if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once PHP_LIBRARY_PATH . 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
     }
     if ($annotationDictionary->Subtype === null || $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME || $annotationDictionary->Subtype->value != 'FileAttachment') {
         require_once PHP_LIBRARY_PATH . 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Subtype => FileAttachment entry is requires');
     }
     parent::__construct($annotationDictionary);
 }
Beispiel #9
0
 /**
  * Parse resource and return it as an Action or Explicit Destination
  *
  * $param Zend_Pdf_Element $resource
  * @return Zend_Pdf_Destination|
  * @throws Zend_Pdf_Exception
  */
 public static function load(Zend_Pdf_Element $resource)
 {
     if ($resource->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
         // Load destination as appropriate action
         return Zend_Pdf_Action::load($resource);
     } else {
         if ($resource->getType() == Zend_Pdf_Element::TYPE_ARRAY || $resource->getType() == Zend_Pdf_Element::TYPE_NAME || $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
             // Resource is an array, just treat it as an explicit destination array
             return Zend_Pdf_Destination::load($resource);
         } else {
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Wrong resource type.');
         }
     }
 }
Beispiel #10
0
 /**
  * Object constructor.
  *
  * If resource is not a Zend_Pdf_Element object, then stream object with specified value is
  * generated.
  *
  * @param Zend_Pdf_Element|string $resource
  */
 public function __construct($resource)
 {
     if ($resource instanceof Zend_Pdf_Element_Object) {
         $this->_objectFactory = $resource->getFactory();
         $this->_resource = $resource;
         return;
     }
     require_once 'Zend/Pdf/ElementFactory.php';
     $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
     if ($resource instanceof Zend_Pdf_Element) {
         $this->_resource = $this->_objectFactory->newObject($resource);
     } else {
         $this->_resource = $this->_objectFactory->newStreamObject($resource);
     }
 }
Beispiel #11
0
 /**
  * Convert PHP value into PDF element.
  *
  * @param mixed $input
  * @return Zend_Pdf_Element
  */
 public static function phpToPdf($input)
 {
     if (is_numeric($input)) {
         //require_once 'Zend/Pdf/Element/Numeric.php';
         return new Zend_Pdf_Element_Numeric($input);
     } else {
         if (is_bool($input)) {
             //require_once 'Zend/Pdf/Element/Boolean.php';
             return new Zend_Pdf_Element_Boolean($input);
         } else {
             if (is_array($input)) {
                 $pdfElementsArray = array();
                 $isDictionary = false;
                 foreach ($input as $key => $value) {
                     if (is_string($key)) {
                         $isDictionary = true;
                     }
                     $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
                 }
                 if ($isDictionary) {
                     //require_once 'Zend/Pdf/Element/Dictionary.php';
                     return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
                 } else {
                     //require_once 'Zend/Pdf/Element/Array.php';
                     return new Zend_Pdf_Element_Array($pdfElementsArray);
                 }
             } else {
                 //require_once 'Zend/Pdf/Element/String.php';
                 return new Zend_Pdf_Element_String((string) $input);
             }
         }
     }
 }
Beispiel #12
0
 /**
  * Convert PDF element to PHP type.
  *
  * @return mixed
  */
 public function toPhp()
 {
     return $this->_value->toPhp();
 }
Beispiel #13
0
 /**
  * Load PDF action object using specified dictionary
  *
  * @internal
  * @param Zend_Pdf_Element $dictionary (It's actually Dictionary or Dictionary Object or Reference to a Dictionary Object)
  * @param SplObjectStorage $processedActions  list of already processed action dictionaries, used to avoid cyclic references
  * @return Zend_Pdf_Action
  * @throws Zend_Pdf_Exception
  */
 public static function load(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions = null)
 {
     if ($processedActions === null) {
         $processedActions = new SplObjectStorage();
     }
     require_once 'Zend/Pdf/Element.php';
     if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
     }
     if (isset($dictionary->Type) && $dictionary->Type->value != 'Action') {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Action dictionary Type entry must be set to \'Action\'.');
     }
     if ($dictionary->S === null) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Action dictionary must contain S entry');
     }
     switch ($dictionary->S->value) {
         case 'GoTo':
             require_once 'Zend/Pdf/Action/GoTo.php';
             return new Zend_Pdf_Action_GoTo($dictionary, $processedActions);
             brake;
         case 'GoToR':
             require_once 'Zend/Pdf/Action/GoToR.php';
             return new Zend_Pdf_Action_GoToR($dictionary, $processedActions);
             brake;
         case 'GoToE':
             require_once 'Zend/Pdf/Action/GoToE.php';
             return new Zend_Pdf_Action_GoToE($dictionary, $processedActions);
             brake;
         case 'Launch':
             require_once 'Zend/Pdf/Action/Launch.php';
             return new Zend_Pdf_Action_Launch($dictionary, $processedActions);
             brake;
         case 'Thread':
             require_once 'Zend/Pdf/Action/Thread.php';
             return new Zend_Pdf_Action_Thread($dictionary, $processedActions);
             brake;
         case 'URI':
             require_once 'Zend/Pdf/Action/URI.php';
             return new Zend_Pdf_Action_URI($dictionary, $processedActions);
             brake;
         case 'Sound':
             require_once 'Zend/Pdf/Action/Sound.php';
             return new Zend_Pdf_Action_Sound($dictionary, $processedActions);
             brake;
         case 'Movie':
             require_once 'Zend/Pdf/Action/Movie.php';
             return new Zend_Pdf_Action_Movie($dictionary, $processedActions);
             brake;
         case 'Hide':
             require_once 'Zend/Pdf/Action/Hide.php';
             return new Zend_Pdf_Action_Hide($dictionary, $processedActions);
             brake;
         case 'Named':
             require_once 'Zend/Pdf/Action/Named.php';
             return new Zend_Pdf_Action_Named($dictionary, $processedActions);
             brake;
         case 'SubmitForm':
             require_once 'Zend/Pdf/Action/SubmitForm.php';
             return new Zend_Pdf_Action_SubmitForm($dictionary, $processedActions);
             brake;
         case 'ResetForm':
             require_once 'Zend/Pdf/Action/ResetForm.php';
             return new Zend_Pdf_Action_ResetForm($dictionary, $processedActions);
             brake;
         case 'ImportData':
             require_once 'Zend/Pdf/Action/ImportData.php';
             return new Zend_Pdf_Action_ImportData($dictionary, $processedActions);
             brake;
         case 'JavaScript':
             require_once 'Zend/Pdf/Action/JavaScript.php';
             return new Zend_Pdf_Action_JavaScript($dictionary, $processedActions);
             brake;
         case 'SetOCGState':
             require_once 'Zend/Pdf/Action/SetOCGState.php';
             return new Zend_Pdf_Action_SetOCGState($dictionary, $processedActions);
             brake;
         case 'Rendition':
             require_once 'Zend/Pdf/Action/Rendition.php';
             return new Zend_Pdf_Action_Rendition($dictionary, $processedActions);
             brake;
         case 'Trans':
             require_once 'Zend/Pdf/Action/Trans.php';
             return new Zend_Pdf_Action_Trans($dictionary, $processedActions);
             brake;
         case 'GoTo3DView':
             require_once 'Zend/Pdf/Action/GoTo3DView.php';
             return new Zend_Pdf_Action_GoTo3DView($dictionary, $processedActions);
             brake;
         default:
             require_once 'Zend/Pdf/Action/Unknown.php';
             return new Zend_Pdf_Action_Unknown($dictionary, $processedActions);
             brake;
     }
 }
 /**
  * Annotation object constructor
  *
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $annotationDictionary)
 {
     if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
     }
     $this->_annotationDictionary = $annotationDictionary;
     if ($this->_annotationDictionary->Type !== null && $this->_annotationDictionary->Type->value != 'Annot') {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Wrong resource type. \'Annot\' expected.');
     }
     if ($this->_annotationDictionary->Rect === null) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('\'Rect\' dictionary entry is required.');
     }
     if (count($this->_annotationDictionary->Rect->items) != 4 || $this->_annotationDictionary->Rect->items[0]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[1]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[2]->getType() != Zend_Pdf_Element::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[3]->getType() != Zend_Pdf_Element::TYPE_NUMERIC) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('\'Rect\' dictionary entry must be an array of four numeric elements.');
     }
 }
 /**
  * Set top level parent indirect object.
  *
  * @param Zend_Pdf_Element_Object $parent
  */
 public function setParentObject(Zend_Pdf_Element_Object $parent)
 {
     parent::setParentObject($parent);
     foreach ($this->items as $item) {
         $item->setParentObject($parent);
     }
 }
Beispiel #16
0
    /**
     * Render the completed PDF to a string.
     * If $newSegmentOnly is true and it's not a new document,
     * then only appended part of PDF is returned.
     *
     * @param boolean $newSegmentOnly
     * @param resource $outputStream
     * @return string
     * @throws Zend_Pdf_Exception
     */
    public function render($newSegmentOnly = false, $outputStream = null)
    {
        if ($this->_isNewDocument) {
            // Drop full document first time even $newSegmentOnly is set to true
            $newSegmentOnly = false;
            $this->_isNewDocument = false;
        }

        // Save document properties if necessary
        if ($this->properties != $this->_originalProperties) {
            $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());

            foreach ($this->properties as $key => $value) {
                switch ($key) {
                    case 'Trapped':
                        switch ($value) {
                            case true:
                                $docInfo->$key = new Zend_Pdf_Element_Name('True');
                                break;

                            case false:
                                $docInfo->$key = new Zend_Pdf_Element_Name('False');
                                break;

                            case null:
                                $docInfo->$key = new Zend_Pdf_Element_Name('Unknown');
                                break;

                            default:
                                require_once 'Zend/Pdf/Exception.php';
                                throw new Zend_Pdf_Exception('Wrong Trapped document property vale: \'' . $value . '\'. Only true, false and null values are allowed.');
                                break;
                        }

                    case 'CreationDate':
                        // break intentionally omitted
                    case 'ModDate':
                        $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
                        break;

                    case 'Title':
                        // break intentionally omitted
                    case 'Author':
                        // break intentionally omitted
                    case 'Subject':
                        // break intentionally omitted
                    case 'Keywords':
                        // break intentionally omitted
                    case 'Creator':
                        // break intentionally omitted
                    case 'Producer':
                        if (extension_loaded('mbstring') === true) {
                            $detected = mb_detect_encoding($value);
                            if ($detected !== 'ASCII') {
                                $value = "\xfe\xff" . mb_convert_encoding($value, 'UTF-16', $detected);
                            }
                        }
                        $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
                        break;

                    default:
                        // Set property using PDF type based on PHP type
                        $docInfo->$key = Zend_Pdf_Element::phpToPdf($value);
                        break;
                }
            }

            $this->_trailer->Info = $docInfo;
        }

        $this->_dumpPages();
        $this->_dumpNamedDestinations();
        $this->_dumpOutlines();

        // Check, that PDF file was modified
        // File is always modified by _dumpPages() now, but future implementations may eliminate this.
        if (!$this->_objFactory->isModified()) {
            if ($newSegmentOnly) {
                // Do nothing, return
                return '';
            }

            if ($outputStream === null) {
                return $this->_trailer->getPDFString();
            } else {
                $pdfData = $this->_trailer->getPDFString();
                while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) {
                    $pdfData = substr($pdfData, $byteCount);
                }

                return '';
            }
        }

        // offset (from a start of PDF file) of new PDF file segment
        $offset = $this->_trailer->getPDFLength();
        // Last Object number in a list of free objects
        $lastFreeObject = $this->_trailer->getLastFreeObject();

        // Array of cross-reference table subsections
        $xrefTable = array();
        // Object numbers of first objects in each subsection
        $xrefSectionStartNums = array();

        // Last cross-reference table subsection
        $xrefSection = array();
        // Dummy initialization of the first element (specail case - header of linked list of free objects).
        $xrefSection[] = 0;
        $xrefSectionStartNums[] = 0;
        // Object number of last processed PDF object.
        // Used to manage cross-reference subsections.
        // Initialized by zero (specail case - header of linked list of free objects).
        $lastObjNum = 0;

        if ($outputStream !== null) {
            if (!$newSegmentOnly) {
                $pdfData = $this->_trailer->getPDFString();
                while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) {
                    $pdfData = substr($pdfData, $byteCount);
                }
            }
        } else {
            $pdfSegmentBlocks = ($newSegmentOnly) ? array() : array($this->_trailer->getPDFString());
        }

        // Iterate objects to create new reference table
        foreach ($this->_objFactory->listModifiedObjects() as $updateInfo) {
            $objNum = $updateInfo->getObjNum();

            if ($objNum - $lastObjNum != 1) {
                // Save cross-reference table subsection and start new one
                $xrefTable[] = $xrefSection;
                $xrefSection = array();
                $xrefSectionStartNums[] = $objNum;
            }

            if ($updateInfo->isFree()) {
                // Free object cross-reference table entry
                $xrefSection[]  = sprintf("%010d %05d f \n", $lastFreeObject, $updateInfo->getGenNum());
                $lastFreeObject = $objNum;
            } else {
                // In-use object cross-reference table entry
                $xrefSection[]  = sprintf("%010d %05d n \n", $offset, $updateInfo->getGenNum());

                $pdfBlock = $updateInfo->getObjectDump();
                $offset += strlen($pdfBlock);

                if ($outputStream === null) {
                    $pdfSegmentBlocks[] = $pdfBlock;
                } else {
                    while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) {
                        $pdfBlock = substr($pdfBlock, $byteCount);
                    }
                }
            }
            $lastObjNum = $objNum;
        }
        // Save last cross-reference table subsection
        $xrefTable[] = $xrefSection;

        // Modify first entry (specail case - header of linked list of free objects).
        $xrefTable[0][0] = sprintf("%010d 65535 f \n", $lastFreeObject);

        $xrefTableStr = "xref\n";
        foreach ($xrefTable as $sectId => $xrefSection) {
            $xrefTableStr .= sprintf("%d %d \n", $xrefSectionStartNums[$sectId], count($xrefSection));
            foreach ($xrefSection as $xrefTableEntry) {
                $xrefTableStr .= $xrefTableEntry;
            }
        }

        $this->_trailer->Size->value = $this->_objFactory->getObjectCount();

        $pdfBlock = $xrefTableStr
                 .  $this->_trailer->toString()
                 . "startxref\n" . $offset . "\n"
                 . "%%EOF\n";

        $this->_objFactory->cleanEnumerationShiftCache();

        if ($outputStream === null) {
            $pdfSegmentBlocks[] = $pdfBlock;

            return implode('', $pdfSegmentBlocks);
        } else {
            while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) {
                $pdfBlock = substr($pdfBlock, $byteCount);
            }

            return '';
        }
    }
Beispiel #17
0
 /**
  * Create PDF outline object using specified dictionary
  *
  * @internal
  * @param Zend_Pdf_Element $dictionary (It's actually Dictionary or Dictionary Object or Reference to a Dictionary Object)
  * @param Zend_Pdf_Action  $parentAction
  * @param SplObjectStorage $processedOutlines  List of already processed Outline dictionaries,
  *                                             used to avoid cyclic references
  * @return Zend_Pdf_Action
  * @throws Zend_Pdf_Exception
  */
 public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedDictionaries = null)
 {
     if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('$dictionary mast be an indirect dictionary object.');
     }
     if ($processedDictionaries === null) {
         $processedDictionaries = new SplObjectStorage();
     }
     $processedDictionaries->attach($dictionary);
     $this->_outlineDictionary = $dictionary;
     if ($dictionary->Count !== null) {
         if ($dictionary->Count->getType() != Zend_Pdf_Element::TYPE_NUMERIC) {
             require_once 'Zend/Pdf/Exception.php';
             throw new Zend_Pdf_Exception('Outline dictionary Count entry must be a numeric element.');
         }
         $childOutlinesCount = $dictionary->Count->value;
         if ($childOutlinesCount > 0) {
             $this->_open = true;
         }
         $childOutlinesCount = abs($childOutlinesCount);
         $childDictionary = $dictionary->First;
         $children = new SplObjectStorage();
         while ($childDictionary !== null) {
             // Check children structure for cyclic references
             if ($children->contains($childDictionary)) {
                 require_once 'Zend/Pdf/Exception.php';
                 throw new Zend_Pdf_Exception('Outline childs load error.');
             }
             if (!$processedDictionaries->contains($childDictionary)) {
                 $this->childOutlines[] = new Zend_Pdf_Outline_Loaded($childDictionary, $processedDictionaries);
             }
             $childDictionary = $childDictionary->Next;
         }
         $this->_originalChildOutlines = $this->childOutlines;
     }
 }
Beispiel #18
0
 /**
  * Dump object to a string to save within PDF file.
  *
  * $factory parameter defines operation context.
  *
  * @param Zend_Pdf_ElementFactory $factory
  * @return string
  */
 public function dump(Zend_Pdf_ElementFactory $factory)
 {
     $shift = $factory->getEnumerationShift($this->_factory);
     return $this->_objNum + $shift . " " . $this->_genNum . " obj \n" . $this->_value->toString($factory) . "\n" . "endobj\n";
 }