brs-software/html2pdf

Common interface for converting HTML documents to PDF using adapters

v1.1.0 2015-12-23 12:08 UTC

This package is not auto-updated.

Last update: 2025-08-30 22:37:36 UTC


README

Common interface for converting HTML documents to PDF using adapters.

Available adapters

Examples

Example for Wkhtmltopdf adapter

<?php
use Brs\Html2Pdf\Html2Pdf;
use Brs\Html2Pdf\Adapter\Wkhtmltopdf;

// you can optionally test the environment
Wkhtmltopdf::testEnv();

$adapter = new Wkhtmltopdf;

// you can change path to binary on your server
$adapter->getWkhtmltopdfCmd()
    ->setPrefix('/special/path/to/whhtmltopdf')
;

// add wkhtmltopdf parameter
$adapter->getWkhtmltopdfCmd()
    ->add('--ignore-load-errors')
    ->add('--lowquality')
;

// if you must to use xvfb-run you can configure it
$adapter->getXvfbCmd()
    ->setPrefix('/special/path/to/xvfb-run')
    ->setArguments(['--server-args=-screen 0, 800x600x24'])
;

$converter = new Html2Pdf($adapter);

// set html file to convert
$converter->setHtmlFile('path/to/document.html');
// or html string
$converter->setHtmlDocument('
<html>
    <body>
        <strong>test pdf</strong>
    </body>
</html>
');
// or url
$converter->setUrl('http://google.com');

// generate the pdf file
$pdf = $converter->getPdfFile();

// send to client for download
$pdf->sendToBrowser('file.pdf');

// or save as local file
$pdf->saveAs('some/path/to/file.pdf');

Requirments

  • PHP 5.4 or higher