예제 #1
0
 /**
  * Load pages recursively
  *
  * @param Zend_Pdf_Element_Reference $pages
  * @param array|null $attributes
  */
 protected function _loadPages(Zend_Pdf_Element_Reference $pages, $attributes = array())
 {
     if ($pages->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
         throw new Zend_Pdf_Exception('Wrong argument');
     }
     foreach ($pages->getKeys() as $property) {
         if (in_array($property, self::$_inheritableAttributes)) {
             $attributes[$property] = $pages->{$property};
             $pages->{$property} = null;
         }
     }
     foreach ($pages->Kids->items as $child) {
         if ($child->Type->value == 'Pages') {
             $this->_loadPages($child, $attributes);
         } else {
             if ($child->Type->value == 'Page') {
                 foreach (self::$_inheritableAttributes as $property) {
                     if ($child->{$property} === null && array_key_exists($property, $attributes)) {
                         /**
                          * Important note.
                          * If any attribute or dependant object is an indirect object, then it's still
                          * shared between pages.
                          */
                         if ($attributes[$property] instanceof Zend_Pdf_Element_Object || $attributes[$property] instanceof Zend_Pdf_Element_Reference) {
                             $child->{$property} = $attributes[$property];
                         } else {
                             $child->{$property} = $this->_objFactory->newObject($attributes[$property]);
                         }
                     }
                 }
                 $this->pages[] = new Core_Pdf_Page($child, $this->_objFactory);
             }
         }
     }
 }
예제 #2
0
 /**
  * Clone page, extract it and dependent objects from the current document,
  * so it can be used within other docs.
  *
  * @internal
  * @param Zend_Pdf_ElementFactory_Interface $factory
  * @param array $processed
  * @return Zend_Pdf_Page
  */
 public function clonePage($factory, &$processed)
 {
     // Clone dictionary object.
     // Do it explicitly to prevent sharing page attributes between different
     // results of clonePage() operation (other resources are still shared)
     $dictionary = new Zend_Pdf_Element_Dictionary();
     foreach ($this->_dictionary->getKeys() as $key) {
         $dictionary->{$key} = $this->_dictionary->{$key}->makeClone($factory->getFactory(), $processed, Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
     }
     $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
     $clonedPage->_attached = false;
     return $clonedPage;
 }