HTML to PDF converter for PHP using WebKit. Uses the wkhtmltopdf C library via FFI.

dev-master 2020-10-19 19:40 UTC

This package is auto-updated.

Last update: 2024-09-20 04:34:00 UTC


README

PDFKit is a PHP package that converts HTML to PDFs using WebKit.

Uses the wkhtmltopdf C library via PHP FFI.

Note: This package is a work in progress and its API is subject to change. Use in production environments not recommended.

Requirements

  • PHP 7.4 or later
  • FFI extension (see Dockerfile)
  • wkhtmltopdf library (see Dockerfile)

Installation

composer require chrisnharvey/pdfkit

Usage

use ChrisHarvey\PDFKit\PDFKit;
use ChrisHarvey\PDFKit\ConversionFailedException;

$pdfkit = new PDFKit();

// Add a page to the pdf
$pdfkit->add([
    'page' => 'http://example.com'
]);

$pdfkit->saveTo('example.pdf');

$pdfkit->onStageChanged(function () {
    echo "Moved to next stage";
});

$pdfKit->onProgressChanged(function ($percent) {
    echo $percent; // Print percentage
});

try {
    $pdfkit->convert();
} catch (ConversionFailedException $e) {
    print_r($e->getErrors());
    print_r($e->getWarnings());
}