Skip to content

Class ZugferdDocumentPdfMerger

HorstOeko edited this page Dec 27, 2024 · 25 revisions

Summary

Class representing the facillity adding existing XML data (file or data-string)
to an existing PDF with conversion to PDF/A

Example

Example for merging an existing PDF file with an existing XML file

use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$existingXmlFile = "/tmp/invoice_1.xml";
$existingPdfFile = "/tmp/emptypdf.pdf";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingXmlFile) || !file_exists($existingPdfFile)) {
    throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($existingXmlFile, $existingPdfFile))
    ->generateDocument()
    ->saveDocument($mergeToPdf);

Example for merging an existing PDF file with a string which contains the XML

use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$xmlString= "<xml>...</xml>";
$existingPdfFile = "/tmp/emptypdf.pdf";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingPdfFile)) {
    throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($xmlString, $existingPdfFile))
    ->generateDocument()
    ->saveDocument($mergeToPdf);

Example for merging a string which contains a PDF with an existing XML file

use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$existingXmlFile = "/tmp/invoice_1.xml";
$pdfString = "%PDF-1.4.....";
$mergeToPdf = "/tmp/fullpdf.pdf";

if (!file_exists($existingXmlFile)) {
    throw new \Exception("XML and/or PDF does not exist");
}

(new ZugferdDocumentPdfMerger($existingXmlFile, $pdfString))
    ->generateDocument()
    ->saveDocument($mergeToPdf);

Example for merging a string which contains a PDF with a string which contains the XML

use horstoeko\zugferd\ZugferdDocumentPdfMerger;

$xmlString= "<xml>...</xml>";
$pdfString = "%PDF-1.4.....";
$mergeToPdf = "/tmp/fullpdf.pdf";

(new ZugferdDocumentPdfMerger($xmlString, $pdfString))
    ->generateDocument()
    ->saveDocument($mergeToPdf);

Methods

__construct

Summary

Constructor

Signature

public function __construct(string $xmlDataOrFilename, string $pdfData): void
{
}

Parameters

Name Type Allows Null Description
xmlDataOrFilename string
The XML data as a string or the full qualified path to an XML-File
containing the XML-data
pdfData string
The full filename or a string containing the binary pdf data. This
is the original PDF (e.g. created by a ERP system)

setDeterministicModeEnabled

Summary

Set the the deterministic mode. This mode should only be used
for testing purposes

Signature

public function setDeterministicModeEnabled(bool $deterministicModeEnabled): static
{
}

Parameters

Name Type Allows Null Description
deterministicModeEnabled bool

Returns

Returns a value of type static

setAuthorTemplate

Summary

Set the template for the author meta information

Signature

public function setAuthorTemplate(string $authorTemplate): static
{
}

Parameters

Name Type Allows Null Description
authorTemplate string

Returns

Returns a value of type static

setKeywordTemplate

Summary

Set the template for the keyword meta information

Signature

public function setKeywordTemplate(string $keywordTemplate): static
{
}

Parameters

Name Type Allows Null Description
keywordTemplate string

Returns

Returns a value of type static

setTitleTemplate

Summary

Set the template for the title meta information

Signature

public function setTitleTemplate(string $titleTemplate): static
{
}

Parameters

Name Type Allows Null Description
titleTemplate string

Returns

Returns a value of type static

setSubjectTemplate

Summary

Set the template for the subject meta information

Signature

public function setSubjectTemplate(string $subjectTemplate): static
{
}

Parameters

Name Type Allows Null Description
subjectTemplate string

Returns

Returns a value of type static

setMetaInformationCallback

Summary

Set the user defined callback for generating custom meta information

Signature

public function setMetaInformationCallback(?callable $callback = null): static
{
}

Parameters

Name Type Allows Null Description
callback callable ✔️

Returns

Returns a value of type static