ciltocruz/wkhtmltopdf-php-lib

HTML to PDF Converter based on wkhtmltopdf for PHP

0.12.6 2021-09-09 09:06 UTC

This package is auto-updated.

Last update: 2024-04-09 14:59:58 UTC


README

Stars Travis CI Build Status Gitlab Pipeline Gitlab coverage report Quality Gate Status License: MIT

Packagist Version Packagist Downloads Packagist PHP Version Support

Twitter

HTML to PDF Converter based on wkhtmltopdf for PHP. This code is based on wkhtmltopdf-bindings.

This PHP library allows generating PDF Files from a url or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage available on OSX, linux, windows.

This library contains windows and linux binaries. (0.12.6 version) Linux binaries are based on the debian version. Verify that your system is compatible.

(N.B. These static binaries are extracted from Debian7 packages, so it might not be compatible with non-debian based linux distros)

If you detect problems you can open an issue, no problem.

Installation using Composer

$ composer require ciltocruz/wkhtmltopdf-php-lib

Usage

Initialization

<?php

require __DIR__ . '/vendor/autoload.php';

use Ciltocruz\WkhtmltopdfPhpLib\WkHtmlToPdf;

$wkhtmltopdf = new WkHtmlToPdf();

Download PDF as a file

$wkhtmltopdf = new WkHtmlToPdf();
$wkhtmltopdf->set_html("your_html");
$wkhtmltopdf->render();
$wkhtmltopdf->output(WkHtmlToPdf::$PDF_DOWNLOAD, $fileOutputName);

Generate local pdf file

$wkhtmltopdf = new WkHtmlToPdf();
$wkhtmltopdf->set_html("your_html");
$wkhtmltopdf->render();
$wkhtmltopdf->output(WkHtmlToPdf::$PDF_SAVEFILE, $fileOutputName);

You can use WkHtmlToPdf::$PDF_ASSTRING for get the response as string.

Pass options to wkhtmlToPdf

// Type wkhtmltopdf -H to see the list of options

Use this wkhtmltopdf binary in other libraries

If you want to use wkhtmltopdf in other libraries you need to add these libraries in your composer.json:

Some suggestions are:

$ composer require mikehaertl/phpwkhtmltopdf
$ composer require knplabs/knp-snappy

And then you can use it setting the correspondant binary

<?php

use Knp\Snappy\Pdf;

$myProjectDirectory = '/path/to/my/project';

$snappy = new Pdf($myProjectDirectory . '/vendor/bin/wkhtmltopdf');

Note: You must use the version that corresponds to you. wkhtmltopdf for unix systems wkhtmltopdf64.exe for windows.

Maintainers

If you are interested in maintaining, feel free to open a PR. This library is maintained by the following people (alphabetically sorted) :

@ciltocruz

Credits

This library has been originally developed by ciltocruz.