PHP code example of brs-software / html2pdf
1. Go to this page and download the library: Download brs-software/html2pdf library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brs-software / html2pdf example snippets
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');