Download the PHP package vianetz/pdf-generator without Composer
On this page you can find all versions of the php package vianetz/pdf-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vianetz/pdf-generator
More information about vianetz/pdf-generator
Files in vianetz/pdf-generator
Package pdf-generator
Short Description A library that generates PDF documents from HTML and other PDFs.
License GPL-3.0-or-later
Homepage https://www.vianetz.com
Informations about the package pdf-generator
vianetz Pdf Library
Generate PDF documents from HTML and merge them into one file - in pure PHP, without a headless browser or any other system binary, so it runs wherever your application runs.
Internally it uses the DomPDF library for PDF generation and FPDI for merging.
More information about this PDF API can also be found on my website.
Installation
Requires PHP 7.4 or later. Optionally install horstoeko/zugferd for attachments (ZUGFeRD / Factur-X)
or tecnickcom/tcpdf for the TCPDF based merger.
Usage
Create PDF document from HTML
Use $pdf->toPdf() to get the raw contents instead. Besides HtmlDocument you may also add existing
PDF files via $pdf->add(new \Vianetz\Pdf\Model\PdfDocument('terms.pdf')).
Each document is rendered on its own and the results are merged, so every document keeps its own header and footer data.
Configuration
Supported paper sizes are a3, a4, a5, letter and legal - any other size throws an
UnsupportedPaperSizeException. See Config for further settings (temp dir, chroot dir).
Background templates
Each page can be stamped onto a template PDF, e.g. your letterhead:
Merge two PDF files into one PDF
PdfMerge::create() optionally takes the merger to use - Merger\Fpdf (default) or Merger\Fpdi (TCPDF).
Pages are placed on the configured paper size, so a larger source gets cropped.
Attachments (ZUGFeRD / Factur-X)
ZugferdFpdf is the only merger supporting attachments, all others throw a \LogicException. As the
factory always wires up the default merger you need to compose the pdf yourself:
Events
Pass an EventManagerInterface implementation as second argument to create() to hook into the
pipeline - the default NoneEventManager does nothing.
| Event | Dispatched | Data |
|---|---|---|
vianetz_pdf_document_render_before |
before each document is rendered | document, merger |
vianetz_pdf_document_render_after |
after each document has been merged | document, merger |
vianetz_pdf_get_contents |
every time toPdf() returns |
contents |
The merger belongs to the render in progress and must not be kept beyond it.
Error handling
A missing background template, an unreadable PDF file or an empty document throws rather than producing
a partial PDF. All exceptions implement \Vianetz\Pdf\Exception, so one catch block covers them all:
Tips & Tricks
- The string literal
__PDF_TPC__will be replaced with the total page count - Inline PHP and remote resources are enabled in the renderer, so do not pass untrusted HTML
Frequently Asked Questions
Please find the Frequently Asked Questions on my website.
Support
If you have any issues or suggestions with this extension, please do not hesitate to contact me.
License
GNU General Public License v3.0
See also LICENSE file.
This extension uses the DomPDF library. For license information please visit the DomPdf
repository.
This extension uses the FPDI library. For license information please visit the FPDI
repository.
This library uses Semantic Versioning - please find more information at semver.org.
All versions of pdf-generator with dependencies
dompdf/dompdf Version ^3.0
setasign/fpdi Version ^2.6
setasign/fpdf Version ^1.8