setasign\SetaPDF2\Merger
Merger The main class of the SetaPDF-Merger Component
File: /SetaPDF v2/Merger/Merger.php
Old class name (alias):
\SetaPDF_Merger
Class hierarchy
Summary
Methods
- __construct()
- _beforePageAdded()
- _checkOutlinesConfig()
- _checkPageNumber()
- _copyDefaultResources()
- _ensureNameConfig()
- _ensureOutlinesConfig()
- _getDocument()
- _handleAcroForms()
- _handleAcroFormsByMergingSameNamedFields()
- _handleAcroFormsByRenamingSameNamedFields()
- _handleNames()
- _handleOptionalContent()
- _handleOutlines()
- _removeFormFieldFromFieldTree()
- addDocument()
- addFile()
- cleanUp()
- getCurrentDocument()
- getDocument()
- getDocumentByFilename()
- getInitialDocument()
- getMaxFileHandler()
- getPageCount()
- merge()
- rewriteStringNamesCallback()
- setHandleNames()
- setMaxFileHandler()
- setRenameSameNamedFormFields()
- setWriter()
- writeDictionaryCallback()
Constants
COPY_OUTLINES_AS_CHILDS
Constant defines that existing outline items should be copied as child items to the newly created outline item
COPY_OUTLINES_TO_ROOT
Constant defines that existing outlines items should be copied to the outlines root
DESTINATION_FIT_MODE
Keyword for the destination fit mode.
DESTINATION_NAME
Keyword for the destination name.
OUTLINES_BOLD
Key for the bold style property of an outline item
OUTLINES_COLOR
Key for the color property of an outline item
OUTLINES_COPY
Key for the copy behavior of an outline item
OUTLINES_FIT_MODE
Key for the fit-mode property of an outline item destination
OUTLINES_ITALIC
Key for the italic style property of an outline item
OUTLINES_PARENT
Key for the parent property of an outline item
OUTLINES_TITLE
Key for the title property of an outline item
PAGES_ALL
PAGES_FIRST
Keyword for the first page
PAGES_LAST
Keyword for the last page
VERSION
Properties
$_adjustNameCallback
$_currentDocument
The currently processed document instance.
$_initialDocument
The initial document
The initial document is the document to which the new documents/pages will be added.
It will be created automatically if none was provided in the constructor.
$beforePageAddedCallback
A callback which is called just before a page is added to the new document
See
Methods
__construct()
The constructor.
Parameters
- $initialDocument : ?\SetaPDF_Core_Document
The initial document to start with
_beforePageAdded()
Will be called just before a page is added to the pages tree.
An own callback can be defined through the $beforePageAddedCallback property. Or this method can be overwritten to implement own logic in the scope of the class.
Parameters
- $page : \SetaPDF_Core_Document_Page
The page that will be added
- $pageNumber : int
The number of the page
_checkOutlinesConfig()
Checks the $outlinesConfig parameter if it is possible to add childs to the resulting outline item.
Parameters
- $outlinesConfig : string|array
The outlines config
_checkPageNumber()
null|int|string|array|callback $condition = null
Checks a page number against a condition.
Parameters
- $pageNumber : int
The page number
- $condition : null|int|string|array|callback
Valid conditions are:
- PAGES_XXX constant or null (equal to Merger::PAGES_ALL)
- Integer with the valid page number
- String with the valid page number or the valid range (e.g. '10-12')
- Array with all valid page numbers
- Callback with the arguments (int $pageNumber, \setasign\SetaPDF2\Core\Document $document)
Exceptions
_copyDefaultResources()
\SetaPDF_Core_Document_Catalog_AcroForm $resAcroForm,
\SetaPDF_Core_Document $resDocument
Helper method that copies the default resources in the AcroForm dictionary.
Parameters
- $acroForm : \SetaPDF_Core_Document_Catalog_AcroForm
- $resAcroForm : \SetaPDF_Core_Document_Catalog_AcroForm
- $resDocument : \SetaPDF_Core_Document
Exceptions
_ensureOutlinesConfig()
Ensures the outlines configuration array.
Parameters
- $outlinesConfig : array|string|null
_getDocument()
Get a document instance by filename.
Parameters
- $filename : string|\SetaPDF_Core_Document
The filename
- $cache : bool
Cache the document by filename
Exceptions
Throws Exception
_handleAcroForms()
Handle AcroForm data.
Parameters
- $touchedPdfs : array
Exceptions
Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\Parser\Pdf\InvalidTokenException
Throws \setasign\SetaPDF2\Core\Reader\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception
Throws \setasign\SetaPDF2\Exception
Throws \setasign\SetaPDF2\NotImplementedException
Throws Exception
_handleAcroFormsByMergingSameNamedFields()
Handles AcroForm data by merging same named form fields.
Parameters
- $touchedPdfs : array
Exceptions
Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\Parser\Pdf\InvalidTokenException
Throws \setasign\SetaPDF2\Core\Reader\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception
Throws \setasign\SetaPDF2\Exception
Throws \setasign\SetaPDF2\NotImplementedException
Throws Exception
_handleAcroFormsByRenamingSameNamedFields()
Handles AcroForm data by renaming same named form fields.
Parameters
- $touchedPdfs : array
Exceptions
Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\Parser\Pdf\InvalidTokenException
Throws \setasign\SetaPDF2\Core\Reader\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception
Throws \setasign\SetaPDF2\Exception
Throws \setasign\SetaPDF2\NotImplementedException
Throws Exception
_handleNames()
Imports names of all used documents and defined named destinations.
Parameters
- $touchedPdfs : array
- $namedDestinations : array
Exceptions
Throws \setasign\SetaPDF2\Core\DataStructure\Tree\KeyAlreadyExistsException
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws Exception
_handleOptionalContent()
Handles optional content data (Layers).
Parameters
- $touchedPdfs : array
Exceptions
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws Exception
_handleOutlines()
Handle creation and import of outlines.
Parameters
- $touchedPdfs : array
- $outlineTargets : array
Exceptions
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws Exception
_removeFormFieldFromFieldTree()
Removes a form field in its parent fields array
Parameters
- $fieldObject : \SetaPDF_Core_Type_IndirectObjectInterface
Exceptions
Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\Parser\Pdf\InvalidTokenException
Throws \setasign\SetaPDF2\Core\Reader\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception
Throws \setasign\SetaPDF2\Exception
addDocument()
mixed $pages = null,
string|array $nameConfig = null,
null|string|array $outlinesConfig = null,
bool $copyLayers = true
Add a document.
Same as addFile() but the document has to be passed as \setasign\SetaPDF2\Core\Document instance.
Parameters
- $documentOrConfig : \SetaPDF_Core_Document|array
The document or config array. If an array is passed the keys has to be named as the method parameters. All other parameters are optional then.
- $pages : mixed
The pages to add from the file. See _checkPageNumber() for a full description.
- $nameConfig : string|array
The configuration for a named destination for this file.
- $outlinesConfig : null|string|array
The outlines config
- $copyLayers : bool
Whether to copy layer information of the document
Exceptions
Throws \InvalidArgumentException
See
addFile()
mixed $pages = null,
string|array $nameConfig = null,
null|string|array $outlinesConfig = null,
bool $copyLayers = true
Add a document by filename.
The document could include dynamic content like form fields, links or any other page annotation.
Form fields are handled especially: If a document was added with form fields which names were already used by a previously added document the field name will be suffixed with a slash and a number.
This behavior may lead to corrupted java scripts which may calculate field sums by field names!
Parameters
- $filenameOrConfig : string|array
The filename or config array. If an array is passed the keys has to be named as the method parameters. All other parameters are optional then.
- $pages : mixed
The pages to add from the file. See _checkPageNumber() for a full description.
- $nameConfig : string|array
The configuration for a named destination for this file.
- $outlinesConfig : null|string|array
The outlines config,
- $copyLayers : bool
Whether to copy layer information of the document.
Exceptions
Throws \InvalidArgumentException
getCurrentDocument()
Get the currently processed document instance.
This method can be used to get the document instance that is actually processed if an Exception is thrown.
getDocumentByFilename()
bool $cache = true
Get a document instance by a filename.
Parameters
- $filename : string
The filename
- $cache : bool
Cache the document by filename
Exceptions
Throws Exception
getPageCount()
Helper method to get the page count of a document or file.
Parameters
- $filename : string|\SetaPDF_Core_Document
The filename or the document instance
- $cacheDocumentInstance : bool
Cache the document instance or not
Exceptions
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws Exception
merge()
Merges the documents/pages in memory.
This method merges the documents and/or pages to the initial document object without calling the save()-method. The document is hold in memory until it is "manually" saved through the initial document instance.
Exceptions
Throws \setasign\SetaPDF2\Core\Exception
Throws \setasign\SetaPDF2\Core\SecHandler\Exception
Throws \setasign\SetaPDF2\Core\Type\Exception
Throws Exception
Throws \Exception
rewriteStringNamesCallback()
Callback method for renaming string values of renamed names.
Parameters
- $document : \SetaPDF_Core_Document
The document instance
- $value : \SetaPDF_Core_Type_StringValue
The string value
See
setHandleNames()
?callback $adjustNameCallback = null
Defines that the document's name dictionaries are merged into the resulting document.
This behavior is enabled by default. It sadly needs much memory and script runtime, because name trees could be very huge.
Parameters
- $handleNames : bool
The flag status
- $adjustNameCallback : ?callback
See \setasign\SetaPDF2\Core\DataStructure\Tree\AbstractTree::merge() for a detailed description of the callback
setMaxFileHandler()
setRenameSameNamedFormFields()
Set the flag defining if same named form fields should be renamed (default behavior).
If this flag is set to false the fields will be merged so that all same named fields will have the same value. Notice that this could occur in an incorrect appearance if the initial values are different.
Parameters
- $renameSameNamedFormFields : bool
The flag status
setWriter()
Set the writer for the initial document.
Parameters
- $writer : \SetaPDF_Core_Writer_WriterInterface
The writer instance
writeDictionaryCallback()
Callback method for renaming values of renamed names.
Parameters
- $document : \SetaPDF_Core_Document
The document instance
- $dict : \SetaPDF_Core_Type_Dictionary
The dictionary