Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Static Protected Attributes
Zend_Pdf Class Reference

Public Member Functions

 save ($filename, $updateOnly=false)
 
 __construct ($source=null, $revision=null, $load=false)
 
 revisions ()
 
 rollback ($steps)
 
 getTextFieldNames ()
 
 setTextFieldProperties ($name, $bitmask)
 
 markTextFieldAsReadOnly ($name)
 
 newPage ($param1, $param2=null)
 
 getMetadata ()
 
 setMetadata ($metadata)
 
 getJavaScript ()
 
 getOpenAction ()
 
 setOpenAction (Zend_Pdf_Target $openAction=null)
 
 getNamedDestinations ()
 
 getNamedDestination ($name)
 
 setNamedDestination ($name, $destination=null)
 
 resolveDestination (Zend_Pdf_Destination $destination, $refreshPageCollectionHashes=true)
 
 extractFonts ()
 
 extractFont ($fontName)
 
 render ($newSegmentOnly=false, $outputStream=null)
 
 setJavaScript ($javaScript)
 
 resetJavaScript ()
 
 addJavaScript ($javaScript)
 

Static Public Member Functions

static getMemoryManager ()
 
static setMemoryManager (Zend_Memory_Manager $memoryManager)
 
static parse (&$source=null, $revision=null)
 
static load ($source=null, $revision=null)
 
static pdfDate ($timestamp=null)
 

Data Fields

const PDF_VERSION = '1.4'
 
const PDF_HEADER = "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n"
 
const PDF_FORM_FIELD_READONLY = 1
 
const PDF_FORM_FIELD_REQUIRED = 2
 
const PDF_FORM_FIELD_NOEXPORT = 4
 
 $pages = array()
 
 $properties = array()
 
 $outlines = array()
 

Protected Member Functions

 _loadPages (Zend_Pdf_Element_Reference $pages, $attributes=array())
 
 _loadNamedDestinations (Zend_Pdf_Element_Reference $root, $pdfHeaderVersion)
 
 _loadOutlines (Zend_Pdf_Element_Reference $root)
 
 _loadJavaScript (Zend_Pdf_Element_Reference $root)
 
 _loadFormFields (Zend_Pdf_Element_Reference $root)
 
 _dumpPages ()
 
 _dumpNamedDestinations ()
 
 _dumpOutlines ()
 
 _refreshPagesHash ()
 
 _cleanUpAction (Zend_Pdf_Action $action, $refreshPageCollectionHashes=true)
 

Protected Attributes

 $_originalProperties = array()
 
 $_javaScript = null
 
 $_namedTargets = array()
 
 $_originalOutlines = array()
 
 $_originalOpenOutlinesCount = 0
 
 $_trailer = null
 
 $_objFactory = null
 
 $_parser
 
 $_formFields = array()
 
 $_isNewDocument = true
 
 $_pageReferences = null
 
 $_pageNumbers = null
 

Static Protected Attributes

static $_memoryManager = null
 
static $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate')
 

Detailed Description

Definition at line 84 of file Pdf.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $source = null,
  $revision = null,
  $load = false 
)

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 - ...)

Parameters
string$source- PDF file to load
integer$revision
bool$load
Exceptions
Zend_Pdf_Exception
Returns
Zend_Pdf

Document id

Document catalog indirect object.

Pages container

Definition at line 322 of file Pdf.php.

323  {
324  #require_once 'Zend/Pdf/ElementFactory.php';
325  $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1);
326 
327  if ($source !== null) {
328  #require_once 'Zend/Pdf/Parser.php';
329  $this->_parser = new Zend_Pdf_Parser($source, $this->_objFactory, $load);
330  $this->_pdfHeaderVersion = $this->_parser->getPDFVersion();
331  $this->_trailer = $this->_parser->getTrailer();
332  if ($this->_trailer->Encrypt !== null) {
333  #require_once 'Zend/Pdf/Exception.php';
334  throw new Zend_Pdf_Exception('Encrypted document modification is not supported');
335  }
336  if ($revision !== null) {
337  $this->rollback($revision);
338  } else {
339  $this->_loadPages($this->_trailer->Root->Pages);
340  }
341 
342  $this->_loadNamedDestinations($this->_trailer->Root, $this->_parser->getPDFVersion());
343  $this->_loadOutlines($this->_trailer->Root);
344  $this->_loadJavaScript($this->_trailer->Root);
345  $this->_loadFormFields($this->_trailer->Root);
346 
347  if ($this->_trailer->Info !== null) {
348  $this->properties = $this->_trailer->Info->toPhp();
349 
350  if (isset($this->properties['Trapped'])) {
351  switch ($this->properties['Trapped']) {
352  case 'True':
353  $this->properties['Trapped'] = true;
354  break;
355 
356  case 'False':
357  $this->properties['Trapped'] = false;
358  break;
359 
360  case 'Unknown':
361  $this->properties['Trapped'] = null;
362  break;
363 
364  default:
365  // Wrong property value
366  // Do nothing
367  break;
368  }
369  }
370 
371  $this->_originalProperties = $this->properties;
372  }
373 
374  $this->_isNewDocument = false;
375  } else {
376  $this->_pdfHeaderVersion = Zend_Pdf::PDF_VERSION;
377 
378  $trailerDictionary = new Zend_Pdf_Element_Dictionary();
379 
383  $docId = md5(uniqid(rand(), true)); // 32 byte (128 bit) identifier
384  $docIdLow = substr($docId, 0, 16); // first 16 bytes
385  $docIdHigh = substr($docId, 16, 16); // second 16 bytes
386 
387  $trailerDictionary->ID = new Zend_Pdf_Element_Array();
388  $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdLow);
389  $trailerDictionary->ID->items[] = new Zend_Pdf_Element_String_Binary($docIdHigh);
390 
391  $trailerDictionary->Size = new Zend_Pdf_Element_Numeric(0);
392 
393  #require_once 'Zend/Pdf/Trailer/Generator.php';
394  $this->_trailer = new Zend_Pdf_Trailer_Generator($trailerDictionary);
395 
399  $docCatalog = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
400  $docCatalog->Type = new Zend_Pdf_Element_Name('Catalog');
401  $docCatalog->Version = new Zend_Pdf_Element_Name(Zend_Pdf::PDF_VERSION);
402  $this->_trailer->Root = $docCatalog;
403 
407  $docPages = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
408  $docPages->Type = new Zend_Pdf_Element_Name('Pages');
409  $docPages->Kids = new Zend_Pdf_Element_Array();
410  $docPages->Count = new Zend_Pdf_Element_Numeric(0);
411  $docCatalog->Pages = $docPages;
412  }
413  }
_loadPages(Zend_Pdf_Element_Reference $pages, $attributes=array())
Definition: Pdf.php:465
$source
Definition: source.php:23
_loadFormFields(Zend_Pdf_Element_Reference $root)
Definition: Pdf.php:623
const PDF_VERSION
Definition: Pdf.php:91
$properties
Definition: Pdf.php:131
_loadNamedDestinations(Zend_Pdf_Element_Reference $root, $pdfHeaderVersion)
Definition: Pdf.php:513
_loadJavaScript(Zend_Pdf_Element_Reference $root)
Definition: Pdf.php:599
static createFactory($objCount)
_loadOutlines(Zend_Pdf_Element_Reference $root)
Definition: Pdf.php:554
rollback($steps)
Definition: Pdf.php:440

Member Function Documentation

◆ _cleanUpAction()

_cleanUpAction ( Zend_Pdf_Action  $action,
  $refreshPageCollectionHashes = true 
)
protected

Walk through action and its chained actions tree and remove nodes if they are GoTo actions with an unresolved target.

Returns null if root node is deleted or updated action overwise.

Todo:
Give appropriate name and make method public
Parameters
Zend_Pdf_Action$action
bool$refreshPageCollectionHashesRefresh page collection hashes before processing
Returns
Zend_Pdf_Action|null

Definition at line 1179 of file Pdf.php.

1180  {
1181  if ($this->_pageReferences === null || $refreshPageCollectionHashes) {
1182  $this->_refreshPagesHash();
1183  }
1184 
1185  // Named target is an action
1186  if ($action instanceof Zend_Pdf_Action_GoTo &&
1187  $this->resolveDestination($action->getDestination(), false) === null) {
1188  // Action itself is a GoTo action with an unresolved destination
1189  return null;
1190  }
1191 
1192  // Walk through child actions
1193  $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST);
1194 
1195  $actionsToClean = array();
1196  $deletionCandidateKeys = array();
1197  foreach ($iterator as $chainedAction) {
1198  if ($chainedAction instanceof Zend_Pdf_Action_GoTo &&
1199  $this->resolveDestination($chainedAction->getDestination(), false) === null) {
1200  // Some child action is a GoTo action with an unresolved destination
1201  // Mark it as a candidate for deletion
1202  $actionsToClean[] = $iterator->getSubIterator();
1203  $deletionCandidateKeys[] = $iterator->getSubIterator()->key();
1204  }
1205  }
1206  foreach ($actionsToClean as $id => $action) {
1207  unset($action->next[$deletionCandidateKeys[$id]]);
1208  }
1209 
1210  return $action;
1211  }
$id
Definition: fieldset.phtml:14
_refreshPagesHash()
Definition: Pdf.php:1098
resolveDestination(Zend_Pdf_Destination $destination, $refreshPageCollectionHashes=true)
Definition: Pdf.php:1122

◆ _dumpNamedDestinations()

_dumpNamedDestinations ( )
protected

Dump named destinations

Todo:
Create a balanced tree instead of plain structure.

Definition at line 817 of file Pdf.php.

818  {
819  ksort($this->_namedTargets, SORT_STRING);
820 
821  $destArrayItems = array();
822  foreach ($this->_namedTargets as $name => $destination) {
823  $destArrayItems[] = new Zend_Pdf_Element_String($name);
824 
825  if ($destination instanceof Zend_Pdf_Target) {
826  $destArrayItems[] = $destination->getResource();
827  } else {
828  #require_once 'Zend/Pdf/Exception.php';
829  throw new Zend_Pdf_Exception('PDF named destinations must be a Zend_Pdf_Target object.');
830  }
831  }
832  $destArray = $this->_objFactory->newObject(new Zend_Pdf_Element_Array($destArrayItems));
833 
834  $DestTree = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
835  $DestTree->Names = $destArray;
836 
837  $root = $this->_trailer->Root;
838 
839  if ($root->Names === null) {
840  $root->touch();
841  $root->Names = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
842  } else {
843  $root->Names->touch();
844  }
845  $root->Names->Dests = $DestTree;
846  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _dumpOutlines()

_dumpOutlines ( )
protected

Dump outlines recursively

Definition at line 851 of file Pdf.php.

852  {
853  $root = $this->_trailer->Root;
854 
855  if ($root->Outlines === null) {
856  if (count($this->outlines) == 0) {
857  return;
858  } else {
859  $root->Outlines = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
860  $root->Outlines->Type = new Zend_Pdf_Element_Name('Outlines');
861  $updateOutlinesNavigation = true;
862  }
863  } else {
864  $updateOutlinesNavigation = false;
865  if (count($this->_originalOutlines) != count($this->outlines)) {
866  // If original and current outlines arrays have different size then outlines list was updated
867  $updateOutlinesNavigation = true;
868  } else if ( !(array_keys($this->_originalOutlines) === array_keys($this->outlines)) ) {
869  // If original and current outlines arrays have different keys (with a glance to an order) then outlines list was updated
870  $updateOutlinesNavigation = true;
871  } else {
872  foreach ($this->outlines as $key => $outline) {
873  if ($this->_originalOutlines[$key] !== $outline) {
874  $updateOutlinesNavigation = true;
875  }
876  }
877  }
878  }
879 
880  $lastOutline = null;
881  $openOutlinesCount = 0;
882  if ($updateOutlinesNavigation) {
883  $root->Outlines->touch();
884  $root->Outlines->First = null;
885 
886  foreach ($this->outlines as $outline) {
887  if ($lastOutline === null) {
888  // First pass. Update Outlines dictionary First entry using corresponding value
889  $lastOutline = $outline->dumpOutline($this->_objFactory, $updateOutlinesNavigation, $root->Outlines);
890  $root->Outlines->First = $lastOutline;
891  } else {
892  // Update previous outline dictionary Next entry (Prev is updated within dumpOutline() method)
893  $currentOutlineDictionary = $outline->dumpOutline($this->_objFactory, $updateOutlinesNavigation, $root->Outlines, $lastOutline);
894  $lastOutline->Next = $currentOutlineDictionary;
895  $lastOutline = $currentOutlineDictionary;
896  }
897  $openOutlinesCount += $outline->openOutlinesCount();
898  }
899 
900  $root->Outlines->Last = $lastOutline;
901  } else {
902  foreach ($this->outlines as $outline) {
903  $lastOutline = $outline->dumpOutline($this->_objFactory, $updateOutlinesNavigation, $root->Outlines, $lastOutline);
904  $openOutlinesCount += $outline->openOutlinesCount();
905  }
906  }
907 
908  if ($openOutlinesCount != $this->_originalOpenOutlinesCount) {
909  $root->Outlines->touch;
910  $root->Outlines->Count = new Zend_Pdf_Element_Numeric($openOutlinesCount);
911  }
912  }

◆ _dumpPages()

_dumpPages ( )
protected

Orginize pages to tha pages tree structure.

Todo:

atomatically attach page to the document, if it's not done yet.

check, that page is attached to the current document

Todo:
Dump pages as a balanced tree instead of a plain set.

Definition at line 724 of file Pdf.php.

725  {
726  $root = $this->_trailer->Root;
727  $pagesContainer = $root->Pages;
728 
729  $pagesContainer->touch();
730  $pagesContainer->Kids->items = array();
731 
732  foreach ($this->pages as $page ) {
733  $page->render($this->_objFactory);
734 
735  $pageDictionary = $page->getPageDictionary();
736  $pageDictionary->touch();
737  $pageDictionary->Parent = $pagesContainer;
738 
739  $pagesContainer->Kids->items[] = $pageDictionary;
740  }
741 
742  $this->_refreshPagesHash();
743 
744  $pagesContainer->Count->touch();
745  $pagesContainer->Count->value = count($this->pages);
746 
747 
748  // Refresh named destinations list
749  foreach ($this->_namedTargets as $name => $namedTarget) {
750  if ($namedTarget instanceof Zend_Pdf_Destination_Explicit) {
751  // Named target is an explicit destination
752  if ($this->resolveDestination($namedTarget, false) === null) {
753  unset($this->_namedTargets[$name]);
754  }
755  } else if ($namedTarget instanceof Zend_Pdf_Action) {
756  // Named target is an action
757  if ($this->_cleanUpAction($namedTarget, false) === null) {
758  // Action is a GoTo action with an unresolved destination
759  unset($this->_namedTargets[$name]);
760  }
761  } else {
762  #require_once 'Zend/Pdf/Exception.php';
763  throw new Zend_Pdf_Exception('Wrong type of named targed (\'' . get_class($namedTarget) . '\').');
764  }
765  }
766 
767  // Refresh outlines
768  #require_once 'Zend/Pdf/RecursivelyIteratableObjectsContainer.php';
769  $iterator = new RecursiveIteratorIterator(new Zend_Pdf_RecursivelyIteratableObjectsContainer($this->outlines), RecursiveIteratorIterator::SELF_FIRST);
770  foreach ($iterator as $outline) {
771  $target = $outline->getTarget();
772 
773  if ($target !== null) {
774  if ($target instanceof Zend_Pdf_Destination) {
775  // Outline target is a destination
776  if ($this->resolveDestination($target, false) === null) {
777  $outline->setTarget(null);
778  }
779  } else if ($target instanceof Zend_Pdf_Action) {
780  // Outline target is an action
781  if ($this->_cleanUpAction($target, false) === null) {
782  // Action is a GoTo action with an unresolved destination
783  $outline->setTarget(null);
784  }
785  } else {
786  #require_once 'Zend/Pdf/Exception.php';
787  throw new Zend_Pdf_Exception('Wrong outline target.');
788  }
789  }
790  }
791 
792  $openAction = $this->getOpenAction();
793  if ($openAction !== null) {
794  if ($openAction instanceof Zend_Pdf_Action) {
795  // OpenAction is an action
796  if ($this->_cleanUpAction($openAction, false) === null) {
797  // Action is a GoTo action with an unresolved destination
798  $this->setOpenAction(null);
799  }
800  } else if ($openAction instanceof Zend_Pdf_Destination) {
801  // OpenAction target is a destination
802  if ($this->resolveDestination($openAction, false) === null) {
803  $this->setOpenAction(null);
804  }
805  } else {
806  #require_once 'Zend/Pdf/Exception.php';
807  throw new Zend_Pdf_Exception('OpenAction has to be either PDF Action or Destination.');
808  }
809  }
810  }
_cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes=true)
Definition: Pdf.php:1179
$page
Definition: pages.php:8
_refreshPagesHash()
Definition: Pdf.php:1098
resolveDestination(Zend_Pdf_Destination $destination, $refreshPageCollectionHashes=true)
Definition: Pdf.php:1122
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _loadFormFields()

_loadFormFields ( Zend_Pdf_Element_Reference  $root)
protected

Load form fields

Populates the _formFields array, for later lookup of fields by name

Parameters
Zend_Pdf_Element_Reference$rootDocument catalog entry

Definition at line 623 of file Pdf.php.

624  {
625  if ($root->AcroForm === null || $root->AcroForm->Fields === null) {
626  return;
627  }
628 
629  foreach ($root->AcroForm->Fields->items as $field) {
630  /* We only support fields that are textfields and have a name */
631  if ($field->FT && $field->FT->value == 'Tx' && $field->T
632  && $field->T !== null
633  ) {
634  $this->_formFields[$field->T->value] = $field;
635  }
636  }
637 
638  if (!$root->AcroForm->NeedAppearances
639  || !$root->AcroForm->NeedAppearances->value
640  ) {
641  /* Ask the .pdf viewer to generate its own appearance data, so we do not have to */
642  $root->AcroForm->add(
643  new Zend_Pdf_Element_Name('NeedAppearances'),
644  new Zend_Pdf_Element_Boolean(true)
645  );
646  $root->AcroForm->touch();
647  }
648  }

◆ _loadJavaScript()

_loadJavaScript ( Zend_Pdf_Element_Reference  $root)
protected

Load JavaScript

Populates the _javaScript string, for later use of getJavaScript method.

Parameters
Zend_Pdf_Element_Reference$rootDocument catalog entry

Definition at line 599 of file Pdf.php.

600  {
601  if (null === $root->Names || null === $root->Names->JavaScript
602  || null === $root->Names->JavaScript->Names
603  ) {
604  return;
605  }
606 
607  foreach ($root->Names->JavaScript->Names->items as $item) {
608  if ($item instanceof Zend_Pdf_Element_Reference
609  && $item->S->value === 'JavaScript'
610  ) {
611  $this->_javaScript[] = $item->JS->value;
612  }
613  }
614  }

◆ _loadNamedDestinations()

_loadNamedDestinations ( Zend_Pdf_Element_Reference  $root,
  $pdfHeaderVersion 
)
protected

Load named destinations recursively

Parameters
Zend_Pdf_Element_Reference$rootDocument catalog entry
string$pdfHeaderVersion
Exceptions
Zend_Pdf_Exception

Definition at line 513 of file Pdf.php.

514  {
515  if ($root->Version !== null && version_compare($root->Version->value, $pdfHeaderVersion, '>')) {
516  $versionIs_1_2_plus = version_compare($root->Version->value, '1.1', '>');
517  } else {
518  $versionIs_1_2_plus = version_compare($pdfHeaderVersion, '1.1', '>');
519  }
520 
521  if ($versionIs_1_2_plus) {
522  // PDF version is 1.2+
523  // Look for Destinations structure at Name dictionary
524  if ($root->Names !== null && $root->Names->Dests !== null) {
525  #require_once 'Zend/Pdf/NameTree.php';
526  #require_once 'Zend/Pdf/Target.php';
527  foreach (new Zend_Pdf_NameTree($root->Names->Dests) as $name => $destination) {
528  $this->_namedTargets[$name] = Zend_Pdf_Target::load($destination);
529  }
530  }
531  } else {
532  // PDF version is 1.1 (or earlier)
533  // Look for Destinations sructure at Dest entry of document catalog
534  if ($root->Dests !== null) {
535  if ($root->Dests->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
536  #require_once 'Zend/Pdf/Exception.php';
537  throw new Zend_Pdf_Exception('Document catalog Dests entry must be a dictionary.');
538  }
539 
540  #require_once 'Zend/Pdf/Target.php';
541  foreach ($root->Dests->getKeys() as $destKey) {
542  $this->_namedTargets[$destKey] = Zend_Pdf_Target::load($root->Dests->$destKey);
543  }
544  }
545  }
546  }
const TYPE_DICTIONARY
Definition: Element.php:37
static load(Zend_Pdf_Element $resource)
Definition: Target.php:41
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ _loadOutlines()

_loadOutlines ( Zend_Pdf_Element_Reference  $root)
protected

Load outlines recursively

Parameters
Zend_Pdf_Element_Reference$rootDocument catalog entry
Exceptions
Zend_Pdf_Exception

Definition at line 554 of file Pdf.php.

555  {
556  if ($root->Outlines === null) {
557  return;
558  }
559 
560  if ($root->Outlines->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
561  #require_once 'Zend/Pdf/Exception.php';
562  throw new Zend_Pdf_Exception('Document catalog Outlines entry must be a dictionary.');
563  }
564 
565  if ($root->Outlines->Type !== null && $root->Outlines->Type->value != 'Outlines') {
566  #require_once 'Zend/Pdf/Exception.php';
567  throw new Zend_Pdf_Exception('Outlines Type entry must be an \'Outlines\' string.');
568  }
569 
570  if ($root->Outlines->First === null) {
571  return;
572  }
573 
574  $outlineDictionary = $root->Outlines->First;
575  $processedDictionaries = new SplObjectStorage();
576  while ($outlineDictionary !== null && !$processedDictionaries->contains($outlineDictionary)) {
577  $processedDictionaries->attach($outlineDictionary);
578 
579  #require_once 'Zend/Pdf/Outline/Loaded.php';
580  $this->outlines[] = new Zend_Pdf_Outline_Loaded($outlineDictionary);
581 
582  $outlineDictionary = $outlineDictionary->Next;
583  }
584 
585  $this->_originalOutlines = $this->outlines;
586 
587  if ($root->Outlines->Count !== null) {
588  $this->_originalOpenOutlinesCount = $root->Outlines->Count->value;
589  }
590  }
$outlines
Definition: Pdf.php:162
const TYPE_DICTIONARY
Definition: Element.php:37

◆ _loadPages()

_loadPages ( Zend_Pdf_Element_Reference  $pages,
  $attributes = array() 
)
protected

Load pages recursively

Parameters
Zend_Pdf_Element_Reference$pages
array | null$attributes
Exceptions
Zend_Pdf_Exception

Important note. If any attribute or dependant object is an indirect object, then it's still shared between pages.

Definition at line 465 of file Pdf.php.

466  {
467  if ($pages->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
468  #require_once 'Zend/Pdf/Exception.php';
469  throw new Zend_Pdf_Exception('Wrong argument');
470  }
471 
472  foreach ($pages->getKeys() as $property) {
473  if (in_array($property, self::$_inheritableAttributes)) {
474  $attributes[$property] = $pages->$property;
475  $pages->$property = null;
476  }
477  }
478 
479 
480  foreach ($pages->Kids->items as $child) {
481  if ($child->Type->value == 'Pages') {
482  $this->_loadPages($child, $attributes);
483  } else if ($child->Type->value == 'Page') {
484  foreach (self::$_inheritableAttributes as $property) {
485  if ($child->$property === null && array_key_exists($property, $attributes)) {
491  if ($attributes[$property] instanceof Zend_Pdf_Element_Object ||
492  $attributes[$property] instanceof Zend_Pdf_Element_Reference) {
493  $child->$property = $attributes[$property];
494  } else {
495  $child->$property = $this->_objFactory->newObject($attributes[$property]);
496  }
497  }
498  }
499 
500  #require_once 'Zend/Pdf/Page.php';
501  $this->pages[] = new Zend_Pdf_Page($child, $this->_objFactory);
502  }
503  }
504  }
_loadPages(Zend_Pdf_Element_Reference $pages, $attributes=array())
Definition: Pdf.php:465
const TYPE_DICTIONARY
Definition: Element.php:37
$attributes
Definition: matrix.phtml:13
$pages
Definition: Pdf.php:114

◆ _refreshPagesHash()

_refreshPagesHash ( )
protected

Refresh page collection hashes

Returns
Zend_Pdf

Definition at line 1098 of file Pdf.php.

1099  {
1100  $this->_pageReferences = array();
1101  $this->_pageNumbers = array();
1102  $count = 1;
1103  foreach ($this->pages as $page) {
1104  $pageDictionaryHashId = spl_object_hash($page->getPageDictionary()->getObject());
1105  $this->_pageReferences[$pageDictionaryHashId] = $page;
1106  $this->_pageNumbers[$count++] = $page;
1107  }
1108 
1109  return $this;
1110  }
$count
Definition: recent.phtml:13
$page
Definition: pages.php:8

◆ addJavaScript()

addJavaScript (   $javaScript)

Appends JavaScript to the document-level JavaScript

Parameters
string | array$javaScript
Exceptions
Zend_Pdf_Exception

Definition at line 1563 of file Pdf.php.

1564  {
1565  if (empty($javaScript)) {
1566  throw new Zend_Pdf_Exception(
1567  'JavaScript must be a non empty string or array of strings'
1568  );
1569  }
1570 
1571  if (!is_array($javaScript)) {
1572  $javaScript = array($javaScript);
1573  }
1574 
1575  if (null === $this->_javaScript) {
1576  $this->_javaScript = $javaScript;
1577  } else {
1578  $this->_javaScript = array_merge($this->_javaScript, $javaScript);
1579  }
1580 
1581  if (!empty($this->_javaScript)) {
1582  $items = array();
1583 
1584  foreach ($this->_javaScript as $javaScript) {
1585  $jsCode = array(
1586  'S' => new Zend_Pdf_Element_Name('JavaScript'),
1587  'JS' => new Zend_Pdf_Element_String($javaScript)
1588  );
1589  $items[] = new Zend_Pdf_Element_String('EmbeddedJS');
1590  $items[] = $this->_objFactory->newObject(
1591  new Zend_Pdf_Element_Dictionary($jsCode)
1592  );
1593  }
1594 
1595  $jsRef = $this->_objFactory->newObject(
1597  array('Names' => new Zend_Pdf_Element_Array($items))
1598  )
1599  );
1600 
1601  if (null === $this->_trailer->Root->Names) {
1602  $this->_trailer->Root->Names = new Zend_Pdf_Element_Dictionary();
1603  }
1604  $this->_trailer->Root->Names->JavaScript = $jsRef;
1605  }
1606  }
$items

◆ extractFont()

extractFont (   $fontName)

Extract font attached to the page by specific font name

$fontName should be specified in UTF-8 encoding

Parameters
string$fontName
Returns
Zend_Pdf_Resource_Font_Extracted|null
Exceptions
Zend_Pdf_Exception

Definition at line 1275 of file Pdf.php.

1276  {
1277  $fontResourcesUnique = array();
1278  #require_once 'Zend/Pdf/Exception.php';
1279  foreach ($this->pages as $page) {
1280  $pageResources = $page->extractResources();
1281 
1282  if ($pageResources->Font === null) {
1283  // Page doesn't contain have any font reference
1284  continue;
1285  }
1286 
1287  $fontResources = $pageResources->Font;
1288 
1289  foreach ($fontResources->getKeys() as $fontResourceName) {
1290  $fontDictionary = $fontResources->$fontResourceName;
1291 
1292  if (! ($fontDictionary instanceof Zend_Pdf_Element_Reference ||
1293  $fontDictionary instanceof Zend_Pdf_Element_Object) ) {
1294  #require_once 'Zend/Pdf/Exception.php';
1295  throw new Zend_Pdf_Exception('Font dictionary has to be an indirect object or object reference.');
1296  }
1297 
1298  $resourceId = spl_object_hash($fontDictionary->getObject());
1299  if (isset($fontResourcesUnique[$resourceId])) {
1300  continue;
1301  } else {
1302  // Mark resource as processed
1303  $fontResourcesUnique[$resourceId] = 1;
1304  }
1305 
1306  if ($fontDictionary->BaseFont->value != $fontName) {
1307  continue;
1308  }
1309 
1310  try {
1311  // Try to extract font
1312  #require_once 'Zend/Pdf/Resource/Font/Extracted.php';
1313  return new Zend_Pdf_Resource_Font_Extracted($fontDictionary);
1314  } catch (Zend_Pdf_Exception $e) {
1315  if ($e->getMessage() != 'Unsupported font type.') {
1316  throw $e;
1317  }
1318  // Continue searhing
1319  }
1320  }
1321  }
1322 
1323  return null;
1324  }
$page
Definition: pages.php:8

◆ extractFonts()

extractFonts ( )

Extract fonts attached to the document

returns array of Zend_Pdf_Resource_Font_Extracted objects

Returns
array
Exceptions
Zend_Pdf_Exception

Definition at line 1221 of file Pdf.php.

1222  {
1223  $fontResourcesUnique = array();
1224  foreach ($this->pages as $page) {
1225  $pageResources = $page->extractResources();
1226 
1227  if ($pageResources->Font === null) {
1228  // Page doesn't contain have any font reference
1229  continue;
1230  }
1231 
1232  $fontResources = $pageResources->Font;
1233 
1234  foreach ($fontResources->getKeys() as $fontResourceName) {
1235  $fontDictionary = $fontResources->$fontResourceName;
1236 
1237  if (! ($fontDictionary instanceof Zend_Pdf_Element_Reference ||
1238  $fontDictionary instanceof Zend_Pdf_Element_Object) ) {
1239  #require_once 'Zend/Pdf/Exception.php';
1240  throw new Zend_Pdf_Exception('Font dictionary has to be an indirect object or object reference.');
1241  }
1242 
1243  $fontResourcesUnique[spl_object_hash($fontDictionary->getObject())] = $fontDictionary;
1244  }
1245  }
1246 
1247  $fonts = array();
1248  #require_once 'Zend/Pdf/Exception.php';
1249  foreach ($fontResourcesUnique as $resourceId => $fontDictionary) {
1250  try {
1251  // Try to extract font
1252  #require_once 'Zend/Pdf/Resource/Font/Extracted.php';
1253  $extractedFont = new Zend_Pdf_Resource_Font_Extracted($fontDictionary);
1254 
1255  $fonts[$resourceId] = $extractedFont;
1256  } catch (Zend_Pdf_Exception $e) {
1257  if ($e->getMessage() != 'Unsupported font type.') {
1258  throw $e;
1259  }
1260  }
1261  }
1262 
1263  return $fonts;
1264  }
$page
Definition: pages.php:8

◆ getJavaScript()

getJavaScript ( )

Return the document-level JavaScript or null if there is no JavaScript for this document

Returns
string

Definition at line 982 of file Pdf.php.

983  {
984  return $this->_javaScript;
985  }
$_javaScript
Definition: Pdf.php:147

◆ getMemoryManager()

static getMemoryManager ( )
static

Request used memory manager

Returns
Zend_Memory_Manager

Definition at line 236 of file Pdf.php.

237  {
238  if (self::$_memoryManager === null) {
239  #require_once 'Zend/Memory.php';
240  self::$_memoryManager = Zend_Memory::factory('none');
241  }
242 
243  return self::$_memoryManager;
244  }
static factory($backend, $backendOptions=array())
Definition: Memory.php:50
static $_memoryManager
Definition: Pdf.php:199

◆ getMetadata()

getMetadata ( )

Return the document-level Metadata or null Metadata stream is not presented

Returns
string

Definition at line 952 of file Pdf.php.

953  {
954  if ($this->_trailer->Root->Metadata !== null) {
955  return $this->_trailer->Root->Metadata->value;
956  } else {
957  return null;
958  }
959  }

◆ getNamedDestination()

getNamedDestination (   $name)

Return specified named destination

Parameters
string$name
Returns
Zend_Pdf_Destination_Explicit|Zend_Pdf_Action_GoTo

Definition at line 1045 of file Pdf.php.

1046  {
1047  if (isset($this->_namedTargets[$name])) {
1048  return $this->_namedTargets[$name];
1049  } else {
1050  return null;
1051  }
1052  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getNamedDestinations()

getNamedDestinations ( )

Return an associative array containing all the named destinations (or GoTo actions) in the PDF. Named targets can be used to reference from outside the PDF, ex: 'http://www.something.com/mydocument.pdf#MyAction'

Returns
array

Definition at line 1034 of file Pdf.php.

1035  {
1036  return $this->_namedTargets;
1037  }
$_namedTargets
Definition: Pdf.php:155

◆ getOpenAction()

getOpenAction ( )

Get open Action Returns Zend_Pdf_Target (Zend_Pdf_Destination or Zend_Pdf_Action object)

Returns
Zend_Pdf_Target

Definition at line 993 of file Pdf.php.

994  {
995  if ($this->_trailer->Root->OpenAction !== null) {
996  #require_once 'Zend/Pdf/Target.php';
997  return Zend_Pdf_Target::load($this->_trailer->Root->OpenAction);
998  } else {
999  return null;
1000  }
1001  }
static load(Zend_Pdf_Element $resource)
Definition: Target.php:41

◆ getTextFieldNames()

getTextFieldNames ( )

Retrieves a list with the names of the AcroForm textfields in the PDF

Returns
array of strings

Definition at line 655 of file Pdf.php.

656  {
657  return array_keys($this->_formFields);
658  }

◆ load()

static load (   $source = null,
  $revision = null 
)
static

Load PDF document from a file

Parameters
string$source
integer$revision
Returns
Zend_Pdf

Definition at line 276 of file Pdf.php.

277  {
278  return new Zend_Pdf($source, $revision, true);
279  }
$source
Definition: source.php:23

◆ markTextFieldAsReadOnly()

markTextFieldAsReadOnly (   $name)

Marks an AcroForm text field as read only

Parameters
string$name

Definition at line 711 of file Pdf.php.

712  {
713  $this->setTextFieldProperties($name, self::PDF_FORM_FIELD_READONLY);
714  }
setTextFieldProperties($name, $bitmask)
Definition: Pdf.php:690
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ newPage()

newPage (   $param1,
  $param2 = null 
)

Create page object, attached to the PDF document. Method signatures:

  1. Create new page with a specified pagesize. If $factory is null then it will be created and page must be attached to the document to be

    included into output.

new Zend_Pdf_Page(string $pagesize);

  1. Create new page with a specified pagesize (in default user space units). If $factory is null then it will be created and page must be attached to the document to be

    included into output.

new Zend_Pdf_Page(numeric $width, numeric $height);

Parameters
mixed$param1
mixed$param2
Returns
Zend_Pdf_Page

Definition at line 936 of file Pdf.php.

937  {
938  #require_once 'Zend/Pdf/Page.php';
939  if ($param2 === null) {
940  return new Zend_Pdf_Page($param1, $this->_objFactory);
941  } else {
942  return new Zend_Pdf_Page($param1, $param2, $this->_objFactory);
943  }
944  }

◆ parse()

static parse ( $source = null,
  $revision = null 
)
static

Create new PDF document from a $source string

Parameters
string$source
integer$revision
Returns
Zend_Pdf

Definition at line 264 of file Pdf.php.

265  {
266  return new Zend_Pdf($source, $revision);
267  }
$source
Definition: source.php:23

◆ pdfDate()

static pdfDate (   $timestamp = null)
static

Convert date to PDF format (it's close to ASN.1 (Abstract Syntax Notation One) defined in ISO/IEC 8824).

Todo:
This really isn't the best location for this method. It should probably actually exist as Zend_Pdf_Element_Date or something like that.
Todo:
Address the following E_STRICT issue: PHP Strict Standards: date(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
Parameters
integer$timestamp(optional) If omitted, uses the current time.
Returns
string

Definition at line 1625 of file Pdf.php.

1626  {
1627  if ($timestamp === null) {
1628  $date = date('\D\:YmdHisO');
1629  } else {
1630  $date = date('\D\:YmdHisO', $timestamp);
1631  }
1632  return substr_replace($date, '\'', -2, 0) . '\'';
1633  }

◆ render()

render (   $newSegmentOnly = false,
  $outputStream = null 
)

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.

Parameters
boolean$newSegmentOnly
resource$outputStream
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 1336 of file Pdf.php.

1337  {
1338  if ($this->_isNewDocument) {
1339  // Drop full document first time even $newSegmentOnly is set to true
1340  $newSegmentOnly = false;
1341  $this->_isNewDocument = false;
1342  }
1343 
1344  // Save document properties if necessary
1345  if ($this->properties != $this->_originalProperties) {
1346  $docInfo = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
1347 
1348  foreach ($this->properties as $key => $value) {
1349  switch ($key) {
1350  case 'Trapped':
1351  switch ($value) {
1352  case true:
1353  $docInfo->$key = new Zend_Pdf_Element_Name('True');
1354  break;
1355 
1356  case false:
1357  $docInfo->$key = new Zend_Pdf_Element_Name('False');
1358  break;
1359 
1360  case null:
1361  $docInfo->$key = new Zend_Pdf_Element_Name('Unknown');
1362  break;
1363 
1364  default:
1365  #require_once 'Zend/Pdf/Exception.php';
1366  throw new Zend_Pdf_Exception('Wrong Trapped document property vale: \'' . $value . '\'. Only true, false and null values are allowed.');
1367  break;
1368  }
1369 
1370  case 'CreationDate':
1371  // break intentionally omitted
1372  case 'ModDate':
1373  $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
1374  break;
1375 
1376  case 'Title':
1377  // break intentionally omitted
1378  case 'Author':
1379  // break intentionally omitted
1380  case 'Subject':
1381  // break intentionally omitted
1382  case 'Keywords':
1383  // break intentionally omitted
1384  case 'Creator':
1385  // break intentionally omitted
1386  case 'Producer':
1387  if (extension_loaded('mbstring') === true) {
1388  $detected = mb_detect_encoding($value);
1389  if ($detected !== 'ASCII') {
1390  $value = "\xfe\xff" . mb_convert_encoding($value, 'UTF-16', $detected);
1391  }
1392  }
1393  $docInfo->$key = new Zend_Pdf_Element_String((string)$value);
1394  break;
1395 
1396  default:
1397  // Set property using PDF type based on PHP type
1398  $docInfo->$key = Zend_Pdf_Element::phpToPdf($value);
1399  break;
1400  }
1401  }
1402 
1403  $this->_trailer->Info = $docInfo;
1404  }
1405 
1406  $this->_dumpPages();
1407  $this->_dumpNamedDestinations();
1408  $this->_dumpOutlines();
1409 
1410  // Check, that PDF file was modified
1411  // File is always modified by _dumpPages() now, but future implementations may eliminate this.
1412  if (!$this->_objFactory->isModified()) {
1413  if ($newSegmentOnly) {
1414  // Do nothing, return
1415  return '';
1416  }
1417 
1418  if ($outputStream === null) {
1419  return $this->_trailer->getPDFString();
1420  } else {
1421  $pdfData = $this->_trailer->getPDFString();
1422  while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) {
1423  $pdfData = substr($pdfData, $byteCount);
1424  }
1425 
1426  return '';
1427  }
1428  }
1429 
1430  // offset (from a start of PDF file) of new PDF file segment
1431  $offset = $this->_trailer->getPDFLength();
1432  // Last Object number in a list of free objects
1433  $lastFreeObject = $this->_trailer->getLastFreeObject();
1434 
1435  // Array of cross-reference table subsections
1436  $xrefTable = array();
1437  // Object numbers of first objects in each subsection
1438  $xrefSectionStartNums = array();
1439 
1440  // Last cross-reference table subsection
1441  $xrefSection = array();
1442  // Dummy initialization of the first element (specail case - header of linked list of free objects).
1443  $xrefSection[] = 0;
1444  $xrefSectionStartNums[] = 0;
1445  // Object number of last processed PDF object.
1446  // Used to manage cross-reference subsections.
1447  // Initialized by zero (specail case - header of linked list of free objects).
1448  $lastObjNum = 0;
1449 
1450  if ($outputStream !== null) {
1451  if (!$newSegmentOnly) {
1452  $pdfData = $this->_trailer->getPDFString();
1453  while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) {
1454  $pdfData = substr($pdfData, $byteCount);
1455  }
1456  }
1457  } else {
1458  $pdfSegmentBlocks = ($newSegmentOnly) ? array() : array($this->_trailer->getPDFString());
1459  }
1460 
1461  // Iterate objects to create new reference table
1462  foreach ($this->_objFactory->listModifiedObjects() as $updateInfo) {
1463  $objNum = $updateInfo->getObjNum();
1464 
1465  if ($objNum - $lastObjNum != 1) {
1466  // Save cross-reference table subsection and start new one
1467  $xrefTable[] = $xrefSection;
1468  $xrefSection = array();
1469  $xrefSectionStartNums[] = $objNum;
1470  }
1471 
1472  if ($updateInfo->isFree()) {
1473  // Free object cross-reference table entry
1474  $xrefSection[] = sprintf("%010d %05d f \n", $lastFreeObject, $updateInfo->getGenNum());
1475  $lastFreeObject = $objNum;
1476  } else {
1477  // In-use object cross-reference table entry
1478  $xrefSection[] = sprintf("%010d %05d n \n", $offset, $updateInfo->getGenNum());
1479 
1480  $pdfBlock = $updateInfo->getObjectDump();
1481  $offset += strlen($pdfBlock);
1482 
1483  if ($outputStream === null) {
1484  $pdfSegmentBlocks[] = $pdfBlock;
1485  } else {
1486  while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) {
1487  $pdfBlock = substr($pdfBlock, $byteCount);
1488  }
1489  }
1490  }
1491  $lastObjNum = $objNum;
1492  }
1493  // Save last cross-reference table subsection
1494  $xrefTable[] = $xrefSection;
1495 
1496  // Modify first entry (specail case - header of linked list of free objects).
1497  $xrefTable[0][0] = sprintf("%010d 65535 f \n", $lastFreeObject);
1498 
1499  $xrefTableStr = "xref\n";
1500  foreach ($xrefTable as $sectId => $xrefSection) {
1501  $xrefTableStr .= sprintf("%d %d \n", $xrefSectionStartNums[$sectId], count($xrefSection));
1502  foreach ($xrefSection as $xrefTableEntry) {
1503  $xrefTableStr .= $xrefTableEntry;
1504  }
1505  }
1506 
1507  $this->_trailer->Size->value = $this->_objFactory->getObjectCount();
1508 
1509  $pdfBlock = $xrefTableStr
1510  . $this->_trailer->toString()
1511  . "startxref\n" . $offset . "\n"
1512  . "%%EOF\n";
1513 
1514  $this->_objFactory->cleanEnumerationShiftCache();
1515 
1516  if ($outputStream === null) {
1517  $pdfSegmentBlocks[] = $pdfBlock;
1518 
1519  return implode('', $pdfSegmentBlocks);
1520  } else {
1521  while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) {
1522  $pdfBlock = substr($pdfBlock, $byteCount);
1523  }
1524 
1525  return '';
1526  }
1527  }
$value
Definition: gender.phtml:16

◆ resetJavaScript()

resetJavaScript ( )

Resets the document-level JavaScript

Definition at line 1546 of file Pdf.php.

1547  {
1548  $this->_javaScript = null;
1549 
1550  $root = $this->_trailer->Root;
1551  if (null === $root->Names || null === $root->Names->JavaScript) {
1552  return;
1553  }
1554  $root->Names->JavaScript = null;
1555  }

◆ resolveDestination()

resolveDestination ( Zend_Pdf_Destination  $destination,
  $refreshPageCollectionHashes = true 
)

Resolve destination.

Returns Zend_Pdf_Page page object or null if destination is not found within PDF document.

Parameters
Zend_Pdf_Destination$destinationDestination to resolve
bool$refreshPageCollectionHashesRefresh page collection hashes before processing
Returns
Zend_Pdf_Page|null
Exceptions
Zend_Pdf_Exception

Definition at line 1122 of file Pdf.php.

1123  {
1124  if ($this->_pageReferences === null || $refreshPageCollectionHashes) {
1125  $this->_refreshPagesHash();
1126  }
1127 
1128  if ($destination instanceof Zend_Pdf_Destination_Named) {
1129  if (!isset($this->_namedTargets[$destination->getName()])) {
1130  return null;
1131  }
1132  $destination = $this->getNamedDestination($destination->getName());
1133 
1134  if ($destination instanceof Zend_Pdf_Action) {
1135  if (!$destination instanceof Zend_Pdf_Action_GoTo) {
1136  return null;
1137  }
1138  $destination = $destination->getDestination();
1139  }
1140 
1141  if (!$destination instanceof Zend_Pdf_Destination_Explicit) {
1142  #require_once 'Zend/Pdf/Exception.php';
1143  throw new Zend_Pdf_Exception('Named destination target has to be an explicit destination.');
1144  }
1145  }
1146 
1147  // Named target is an explicit destination
1148  $pageElement = $destination->getResource()->items[0];
1149 
1150  if ($pageElement->getType() == Zend_Pdf_Element::TYPE_NUMERIC) {
1151  // Page reference is a PDF number
1152  if (!isset($this->_pageNumbers[$pageElement->value])) {
1153  return null;
1154  }
1155 
1156  return $this->_pageNumbers[$pageElement->value];
1157  }
1158 
1159  // Page reference is a PDF page dictionary reference
1160  $pageDictionaryHashId = spl_object_hash($pageElement->getObject());
1161  if (!isset($this->_pageReferences[$pageDictionaryHashId])) {
1162  return null;
1163  }
1164  return $this->_pageReferences[$pageDictionaryHashId];
1165  }
const TYPE_NUMERIC
Definition: Element.php:33
getNamedDestination($name)
Definition: Pdf.php:1045
_refreshPagesHash()
Definition: Pdf.php:1098

◆ revisions()

revisions ( )

Retrive number of revisions.

Returns
integer

Definition at line 420 of file Pdf.php.

421  {
422  $revisions = 1;
423  $currentTrailer = $this->_trailer;
424 
425  while ($currentTrailer->getPrev() !== null && $currentTrailer->getPrev()->Root !== null ) {
426  $revisions++;
427  $currentTrailer = $currentTrailer->getPrev();
428  }
429 
430  return $revisions++;
431  }
$_trailer
Definition: Pdf.php:185

◆ rollback()

rollback (   $steps)

Rollback document $steps number of revisions. This method must be invoked before any changes, applied to the document. Otherwise behavior is undefined.

Parameters
integer$steps

Definition at line 440 of file Pdf.php.

441  {
442  for ($count = 0; $count < $steps; $count++) {
443  if ($this->_trailer->getPrev() !== null && $this->_trailer->getPrev()->Root !== null) {
444  $this->_trailer = $this->_trailer->getPrev();
445  } else {
446  break;
447  }
448  }
449  $this->_objFactory->setObjectCount($this->_trailer->Size->value);
450 
451  // Mark content as modified to force new trailer generation at render time
452  $this->_trailer->Root->touch();
453 
454  $this->pages = array();
455  $this->_loadPages($this->_trailer->Root->Pages);
456  }
_loadPages(Zend_Pdf_Element_Reference $pages, $attributes=array())
Definition: Pdf.php:465
$count
Definition: recent.phtml:13

◆ save()

save (   $filename,
  $updateOnly = false 
)

Render PDF document and save it.

If $updateOnly is true and it's not a new document, then it only appends new section to the end of file.

Parameters
string$filename
boolean$updateOnly
Exceptions
Zend_Pdf_Exception

Definition at line 291 of file Pdf.php.

292  {
293  if (($file = @fopen($filename, $updateOnly ? 'ab':'wb')) === false ) {
294  #require_once 'Zend/Pdf/Exception.php';
295  throw new Zend_Pdf_Exception( "Can not open '$filename' file for writing." );
296  }
297 
298  $this->render($updateOnly, $file);
299 
300  fclose($file);
301  }
render($newSegmentOnly=false, $outputStream=null)
Definition: Pdf.php:1336

◆ setJavaScript()

setJavaScript (   $javaScript)

Sets the document-level JavaScript

Resets and appends

Parameters
string | array$javaScript

Definition at line 1536 of file Pdf.php.

1537  {
1538  $this->resetJavaScript();
1539 
1540  $this->addJavaScript($javaScript);
1541  }
addJavaScript($javaScript)
Definition: Pdf.php:1563
resetJavaScript()
Definition: Pdf.php:1546

◆ setMemoryManager()

static setMemoryManager ( Zend_Memory_Manager  $memoryManager)
static

Set user defined memory manager

Parameters
Zend_Memory_Manager$memoryManager

Definition at line 251 of file Pdf.php.

252  {
253  self::$_memoryManager = $memoryManager;
254  }

◆ setMetadata()

setMetadata (   $metadata)

Sets the document-level Metadata (mast be valid XMP document)

Parameters
string$metadata

Definition at line 966 of file Pdf.php.

967  {
968  $metadataObject = $this->_objFactory->newStreamObject($metadata);
969  $metadataObject->dictionary->Type = new Zend_Pdf_Element_Name('Metadata');
970  $metadataObject->dictionary->Subtype = new Zend_Pdf_Element_Name('XML');
971 
972  $this->_trailer->Root->Metadata = $metadataObject;
973  $this->_trailer->Root->touch();
974  }

◆ setNamedDestination()

setNamedDestination (   $name,
  $destination = null 
)

Set specified named destination

Parameters
string$name
Zend_Pdf_Destination_Explicit | Zend_Pdf_Action_GoTo$destination
Exceptions
Zend_Pdf_Exception

Definition at line 1061 of file Pdf.php.

1062  {
1063  if ($destination !== null &&
1064  !$destination instanceof Zend_Pdf_Action_GoTo &&
1065  !$destination instanceof Zend_Pdf_Destination_Explicit) {
1066  #require_once 'Zend/Pdf/Exception.php';
1067  throw new Zend_Pdf_Exception('PDF named destination must refer an explicit destination or a GoTo PDF action.');
1068  }
1069 
1070  if ($destination !== null) {
1071  $this->_namedTargets[$name] = $destination;
1072  } else {
1073  unset($this->_namedTargets[$name]);
1074  }
1075  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setOpenAction()

setOpenAction ( Zend_Pdf_Target  $openAction = null)

Set open Action which is actually Zend_Pdf_Destination or Zend_Pdf_Action object

Parameters
Zend_Pdf_Target$openAction
Returns
Zend_Pdf

Definition at line 1009 of file Pdf.php.

1010  {
1011  $root = $this->_trailer->Root;
1012  $root->touch();
1013 
1014  if ($openAction === null) {
1015  $root->OpenAction = null;
1016  } else {
1017  $root->OpenAction = $openAction->getResource();
1018 
1019  if ($openAction instanceof Zend_Pdf_Action) {
1020  $openAction->dumpAction($this->_objFactory);
1021  }
1022  }
1023 
1024  return $this;
1025  }

◆ setTextFieldProperties()

setTextFieldProperties (   $name,
  $bitmask 
)

Sets the properties for an AcroForm text field

Parameters
string$name
mixed$bitmask
Exceptions
Zend_Pdf_Exception

Definition at line 690 of file Pdf.php.

691  {
692  if (!isset($this->_formFields[$name])) {
693  throw new Zend_Pdf_Exception(
694  "Field '$name' does not exist or is not a textfield"
695  );
696  }
697 
698  $field = $this->_formFields[$name];
699  $field->add(
700  new Zend_Pdf_Element_Name('Ff'),
701  new Zend_Pdf_Element_Numeric($bitmask)
702  );
703  $field->touch();
704  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_formFields

$_formFields = array()
protected

Definition at line 221 of file Pdf.php.

◆ $_inheritableAttributes

$_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate')
staticprotected

Definition at line 214 of file Pdf.php.

◆ $_isNewDocument

$_isNewDocument = true
protected

Definition at line 229 of file Pdf.php.

◆ $_javaScript

$_javaScript = null
protected

Definition at line 147 of file Pdf.php.

◆ $_memoryManager

$_memoryManager = null
staticprotected

Definition at line 199 of file Pdf.php.

◆ $_namedTargets

$_namedTargets = array()
protected

Definition at line 155 of file Pdf.php.

◆ $_objFactory

$_objFactory = null
protected

Definition at line 192 of file Pdf.php.

◆ $_originalOpenOutlinesCount

$_originalOpenOutlinesCount = 0
protected

Definition at line 178 of file Pdf.php.

◆ $_originalOutlines

$_originalOutlines = array()
protected

Definition at line 170 of file Pdf.php.

◆ $_originalProperties

$_originalProperties = array()
protected

Definition at line 140 of file Pdf.php.

◆ $_pageNumbers

$_pageNumbers = null
protected

Definition at line 1091 of file Pdf.php.

◆ $_pageReferences

$_pageReferences = null
protected

Definition at line 1083 of file Pdf.php.

◆ $_parser

$_parser
protected

Definition at line 207 of file Pdf.php.

◆ $_trailer

$_trailer = null
protected

Definition at line 185 of file Pdf.php.

◆ $outlines

$outlines = array()

Definition at line 162 of file Pdf.php.

◆ $pages

$pages = array()

Definition at line 114 of file Pdf.php.

◆ $properties

$properties = array()

Definition at line 131 of file Pdf.php.

◆ PDF_FORM_FIELD_NOEXPORT

const PDF_FORM_FIELD_NOEXPORT = 4

Definition at line 103 of file Pdf.php.

◆ PDF_FORM_FIELD_READONLY

const PDF_FORM_FIELD_READONLY = 1

Form field options

Definition at line 101 of file Pdf.php.

◆ PDF_FORM_FIELD_REQUIRED

const PDF_FORM_FIELD_REQUIRED = 2

Definition at line 102 of file Pdf.php.

◆ PDF_HEADER

const PDF_HEADER = "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n"

PDF file header.

Definition at line 96 of file Pdf.php.

◆ PDF_VERSION

const PDF_VERSION = '1.4'

Version number of generated PDF documents.

Definition at line 91 of file Pdf.php.


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