Convert HTML and CSS into PDF documents on top of phppdf/phppdf.
- PHP 8.4+
ext-domext-libxml
composer require phppdf/html-converterThe documentation can be found here: https://phppdf.github.io/html-converter/
use PhpPdf\Html\HtmlConverter;
use PhpPdf\Output\PdfMemoryOutput;
use PhpPdf\Serialization\PdfDocumentSerializer;
$html = '<h1>Hello World</h1><p>Welcome to the PDF.</p>';
$document = HtmlConverter::fromHtml($html)->build();
$output = new PdfMemoryOutput();
(new PdfDocumentSerializer($output))->writeDocument($document);
header('Content-Type: application/pdf');
echo $output->getContent();Because HtmlConverter::fromHtml() returns a plain PdfDocumentBuilder, you can prepend or
append pages, add metadata/encryption/signatures, and apply compression before serialising.
Working examples live in the examples repository: https://github.com/phppdf/examples
composer install
composer phpunit
composer phpunit:coverage
composer phpcs
composer phpstan