issidorov/html-pdf

dev-master 2017-07-05 12:52 UTC

README

This is wrapper on node library https://www.npmjs.com/package/html-pdf .

Simple example:

use issidorov\htmlPdf\Pdf;

$pdf = Pdf::fromHtmlFile($htmlFileName);
$pdf->writeToFile($pdfFileName);

Install

Install for Ubuntu:

$ sudo apt install composer npm nodejs-legacy libfontconfig
$ sudo npm install -g html-pdf
$ composer require issidorov/html-pdf

API

Create instance of class:

$pdf = Pdf::fromHtmlFile($htmlFileName);
// OR
$pdf = Pdf::fromHtmlContent($html);

Run convert to pdf file:

// Write to concrete file
$pdf->writeToFile($pdfFileName);

// Write to /tmp directory
$pdfFileName = $pdf->writeToTmpFile();

Set CSS and Images base directory:

$pdf->setBasePath(__DIR__ . '/assets');

Set page size:

$pdf->setSize('100mm', '50mm');
// OR
$pdf->setSizeByFormat('A4');

Set and remove border sizes:

// Set border
$pdf->setBoder('20mm', '20mm', '20mm', '20mm');

// Clean border
$pdf->removeBoder()

Set page headers:

$pdf->setHeaderHeight('50mm');
$pdf->setHeaderContent('<div>Header</div>');

Set page footers:

$pdf->setFooterHeight('50mm');
$pdf->setFooterContent('<div>Footer</div>');

Set page header content on first page:

$pdf->setHeaderContent('<div>First page</div>', 'first');