vianetz / pdf-generator
A library that supports method for generating PDF documents based on DomPdf and FPDI.
Installs: 20 974
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8
- dompdf/dompdf: ^2.0|^3.0
- setasign/fpdf: ^1.8
- setasign/fpdi: ^2.6
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9|^10|^11
Suggests
- horstoeko/zugferd: Create Zugferd documents with this merger library
- tecnickcom/tcpdf: Necessary if you want to use TCPDF for merging. By default this package uses the fpdf merger.
- vianetz/signaturportal-api: Use this library to sign your generated PDF documents.
README
This library offers an easy-to-use API for PDF generation and merging.
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.
Usage
Create PDF document from HTML contents
// Create a new pdf instance. $pdf = \Vianetz\Pdf\Model\PdfFactory::general()->create(); // Create the document. You can return any kind of HTML content here. $document = new \Vianetz\Pdf\Model\HtmlDocument('<strong>Hello</strong> World!'); // Add our document to the pdf. You can add as many documents as you like // as they will all be merged into one PDF file. $pdf->add($document); // Save the resulting PDF to file test.pdf - That's it :-) $pdf->saveToFile('test.pdf');
Merge a PDF file and a PDF string into one PDF file
// Load some random PDF contents $pdfString = file_get_contents('test1.pdf'); // Setup things $pdfMerge = \Vianetz\Pdf\Model\PdfMerge::create(); // Do the merge. $pdfMerge->mergePdfString($pdfString, 'background.pdf'); $pdfMerge->mergePdfFile('test2.pdf'); // Save the result PDF to file result.pdf. file_put_contents($fileName, $pdfMerge->toPdf());
Tips & Tricks
- The string literal
__PDF_TPC__
will be replaced with the total page count
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.