27 #require_once 'Zend/Pdf/Page.php'; 30 #require_once 'Zend/Pdf/Style.php'; 33 #require_once 'Zend/Pdf/Color/GrayScale.php'; 36 #require_once 'Zend/Pdf/Color/Rgb.php'; 39 #require_once 'Zend/Pdf/Color/Cmyk.php'; 42 #require_once 'Zend/Pdf/Color/Html.php'; 45 #require_once 'Zend/Pdf/Image.php'; 48 #require_once 'Zend/Pdf/Font.php'; 51 #require_once 'Zend/Pdf/Resource/Extractor.php'; 54 #require_once 'Zend/Pdf/Canvas.php'; 58 #require_once 'Zend/Pdf/Element.php'; 59 #require_once 'Zend/Pdf/Element/Array.php'; 60 #require_once 'Zend/Pdf/Element/String/Binary.php'; 61 #require_once 'Zend/Pdf/Element/Boolean.php'; 62 #require_once 'Zend/Pdf/Element/Dictionary.php'; 63 #require_once 'Zend/Pdf/Element/Name.php'; 64 #require_once 'Zend/Pdf/Element/Null.php'; 65 #require_once 'Zend/Pdf/Element/Numeric.php'; 66 #require_once 'Zend/Pdf/Element/String.php'; 238 if (self::$_memoryManager ===
null) {
239 #require_once 'Zend/Memory.php'; 253 self::$_memoryManager = $memoryManager;
291 public function save($filename, $updateOnly =
false)
293 if (($file = @
fopen($filename, $updateOnly ?
'ab':
'wb')) ===
false ) {
294 #require_once 'Zend/Pdf/Exception.php'; 298 $this->
render($updateOnly, $file);
324 #require_once 'Zend/Pdf/ElementFactory.php'; 328 #require_once 'Zend/Pdf/Parser.php'; 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'; 336 if ($revision !==
null) {
339 $this->
_loadPages($this->_trailer->Root->Pages);
347 if ($this->_trailer->Info !==
null) {
348 $this->properties = $this->_trailer->Info->toPhp();
350 if (isset($this->properties[
'Trapped'])) {
351 switch ($this->properties[
'Trapped']) {
353 $this->properties[
'Trapped'] =
true;
357 $this->properties[
'Trapped'] =
false;
361 $this->properties[
'Trapped'] =
null;
374 $this->_isNewDocument =
false;
383 $docId = md5(uniqid(rand(),
true));
384 $docIdLow = substr($docId, 0, 16);
385 $docIdHigh = substr($docId, 16, 16);
393 #require_once 'Zend/Pdf/Trailer/Generator.php'; 402 $this->_trailer->Root = $docCatalog;
411 $docCatalog->Pages = $docPages;
425 while ($currentTrailer->getPrev() !==
null && $currentTrailer->getPrev()->Root !== null ) {
427 $currentTrailer = $currentTrailer->getPrev();
443 if ($this->_trailer->getPrev() !==
null && $this->_trailer->getPrev()->Root !==
null) {
444 $this->_trailer = $this->_trailer->getPrev();
449 $this->_objFactory->setObjectCount($this->_trailer->Size->value);
452 $this->_trailer->Root->touch();
454 $this->pages = array();
455 $this->
_loadPages($this->_trailer->Root->Pages);
468 #require_once 'Zend/Pdf/Exception.php'; 472 foreach (
$pages->getKeys() as $property) {
473 if (in_array($property, self::$_inheritableAttributes)) {
480 foreach (
$pages->Kids->items as $child) {
481 if ($child->Type->value ==
'Pages') {
483 }
else if ($child->Type->value ==
'Page') {
484 foreach (self::$_inheritableAttributes as $property) {
485 if ($child->$property ===
null && array_key_exists($property,
$attributes)) {
495 $child->$property = $this->_objFactory->newObject(
$attributes[$property]);
500 #require_once 'Zend/Pdf/Page.php'; 501 $this->pages[] =
new Zend_Pdf_Page($child, $this->_objFactory);
515 if ($root->Version !==
null && version_compare($root->Version->value, $pdfHeaderVersion,
'>')) {
516 $versionIs_1_2_plus = version_compare($root->Version->value,
'1.1',
'>');
518 $versionIs_1_2_plus = version_compare($pdfHeaderVersion,
'1.1',
'>');
521 if ($versionIs_1_2_plus) {
524 if ($root->Names !==
null && $root->Names->Dests !==
null) {
525 #require_once 'Zend/Pdf/NameTree.php'; 526 #require_once 'Zend/Pdf/Target.php'; 534 if ($root->Dests !==
null) {
536 #require_once 'Zend/Pdf/Exception.php'; 540 #require_once 'Zend/Pdf/Target.php'; 541 foreach ($root->Dests->getKeys() as $destKey) {
556 if ($root->Outlines ===
null) {
561 #require_once 'Zend/Pdf/Exception.php'; 562 throw new Zend_Pdf_Exception(
'Document catalog Outlines entry must be a dictionary.');
565 if ($root->Outlines->Type !==
null && $root->Outlines->Type->value !=
'Outlines') {
566 #require_once 'Zend/Pdf/Exception.php'; 570 if ($root->Outlines->First ===
null) {
574 $outlineDictionary = $root->Outlines->First;
575 $processedDictionaries =
new SplObjectStorage();
576 while ($outlineDictionary !==
null && !$processedDictionaries->contains($outlineDictionary)) {
577 $processedDictionaries->attach($outlineDictionary);
579 #require_once 'Zend/Pdf/Outline/Loaded.php'; 582 $outlineDictionary = $outlineDictionary->Next;
587 if ($root->Outlines->Count !==
null) {
588 $this->_originalOpenOutlinesCount = $root->Outlines->Count->value;
601 if (
null === $root->Names ||
null === $root->Names->JavaScript
602 ||
null === $root->Names->JavaScript->Names
607 foreach ($root->Names->JavaScript->Names->items as
$item) {
609 &&
$item->S->value ===
'JavaScript' 611 $this->_javaScript[] =
$item->JS->value;
625 if ($root->AcroForm ===
null || $root->AcroForm->Fields ===
null) {
629 foreach ($root->AcroForm->Fields->items as $field) {
631 if ($field->FT && $field->FT->value ==
'Tx' && $field->T
632 && $field->T !==
null 634 $this->_formFields[$field->T->value] = $field;
638 if (!$root->AcroForm->NeedAppearances
639 || !$root->AcroForm->NeedAppearances->value
642 $root->AcroForm->add(
646 $root->AcroForm->
touch();
657 return array_keys($this->_formFields);
669 if (!isset($this->_formFields[
$name])) {
671 "Field '$name' does not exist or is not a textfield" 676 $field = $this->_formFields[
$name];
692 if (!isset($this->_formFields[
$name])) {
694 "Field '$name' does not exist or is not a textfield" 698 $field = $this->_formFields[
$name];
726 $root = $this->_trailer->Root;
727 $pagesContainer = $root->Pages;
729 $pagesContainer->touch();
730 $pagesContainer->Kids->items = array();
732 foreach ($this->pages as
$page ) {
733 $page->render($this->_objFactory);
735 $pageDictionary =
$page->getPageDictionary();
736 $pageDictionary->touch();
737 $pageDictionary->Parent = $pagesContainer;
739 $pagesContainer->Kids->items[] = $pageDictionary;
744 $pagesContainer->Count->touch();
745 $pagesContainer->Count->value = count($this->pages);
749 foreach ($this->_namedTargets as
$name => $namedTarget) {
753 unset($this->_namedTargets[
$name]);
759 unset($this->_namedTargets[
$name]);
762 #require_once 'Zend/Pdf/Exception.php'; 763 throw new Zend_Pdf_Exception(
'Wrong type of named targed (\'' . get_class($namedTarget) .
'\').
'); 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(); 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); 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); 786 #require_once 'Zend/Pdf/Exception.php
'; 787 throw new Zend_Pdf_Exception('Wrong outline target.
'); 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); 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); 806 #require_once 'Zend/Pdf/Exception.php
'; 807 throw new Zend_Pdf_Exception('OpenAction has to be either PDF Action or Destination.
'); 817 protected function _dumpNamedDestinations() 819 ksort($this->_namedTargets, SORT_STRING); 821 $destArrayItems = array(); 822 foreach ($this->_namedTargets as $name => $destination) { 823 $destArrayItems[] = new Zend_Pdf_Element_String($name); 825 if ($destination instanceof Zend_Pdf_Target) { 826 $destArrayItems[] = $destination->getResource(); 828 #require_once 'Zend/Pdf/Exception.php
'; 829 throw new Zend_Pdf_Exception('PDF named destinations must be a
Zend_Pdf_Target object.
'); 832 $destArray = $this->_objFactory->newObject(new Zend_Pdf_Element_Array($destArrayItems)); 834 $DestTree = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); 835 $DestTree->Names = $destArray; 837 $root = $this->_trailer->Root; 839 if ($root->Names === null) { 841 $root->Names = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); 843 $root->Names->touch(); 845 $root->Names->Dests = $DestTree; 851 protected function _dumpOutlines() 853 $root = $this->_trailer->Root; 855 if ($root->Outlines === null) { 856 if (count($this->outlines) == 0) { 859 $root->Outlines = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); 860 $root->Outlines->Type = new Zend_Pdf_Element_Name('Outlines
'); 861 $updateOutlinesNavigation = true; 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; 872 foreach ($this->outlines as $key => $outline) { 873 if ($this->_originalOutlines[$key] !== $outline) { 874 $updateOutlinesNavigation = true; 881 $openOutlinesCount = 0; 882 if ($updateOutlinesNavigation) { 883 $root->Outlines->touch(); 884 $root->Outlines->First = null; 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; 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; 897 $openOutlinesCount += $outline->openOutlinesCount(); 900 $root->Outlines->Last = $lastOutline; 902 foreach ($this->outlines as $outline) { 903 $lastOutline = $outline->dumpOutline($this->_objFactory, $updateOutlinesNavigation, $root->Outlines, $lastOutline); 904 $openOutlinesCount += $outline->openOutlinesCount(); 908 if ($openOutlinesCount != $this->_originalOpenOutlinesCount) { 909 $root->Outlines->touch; 910 $root->Outlines->Count = new Zend_Pdf_Element_Numeric($openOutlinesCount); 936 public function newPage($param1, $param2 = null) 938 #require_once 'Zend/Pdf/Page.php
'; 939 if ($param2 === null) { 940 return new Zend_Pdf_Page($param1, $this->_objFactory); 942 return new Zend_Pdf_Page($param1, $param2, $this->_objFactory); 952 public function getMetadata() 954 if ($this->_trailer->Root->Metadata !== null) { 955 return $this->_trailer->Root->Metadata->value; 966 public function setMetadata($metadata) 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
'); 972 $this->_trailer->Root->Metadata = $metadataObject; 973 $this->_trailer->Root->touch(); 982 public function getJavaScript() 984 return $this->_javaScript; 993 public function getOpenAction() 995 if ($this->_trailer->Root->OpenAction !== null) { 996 #require_once 'Zend/Pdf/Target.php
'; 997 return Zend_Pdf_Target::load($this->_trailer->Root->OpenAction); 1009 public function setOpenAction(Zend_Pdf_Target $openAction = null) 1011 $root = $this->_trailer->Root; 1014 if ($openAction === null) { 1015 $root->OpenAction = null; 1017 $root->OpenAction = $openAction->getResource(); 1019 if ($openAction instanceof Zend_Pdf_Action) { 1020 $openAction->dumpAction($this->_objFactory); 1034 public function getNamedDestinations() 1036 return $this->_namedTargets; 1045 public function getNamedDestination($name) 1047 if (isset($this->_namedTargets[$name])) { 1048 return $this->_namedTargets[$name]; 1061 public function setNamedDestination($name, $destination = null) 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.
'); 1070 if ($destination !== null) { 1071 $this->_namedTargets[$name] = $destination; 1073 unset($this->_namedTargets[$name]); 1083 protected $_pageReferences = null; 1091 protected $_pageNumbers = null; 1098 protected function _refreshPagesHash() 1100 $this->_pageReferences = array(); 1101 $this->_pageNumbers = array(); 1103 foreach ($this->pages as $page) { 1104 $pageDictionaryHashId = spl_object_hash($page->getPageDictionary()->getObject()); 1105 $this->_pageReferences[$pageDictionaryHashId] = $page; 1106 $this->_pageNumbers[$count++] = $page; 1122 public function resolveDestination(Zend_Pdf_Destination $destination, $refreshPageCollectionHashes = true) 1124 if ($this->_pageReferences === null || $refreshPageCollectionHashes) { 1125 $this->_refreshPagesHash(); 1128 if ($destination instanceof Zend_Pdf_Destination_Named) { 1129 if (!isset($this->_namedTargets[$destination->getName()])) { 1132 $destination = $this->getNamedDestination($destination->getName()); 1134 if ($destination instanceof Zend_Pdf_Action) { 1135 if (!$destination instanceof Zend_Pdf_Action_GoTo) { 1138 $destination = $destination->getDestination(); 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.
'); 1147 // Named target is an explicit destination 1148 $pageElement = $destination->getResource()->items[0]; 1150 if ($pageElement->getType() == Zend_Pdf_Element::TYPE_NUMERIC) { 1151 // Page reference is a PDF number 1152 if (!isset($this->_pageNumbers[$pageElement->value])) { 1156 return $this->_pageNumbers[$pageElement->value]; 1159 // Page reference is a PDF page dictionary reference 1160 $pageDictionaryHashId = spl_object_hash($pageElement->getObject()); 1161 if (!isset($this->_pageReferences[$pageDictionaryHashId])) { 1164 return $this->_pageReferences[$pageDictionaryHashId]; 1179 protected function _cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes = true) 1181 if ($this->_pageReferences === null || $refreshPageCollectionHashes) { 1182 $this->_refreshPagesHash(); 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 1192 // Walk through child actions 1193 $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST); 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(); 1206 foreach ($actionsToClean as $id => $action) { 1207 unset($action->next[$deletionCandidateKeys[$id]]); 1221 public function extractFonts() 1223 $fontResourcesUnique = array(); 1224 foreach ($this->pages as $page) { 1225 $pageResources = $page->extractResources(); 1227 if ($pageResources->Font === null) { 1228 // Page doesn't contain have any font reference
1232 $fontResources = $pageResources->Font;
1234 foreach ($fontResources->getKeys() as $fontResourceName) {
1235 $fontDictionary = $fontResources->$fontResourceName;
1239 #require_once 'Zend/Pdf/Exception.php'; 1240 throw new Zend_Pdf_Exception(
'Font dictionary has to be an indirect object or object reference.');
1243 $fontResourcesUnique[spl_object_hash($fontDictionary->getObject())] = $fontDictionary;
1248 #require_once 'Zend/Pdf/Exception.php'; 1249 foreach ($fontResourcesUnique as $resourceId => $fontDictionary) {
1252 #require_once 'Zend/Pdf/Resource/Font/Extracted.php'; 1255 $fonts[$resourceId] = $extractedFont;
1257 if ($e->getMessage() !=
'Unsupported font type.') {
1277 $fontResourcesUnique = array();
1278 #require_once 'Zend/Pdf/Exception.php'; 1279 foreach ($this->pages as
$page) {
1280 $pageResources =
$page->extractResources();
1282 if ($pageResources->Font ===
null) {
1287 $fontResources = $pageResources->Font;
1289 foreach ($fontResources->getKeys() as $fontResourceName) {
1290 $fontDictionary = $fontResources->$fontResourceName;
1294 #require_once 'Zend/Pdf/Exception.php'; 1295 throw new Zend_Pdf_Exception(
'Font dictionary has to be an indirect object or object reference.');
1298 $resourceId = spl_object_hash($fontDictionary->getObject());
1299 if (isset($fontResourcesUnique[$resourceId])) {
1303 $fontResourcesUnique[$resourceId] = 1;
1306 if ($fontDictionary->BaseFont->value != $fontName) {
1312 #require_once 'Zend/Pdf/Resource/Font/Extracted.php'; 1315 if ($e->getMessage() !=
'Unsupported font type.') {
1336 public function render($newSegmentOnly =
false, $outputStream =
null)
1338 if ($this->_isNewDocument) {
1340 $newSegmentOnly =
false;
1341 $this->_isNewDocument =
false;
1345 if ($this->properties != $this->_originalProperties) {
1348 foreach ($this->properties as $key =>
$value) {
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.
'); 1370 case 'CreationDate
': 1371 // break intentionally omitted 1373 $docInfo->$key = new Zend_Pdf_Element_String((string)$value); 1377 // break intentionally omitted 1379 // break intentionally omitted 1381 // break intentionally omitted 1383 // break intentionally omitted 1385 // break intentionally omitted 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); 1393 $docInfo->$key = new Zend_Pdf_Element_String((string)$value); 1397 // Set property using PDF type based on PHP type 1398 $docInfo->$key = Zend_Pdf_Element::phpToPdf($value); 1403 $this->_trailer->Info = $docInfo; 1406 $this->_dumpPages(); 1407 $this->_dumpNamedDestinations(); 1408 $this->_dumpOutlines(); 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 1418 if ($outputStream === null) { 1419 return $this->_trailer->getPDFString(); 1421 $pdfData = $this->_trailer->getPDFString(); 1422 while ( strlen($pdfData) > 0 && ($byteCount = fwrite($outputStream, $pdfData)) != false ) { 1423 $pdfData = substr($pdfData, $byteCount); 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(); 1435 // Array of cross-reference table subsections 1436 $xrefTable = array(); 1437 // Object numbers of first objects in each subsection 1438 $xrefSectionStartNums = array(); 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). 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). 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); 1458 $pdfSegmentBlocks = ($newSegmentOnly) ? array() : array($this->_trailer->getPDFString()); 1461 // Iterate objects to create new reference table 1462 foreach ($this->_objFactory->listModifiedObjects() as $updateInfo) { 1463 $objNum = $updateInfo->getObjNum(); 1465 if ($objNum - $lastObjNum != 1) { 1466 // Save cross-reference table subsection and start new one 1467 $xrefTable[] = $xrefSection; 1468 $xrefSection = array(); 1469 $xrefSectionStartNums[] = $objNum; 1472 if ($updateInfo->isFree()) { 1473 // Free object cross-reference table entry 1474 $xrefSection[] = sprintf("%010d %05d f \n", $lastFreeObject, $updateInfo->getGenNum()); 1475 $lastFreeObject = $objNum; 1477 // In-use object cross-reference table entry 1478 $xrefSection[] = sprintf("%010d %05d n \n", $offset, $updateInfo->getGenNum()); 1480 $pdfBlock = $updateInfo->getObjectDump(); 1481 $offset += strlen($pdfBlock); 1483 if ($outputStream === null) { 1484 $pdfSegmentBlocks[] = $pdfBlock; 1486 while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) { 1487 $pdfBlock = substr($pdfBlock, $byteCount); 1491 $lastObjNum = $objNum; 1493 // Save last cross-reference table subsection 1494 $xrefTable[] = $xrefSection; 1496 // Modify first entry (specail case - header of linked list of free objects). 1497 $xrefTable[0][0] = sprintf("%010d 65535 f \n", $lastFreeObject); 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; 1507 $this->_trailer->Size->value = $this->_objFactory->getObjectCount(); 1509 $pdfBlock = $xrefTableStr 1510 . $this->_trailer->toString() 1511 . "startxref\n" . $offset . "\n" 1514 $this->_objFactory->cleanEnumerationShiftCache(); 1516 if ($outputStream === null) { 1517 $pdfSegmentBlocks[] = $pdfBlock; 1519 return implode('', $pdfSegmentBlocks); 1521 while ( strlen($pdfBlock) > 0 && ($byteCount = fwrite($outputStream, $pdfBlock)) != false ) { 1522 $pdfBlock = substr($pdfBlock, $byteCount); 1536 public function setJavaScript($javaScript) 1538 $this->resetJavaScript(); 1540 $this->addJavaScript($javaScript); 1546 public function resetJavaScript() 1548 $this->_javaScript = null; 1550 $root = $this->_trailer->Root; 1551 if (null === $root->Names || null === $root->Names->JavaScript) { 1554 $root->Names->JavaScript = null; 1563 public function addJavaScript($javaScript) 1565 if (empty($javaScript)) { 1566 throw new Zend_Pdf_Exception( 1567 'JavaScript must be a non empty
string or array of strings
' 1571 if (!is_array($javaScript)) { 1572 $javaScript = array($javaScript); 1575 if (null === $this->_javaScript) { 1576 $this->_javaScript = $javaScript; 1578 $this->_javaScript = array_merge($this->_javaScript, $javaScript); 1581 if (!empty($this->_javaScript)) { 1584 foreach ($this->_javaScript as $javaScript) { 1586 'S
' => new Zend_Pdf_Element_Name('JavaScript
'), 1587 'JS
' => new Zend_Pdf_Element_String($javaScript) 1589 $items[] = new Zend_Pdf_Element_String('EmbeddedJS
'); 1590 $items[] = $this->_objFactory->newObject( 1591 new Zend_Pdf_Element_Dictionary($jsCode) 1595 $jsRef = $this->_objFactory->newObject( 1596 new Zend_Pdf_Element_Dictionary( 1597 array('Names
' => new Zend_Pdf_Element_Array($items)) 1601 if (null === $this->_trailer->Root->Names) { 1602 $this->_trailer->Root->Names = new Zend_Pdf_Element_Dictionary(); 1604 $this->_trailer->Root->Names->JavaScript = $jsRef; 1625 public static function pdfDate($timestamp = null) 1627 if ($timestamp === null) { 1628 $date = date('\D\:YmdHisO
'); 1630 $date = date('\D\:YmdHisO
', $timestamp); 1632 return substr_replace($date, '\
'', -2, 0) .
'\'';
_loadPages(Zend_Pdf_Element_Reference $pages, $attributes=array())
__construct($source=null, $revision=null, $load=false)
render($newSegmentOnly=false, $outputStream=null)
markTextFieldAsReadOnly($name)
_loadFormFields(Zend_Pdf_Element_Reference $root)
$_originalOpenOutlinesCount
setTextFieldProperties($name, $bitmask)
static parse(&$source=null, $revision=null)
static factory($backend, $backendOptions=array())
_cleanUpAction(Zend_Pdf_Action $action, $refreshPageCollectionHashes=true)
save($filename, $updateOnly=false)
static $_inheritableAttributes
const PDF_FORM_FIELD_READONLY
static setMemoryManager(Zend_Memory_Manager $memoryManager)
const PDF_FORM_FIELD_REQUIRED
const PDF_FORM_FIELD_NOEXPORT
static getMemoryManager()
_loadNamedDestinations(Zend_Pdf_Element_Reference $root, $pdfHeaderVersion)
_loadJavaScript(Zend_Pdf_Element_Reference $root)
static load(Zend_Pdf_Element $resource)
static createFactory($objCount)
resolveDestination(Zend_Pdf_Destination $destination, $refreshPageCollectionHashes=true)
_loadOutlines(Zend_Pdf_Element_Reference $root)
static load($source=null, $revision=null)
if(!isset($_GET['name'])) $name