General entity which describes PDF document.

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
package Zend_Pdf
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Creates or loads PDF document.

__construct(string $source = null, integer $revision = null, boolean $load = false) : \Zend_Pdf

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

$source

string
  • PDF file to load

$revision

integer

$load

boolean

Exceptions

\Zend_Pdf_Exception

Returns

\Zend_Pdf

Appends JavaScript to the document-level JavaScript

addJavaScript(string|array $javaScript) 

Parameters

$javaScript

stringarray

Exceptions

\Zend_Pdf_Exception

Extract font attached to the page by specific font name

extractFont(string $fontName) : \Zend_Pdf_Resource_Font_Extracted | null

$fontName should be specified in UTF-8 encoding

Parameters

$fontName

string

Exceptions

\Zend_Pdf_Exception

Returns

\Zend_Pdf_Resource_Font_Extractednull

Extract fonts attached to the document

extractFonts() : array

returns array of Zend_Pdf_Resource_Font_Extracted objects

Exceptions

\Zend_Pdf_Exception

Returns

array

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

getJavaScript() : string

Returns

string

Request used memory manager

getMemoryManager() : \Zend_Memory_Manager
Static

Returns

\Zend_Memory_Manager

Return specified named destination

getNamedDestination(string $name) : \Zend_Pdf_Destination_Explicit | \Zend_Pdf_Action_GoTo

Parameters

$name

string

Returns

\Zend_Pdf_Destination_Explicit\Zend_Pdf_Action_GoTo

Return an associative array containing all the named destinations (or GoTo actions) in the PDF.

getNamedDestinations() : array

Named targets can be used to reference from outside the PDF, ex: 'http://www.something.com/mydocument.pdf#MyAction'

Returns

array

Get open Action Returns Zend_Pdf_Target (Zend_Pdf_Destination or Zend_Pdf_Action object)

getOpenAction() : \Zend_Pdf_Target

Returns

\Zend_Pdf_Target

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

getTextFieldNames() : array

Returns

arrayof strings

Load PDF document from a file

load(string $source = null, integer $revision = null) : \Zend_Pdf
Static

Parameters

$source

string

$revision

integer

Returns

\Zend_Pdf

Marks an AcroForm text field as read only

markTextFieldAsReadOnly(string $name) 

Parameters

$name

string

Create page object, attached to the PDF document.

newPage(mixed $param1, mixed $param2 = null) : \Zend_Pdf_Page

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

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

$param1

mixed

$param2

mixed

Returns

\Zend_Pdf_Page

Create new PDF document from a $source string

parse(string $source = null, integer $revision = null) : \Zend_Pdf
Static

Parameters

$source

string

$revision

integer

Returns

\Zend_Pdf

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

pdfDate(integer $timestamp = null) : string
Static
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

$timestamp

integer

(optional) If omitted, uses the current time.

Returns

string

Render the completed PDF to a string.

render(boolean $newSegmentOnly = false, resource $outputStream = null) : string

If $newSegmentOnly is true and it's not a new document, then only appended part of PDF is returned.

Parameters

$newSegmentOnly

boolean

$outputStream

resource

Exceptions

\Zend_Pdf_Exception

Returns

string

Resets the document-level JavaScript

resetJavaScript() 

Resolve destination.

resolveDestination(\Zend_Pdf_Destination $destination, boolean $refreshPageCollectionHashes = true) : \Zend_Pdf_Page | null

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

Parameters

$destination

\Zend_Pdf_Destination

Destination to resolve

$refreshPageCollectionHashes

boolean

Refresh page collection hashes before processing

Exceptions

\Zend_Pdf_Exception

Returns

\Zend_Pdf_Pagenull

Retrive number of revisions.

revisions() : integer

Returns

integer

Rollback document $steps number of revisions.

rollback(integer $steps) 

This method must be invoked before any changes, applied to the document. Otherwise behavior is undefined.

Parameters

$steps

integer

Render PDF document and save it.

save(string $filename, boolean $updateOnly = false

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

Parameters

$filename

string

$updateOnly

boolean

Exceptions

\Zend_Pdf_Exception

Sets the document-level JavaScript

setJavaScript(string|array $javaScript) 

Resets and appends

Parameters

$javaScript

stringarray

Set user defined memory manager

setMemoryManager(\Zend_Memory_Manager $memoryManager) 
Static

Parameters

$memoryManager

\Zend_Memory_Manager

Set specified named destination

setNamedDestination(string $name, \Zend_Pdf_Destination_Explicit|\Zend_Pdf_Action_GoTo $destination = null

Parameters

$name

string

$destination

\Zend_Pdf_Destination_Explicit\Zend_Pdf_Action_GoTo

Exceptions

\Zend_Pdf_Exception

Set open Action which is actually Zend_Pdf_Destination or Zend_Pdf_Action object

setOpenAction(\Zend_Pdf_Target $openAction = null
returns Zend_Pdf

Parameters

$openAction

\Zend_Pdf_Target

Sets the value of an AcroForm text field

setTextField(string $name, string $value) 

Parameters

$name

string

Name of textfield

$value

string

Value

Exceptions

\Zend_Pdf_Exception if the textfield does not exist in the pdf

Sets the properties for an AcroForm text field

setTextFieldProperties(string $name, mixed $bitmask) 

Parameters

$name

string

$bitmask

mixed

Exceptions

\Zend_Pdf_Exception

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

_cleanUpAction(\Zend_Pdf_Action $action, boolean $refreshPageCollectionHashes = true) : \Zend_Pdf_Action | null

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

todo Give appropriate name and make method public

Parameters

$action

\Zend_Pdf_Action

$refreshPageCollectionHashes

boolean

Refresh page collection hashes before processing

Returns

\Zend_Pdf_Actionnull

Dump named destinations

_dumpNamedDestinations() 
todo Create a balanced tree instead of plain structure.

Dump outlines recursively

_dumpOutlines() 

Orginize pages to tha pages tree structure.

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

Load form fields

_loadFormFields(\Zend_Pdf_Element_Reference $root) 

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

Parameters

$root

\Zend_Pdf_Element_Reference

Document catalog entry

Load JavaScript

_loadJavaScript(\Zend_Pdf_Element_Reference $root) 

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

Parameters

$root

\Zend_Pdf_Element_Reference

Document catalog entry

Load named destinations recursively

_loadNamedDestinations(\Zend_Pdf_Element_Reference $root, string $pdfHeaderVersion) 

Parameters

$root

\Zend_Pdf_Element_Reference

Document catalog entry

$pdfHeaderVersion

string

Exceptions

\Zend_Pdf_Exception

Load outlines recursively

_loadOutlines(\Zend_Pdf_Element_Reference $root) 

Parameters

$root

\Zend_Pdf_Element_Reference

Document catalog entry

Exceptions

\Zend_Pdf_Exception

Load pages recursively

_loadPages(\Zend_Pdf_Element_Reference $pages, array|null $attributes = array()

Parameters

$pages

\Zend_Pdf_Element_Reference

$attributes

arraynull

Exceptions

\Zend_Pdf_Exception

Refresh page collection hashes

_refreshPagesHash() : \Zend_Pdf

Returns

\Zend_Pdf

 Properties

 

Document outlines

$outlines : array

Default

array()
 

Pages collection

$pages : array

Default

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.
 

Document properties

$properties : array

Default

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)

 

List of form fields

$_formFields : array

Default

array()
 

List of inheritable attributesfor pages tree

$_inheritableAttributes : array

Default

array('Resources', 'MediaBox', 'CropBox', 'Rotate')
Static
 

True if the object is a newly created PDF document (affects save() method behavior) False otherwise

$_isNewDocument : boolean

Default

true
 

Document level javascript

$_javaScript : string

Default

null
 

Memory manager for stream objects

$_memoryManager : \Zend_Memory_Manager | null

Default

null
Static
 

Document named destinations or "GoTo.

$_namedTargets : array

Default

array()

.." actions, used to refer document parts from outside PDF

 

PDF objects factory.

$_objFactory : \Zend_Pdf_ElementFactory_Interface

Default

null
 

Original document outlines open elements count Used to track outlines update

$_originalOpenOutlinesCount : integer

Default

0
 

Original document outlines list Used to track outlines update

$_originalOutlines : array

Default

array()
 

Original properties set.

$_originalProperties : array

Default

array()

Used for tracking properties changes

 

Pages collection hash: <page number> => Zend_Pdf_Page

$_pageNumbers : array

Default

null
 

Pages collection hash: <page dictionary object hash id> => Zend_Pdf_Page

$_pageReferences : \SplObjectStorage

Default

null
 

Pdf file parser.

$_parser : \Zend_Pdf_Parser

Default

It's not used, but has to be destroyed only with Zend_Pdf object

 

Pdf trailer (last or just created)

$_trailer : \Zend_Pdf_Trailer

Default

null

 Constants

 

PDF_FORM_FIELD_NOEXPORT

PDF_FORM_FIELD_NOEXPORT = 4 
 

Form field options

PDF_FORM_FIELD_READONLY = 1 
 

PDF_FORM_FIELD_REQUIRED

PDF_FORM_FIELD_REQUIRED = 2 
 

PDF file header.

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

Version number of generated PDF documents.

PDF_VERSION = '1.4'