* @copyright 2002-2026 Nicola Asuni - Tecnick.com LTD
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/
// NOTE: local file reads (images, fonts, attachments) are restricted to an allowlist of
// trusted paths that covers this package tree, so run the examples in place. To read assets
// from other locations, list them in the 'allowedPaths' entry of the fileOptions constructor
// parameter (see E047_remote_resources_security.php).
// NOTE: run make fonts in the project root to generate the dependencies and example fonts.
// autoloader when using Composer
require __DIR__ . '/../vendor/autoload.php';
// define fonts directory
\define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
// autoloader when using RPM or DEB package installation
//require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php');
// main TCPDF object
$pdf = new \Com\Tecnick\Pdf\Tcpdf(
unit: \Com\Tecnick\Pdf\Page\Unit::Millimeter,
isunicode: true,
subsetfont: false,
compress: true,
mode: \Com\Tecnick\Pdf\PdfConformance::Pdfa3,
objEncrypt: null,
);
// ----------
$pdf->setCreator('tc-lib-pdf');
$pdf->setAuthor('Nicola Asuni');
$pdf->setSubject('tc-lib-pdf example: 001');
$pdf->setTitle('Example Invoice Factur-X 1.07 / ZUGFeRD 2.3');
$pdf->setKeywords('TCPDF tc-lib-pdf invoice Factur-X ZUGFeRD e-invoice XML');
$pdf->setPDFFilename('001_invoice.pdf');
$pdf->setViewerPreferences(['DisplayDocTitle' => true]);
$pdf->enableDefaultPageContent();
// ----------
// Insert fonts
$bfont1 = $pdf->font->insert($pdf->pon, 'dejavusans', '', 10);
// ----------
// Factur-X 1.07 / ZUGFeRD 2.3
$pageF01 = $pdf->addPage();
$pdf->setBookmark(name: 'Factur', link: '', level: 0, page: -1, posx: 0, posy: 0, fstyle: 'B', color: '');
$pdf->page->addContent($bfont1['out']);
$invoiceHTML = '
INVOICE EXAMPLE
Seller
ELEKTRON Industrieservice GmbH
Geschäftsführer Egon Schrempp Amtsgericht Stuttgart HRB 1234
Erfurter Strasse 13
74465 Demoort, DE
VAT: DE136695976
|
Invoice No.: 181301674
Invoice Date: 15.11.2024
Delivery Date: 01.11.2024
Order Ref.: per Mail vom 01.09.2024
Project: 13130162
|
Bill To:
ConsultingService GmbH
Attn: Liselotte Müller-Lüdenscheidt
Musterstr. 18
76138 Karlsruhe, DE
| Pos. |
Description |
Qty |
Unit |
Unit Price |
Amount |
| 01 |
TGA Obermonteur/Monteur Beamermontage |
3 |
HUR |
43.20 |
129.60 |
| 02 |
Beamer-Deckenhalterung Außerhalb Angebot |
1 |
H87 |
122.50 |
122.50 |
|
| Net Total | EUR 252.10 |
| VAT 19% | EUR 47.90 |
| Grand Total | EUR 300.00 |
| Prepaid | EUR 0.00 |
| Due Amount | EUR 300.00 |
|
Payment Terms: Zahlbar sofort rein netto
Bank: IBAN DE91100000000123456789
Payment Reference: Rechnung 181301674
Factur-X 1.07 / ZUGFeRD 2.3 — embedded XML attachment: factur-x.xml
';
$pdf->page->addContent($pdf->getHTMLCell($invoiceHTML, 15, 15, 180));
$invoiceXML = <<
Baurechnung
urn:cen.eu:en16931:2017
181301674
204
20241115
Rapport-Nr.: 42389 vom 01.11.2024
Im 2. OG BT1 Besprechungsraum eine Beamerhalterung an die Decke montiert. Dafür eine Deckenplatte ausgesägt. Beamerhalterung zur Montage auseinander gebaut. Ein Stromkabel für den Beamer, ein HDMI Kabel und ein VGA Kabel durch die Halterung gezogen. Beamerhalterung wieder zusammengebaut und Beamer montiert. Beamer verkabelt und ausgerichtet. Decke geschlossen.
01
01 Beamermontage
Für die doppelte Verlegung, falls erforderlich.
TGA Obermonteur/Monteur
43.2
43.2
3
VAT
S
19
129.6
02
02 Außerhalb Angebot
Beamer-Deckenhalterung
122.5
122.5
1
VAT
S
19
122.5
Liselotte Müller-Lüdenscheidt
549910
ELEKTRON Industrieservice GmbH
Geschäftsführer Egon Schrempp Amtsgericht Stuttgart HRB 1234
74465
Erfurter Strasse 13
Demoort
DE
DE136695976
16259
ConsultingService GmbH
76138
Musterstr. 18
Karlsruhe
DE
per Mail vom 01.09.2024
13130162
#ef=Aufmass.png
916
42389
#ef=ElektronRapport_neu-red.pdf
916
13130162
Projekt
20241101
Rechnung 181301674
EUR
58
DE91100000000123456789
47.9
VAT
252.1
S
19
Zahlbar sofort rein netto
252.1
0
0
252.1
47.9
300
0
300
420
XML;
// Factur-X/ZUGFeRD requires the XML to be embedded as text/xml with the
// AFRelationship set to "Alternative" and the exact file name "factur-x.xml".
$pdf->addContentAsEmbeddedFile(
file: 'factur-x.xml',
content: $invoiceXML,
mime: 'text/xml',
afrel: \Com\Tecnick\Pdf\AFRelationship::Alternative,
desc: 'Factur-X/ZUGFeRD electronic invoice',
);
$pdf->setCustomXMP('x:xmpmeta.rdf:RDF.rdf:Description.pdfaExtension:schemas.rdf:Bag', '
Factur-X PDFA Extension Schema
urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#
fx
DocumentFileName
Text
external
The name of the embedded XML document
DocumentType
Text
external
The type of the hybrid document in capital letters, e.g. INVOICE or ORDER
Version
Text
external
The actual version of the standard applying to the embedded XML document
ConformanceLevel
Text
external
The conformance level of the embedded XML document
');
$pdf->setCustomXMP('x:xmpmeta.rdf:RDF', '
INVOICE
factur-x.xml
1.0
EN 16931
');
// =============================================================
$rawpdf = $pdf->getOutPDFString();
$pdf->renderPDF(rawpdf: $rawpdf);