Pdf.php
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Pdf
- Version
- $Id: Pdf.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Pdf
It implements document abstraction with a document level operations.
Class is used to create new PDF document or load existing document. See details in a class constructor description
Class agregates document level properties and entities (pages, bookmarks, document level actions, attachments, form object, etc)
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants
Properties

array $_inheritableAttributes = array('Resources', 'MediaBox', 'CropBox', 'Rotate')array('Resources', 'MediaBox', 'CropBox', 'Rotate')Details- Type
- array

boolean $_isNewDocument = truetrueDetails- Type
- boolean

\Zend_Memory_Manager|null $_memoryManager = nullnullDetails- Type
- \Zend_Memory_Manager | null

array $_namedTargets = array().." actions, used to refer document parts from outside PDF
array()Details- Type
- array

integer $_originalOpenOutlinesCount = 00Details- Type
- integer

array $_originalOutlines = array()array()Details- Type
- array

array $_originalProperties = array()Used for tracking properties changes
array()Details- Type
- array

\SplObjectStorage $_pageReferences = nullnullDetails
\Zend_Pdf_Parser $_parserIt's not used, but has to be destroyed only with Zend_Pdf object
- Type
- \Zend_Pdf_Parser

array $pages = array()array()Details- Type
- array
- Todo
- implement it as a class, which supports ArrayAccess and Iterator interfaces, to provide incremental parsing and pages tree updating. That will give good performance and memory (PDF size) benefits.

array $properties = array()It's an associative array with PDF meta information, values may be string, boolean or float. Returned array could be used directly to access, add, modify or remove document properties.
Standard document properties: Title (must be set for PDF/X documents), Author, Subject, Keywords (comma separated list), Creator (the name of the application, that created document, if it was converted from other format), Trapped (must be true, false or null, can not be null for PDF/X documents)
array()Details- Type
- array
Methods

__construct(string $source = null, integer $revision = null, $load = false) : \Zend_PdfCreates 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 - ...)
| Name | Type | Description |
|---|---|---|
| $source | string |
|
| $revision | integer | |
| $load |
| Type | Description |
|---|---|
| \Zend_Pdf |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

_cleanUpAction(\Zend_Pdf_Action $action, $refreshPageCollectionHashes = true) : \Zend_Pdf_Action | nullWalk 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.
| Name | Type | Description |
|---|---|---|
| $action | \Zend_Pdf_Action | |
| $refreshPageCollectionHashes |
| Type | Description |
|---|---|
| \Zend_Pdf_Action | null |
- Todo
- Give appropriate name and make method public

_dumpNamedDestinations() : voidDump named destinations
- Todo
- Create a balanced tree instead of plain structure.

_dumpPages() : voidOrginize pages to tha pages tree structure.
- Todo
- atomatically attach page to the document, if it's not done yet.
- Todo
- check, that page is attached to the current document
- Todo
- Dump pages as a balanced tree instead of a plain set.

_loadNamedDestinations(\Zend_Pdf_Element_Reference $root, string $pdfHeaderVersion) : voidLoad named destinations recursively
| Name | Type | Description |
|---|---|---|
| $root | \Zend_Pdf_Element_Reference | Document catalog entry |
| $pdfHeaderVersion | string |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

_loadOutlines(\Zend_Pdf_Element_Reference $root) : voidLoad outlines recursively
| Name | Type | Description |
|---|---|---|
| $root | \Zend_Pdf_Element_Reference | Document catalog entry |

_loadPages(\Zend_Pdf_Element_Reference $pages, array | null $attributes = array()) : voidLoad pages recursively
| Name | Type | Description |
|---|---|---|
| $pages | \Zend_Pdf_Element_Reference | |
| $attributes | array | null |

extractFont( $fontName) : \Zend_Pdf_Resource_Font_Extracted | nullExtract font attached to the page by specific font name
$fontName should be specified in UTF-8 encoding
| Name | Type | Description |
|---|---|---|
| $fontName |
| Type | Description |
|---|---|
| \Zend_Pdf_Resource_Font_Extracted | null |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

extractFonts() : arrayExtract fonts attached to the document
returns array of Zend_Pdf_Resource_Font_Extracted objects
| Type | Description |
|---|---|
| array |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

getJavaScript() : stringReturn the document-level JavaScript or null if there is no JavaScript for this document
| Type | Description |
|---|---|
| string |

getMemoryManager() : \Zend_Memory_ManagerRequest used memory manager
| Type | Description |
|---|---|
| \Zend_Memory_Manager |

getMetadata() : stringReturn the document-level Metadata or null Metadata stream is not presented
| Type | Description |
|---|---|
| string |

getNamedDestination(string $name) : \Zend_Pdf_Destination_Explicit | \Zend_Pdf_Action_GoToReturn specified named destination
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| \Zend_Pdf_Destination_Explicit | \Zend_Pdf_Action_GoTo |

getNamedDestinations() : arrayReturn 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'
| Type | Description |
|---|---|
| array |

getOpenAction() : \Zend_Pdf_TargetGet open Action Returns Zend_Pdf_Target (Zend_Pdf_Destination or Zend_Pdf_Action object)
| Type | Description |
|---|---|
| \Zend_Pdf_Target |

load(string $source = null, integer $revision = null) : \Zend_PdfLoad PDF document from a file
| Name | Type | Description |
|---|---|---|
| $source | string | |
| $revision | integer |
| Type | Description |
|---|---|
| \Zend_Pdf |

newPage(mixed $param1, mixed $param2 = null) : \Zend_Pdf_PageCreate page object, attached to the PDF document.
Method signatures:
- 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);
- 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);
| Name | Type | Description |
|---|---|---|
| $param1 | mixed | |
| $param2 | mixed |
| Type | Description |
|---|---|
| \Zend_Pdf_Page |

parse(string $source = null, integer $revision = null) : \Zend_PdfCreate new PDF document from a $source string
| Name | Type | Description |
|---|---|---|
| $source | string | |
| $revision | integer |
| Type | Description |
|---|---|
| \Zend_Pdf |

pdfDate(integer $timestamp = null) : stringConvert date to PDF format (it's close to ASN.1 (Abstract Syntax Notation One) defined in ISO/IEC 8824).
| Name | Type | Description |
|---|---|---|
| $timestamp | integer | (optional) If omitted, uses the current time. |
| Type | Description |
|---|---|
| string |
- 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.

render(boolean $newSegmentOnly = false, resource $outputStream = null) : stringRender 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.
| Name | Type | Description |
|---|---|---|
| $newSegmentOnly | boolean | |
| $outputStream | resource |
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

resolveDestination(\Zend_Pdf_Destination $destination, $refreshPageCollectionHashes = true) : \Zend_Pdf_Page | nullResolve destination.
Returns Zend_Pdf_Page page object or null if destination is not found within PDF document.
| Name | Type | Description |
|---|---|---|
| $destination | \Zend_Pdf_Destination | Destination to resolve |
| $refreshPageCollectionHashes |
| Type | Description |
|---|---|
| \Zend_Pdf_Page | null |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

rollback(integer $steps) : voidRollback document $steps number of revisions.
This method must be invoked before any changes, applied to the document. Otherwise behavior is undefined.
| Name | Type | Description |
|---|---|---|
| $steps | integer |

save(string $filename, boolean $updateOnly = false) : voidRender 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.
| Name | Type | Description |
|---|---|---|
| $filename | string | |
| $updateOnly | boolean |
| Exception | Description |
|---|---|
| \Zend_Pdf_Exception |

setJavaScript(string $javascript) : voidSet the document-level JavaScript
| Name | Type | Description |
|---|---|---|
| $javascript | string |

setMemoryManager(\Zend_Memory_Manager $memoryManager) : voidSet user defined memory manager
| Name | Type | Description |
|---|---|---|
| $memoryManager | \Zend_Memory_Manager |

setMetadata(string $metadata) : voidSets the document-level Metadata (mast be valid XMP document)
| Name | Type | Description |
|---|---|---|
| $metadata | string |

setNamedDestination(string $name, $destination = null) : voidSet specified named destination
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $destination |

setOpenAction(\Zend_Pdf_Target $openAction = null) : voidSet open Action which is actually Zend_Pdf_Destination or Zend_Pdf_Action object
| Name | Type | Description |
|---|---|---|
| $openAction | \Zend_Pdf_Target |
- Returns
- Zend_Pdf