Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/chrisnharvey/pdfkit
- Owner: chrisnharvey
- License: mit
- Created: 2020-10-02T21:24:35.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-19T19:40:17.000Z (about 4 years ago)
- Last Synced: 2024-05-03T00:02:53.934Z (7 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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());
}
```