Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chrisnharvey/pdfkit

HTML to PDF conversion library using wkhtmltopdf via FFI
https://github.com/chrisnharvey/pdfkit

Last synced: about 4 hours ago
JSON representation

HTML to PDF conversion library using wkhtmltopdf via FFI

Awesome Lists containing this project

README

        

# PDFKit for PHP

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

Uses the [wkhtmltopdf](http://github.com/antialize/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

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