Skip to content

chrisnharvey/pdfkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDFKit for PHP

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());
}

About

HTML to PDF conversion library using wkhtmltopdf via FFI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published