PHPackages                             julwil/html-to-pdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. julwil/html-to-pdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

julwil/html-to-pdf
==================

Convert HTML markup into beautiful PDF files using the famous wkhtmltopdf library

v3.0(5y ago)0722MITPHPPHP &gt;=5.5.9

Since Apr 28Pushed 5y agoCompare

[ Source](https://github.com/julwil/html-to-pdf)[ Packagist](https://packagist.org/packages/julwil/html-to-pdf)[ RSS](/packages/julwil-html-to-pdf/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (6)Used By (0)

HtmlToPdf
=========

[](#htmltopdf)

Convert HTML markup into beautiful PDF files using the famous wkhtmltopdf library.

[![Build Status](https://camo.githubusercontent.com/519f6f9109c62924a39784e822f49ce729a5ff85094288722bb46307059e2569/68747470733a2f2f7472617669732d63692e6f72672f73706972697469782f68746d6c2d746f2d7064662e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/spiritix/html-to-pdf)[![Code Climate](https://camo.githubusercontent.com/beb99f1d587b52e2bb9c5bd2780a9e994d20ebde8d2e3f2f6f0a6d3db9ade7b0/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73706972697469782f68746d6c2d746f2d7064662f6261646765732f6770612e737667)](https://codeclimate.com/github/spiritix/html-to-pdf)[![Total Downloads](https://camo.githubusercontent.com/25ed797a5aab74023af84ac21c00baf8a9afb8bb0b170423f85ba4a72efb1fd4/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f68746d6c2d746f2d7064662f642f746f74616c2e737667)](https://packagist.org/packages/spiritix/html-to-pdf)[![Latest Stable Version](https://camo.githubusercontent.com/240b371ff725a6acccd9d86cc77bb2067a27b83a0139277578d88946e1f637af/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f68746d6c2d746f2d7064662f762f737461626c652e737667)](https://packagist.org/packages/spiritix/html-to-pdf)[![Latest Unstable Version](https://camo.githubusercontent.com/be81d7e5ab17596bb4bcb76c8f75b2b03a0f6caa9b77382efff21dd0823b2f0b/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f68746d6c2d746f2d7064662f762f756e737461626c652e737667)](https://packagist.org/packages/spiritix/html-to-pdf)[![License](https://camo.githubusercontent.com/cea097b5057ef6a7c6409d1dae551a80f5bf9b5d80392d4bcbde6a625f1f84cc/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f68746d6c2d746f2d7064662f6c6963656e73652e737667)](https://packagist.org/packages/spiritix/html-to-pdf)

**Unfortunately, wkhtmltopdf is based on a very outdated version of WebKit and [not really maintained anymore](https://github.com/wkhtmltopdf/wkhtmltopdf/issues). I've therefore recently launched a [new version](https://github.com/spiritix/php-chrome-html2pdf) of this library which is based on Google Chrome. Give it a try!**

Features
--------

[](#features)

- Does not require any complex installation or configuration, works out of the box
- Offers all [features](http://wkhtmltopdf.org/usage/wkhtmltopdf.txt) of wkhtmltopdf
- Possibility to get the HTML from an external URL
- Possibility to download, embed or save the generated PDF files (or even get their contents as a string)
- Supports PHP7

Requirements
------------

[](#requirements)

- PHP 5.5+
- Enabled program execution functions (proc\_open)
- Enabled 'fopen' wrappers (in order to use the URL to PDF functionality)
- Unix based operating system (Windows support will may be added in the future)

Installation
------------

[](#installation)

HtmlToPdf can be installed via [Composer](http://getcomposer.org) by requiring the `spiritix/html-to-pdf` package in your project's `composer.json`.

```
php composer.phar require spiritix/html-to-pdf
```

Usage
-----

[](#usage)

The usage of this library is pretty simple. You just need a converter instance, pass an input and an output handler to it and set some options if you like. After running the conversion, the converter will provide you with the output handler instance. Now you may use it's specific functionality to get your PDF file.

```
use Spiritix\HtmlToPdf\Converter;
use Spiritix\HtmlToPdf\Input\UrlInput;
use Spiritix\HtmlToPdf\Output\DownloadOutput;

$input = new UrlInput();
$input->setUrl('https://www.google.com');

$converter = new Converter($input, new DownloadOutput());

$converter->setOption('n');
$converter->setOption('d', '300');

$converter->setOptions([
    'no-background',
    'margin-bottom' => '100',
    'margin-top' => '100',
]);

$output = $converter->convert();
$output->download();
```

### Input handlers

[](#input-handlers)

The following input handlers are available:

- StringInput - Accepts the HTML contents as a string
- UrlInput - Fetch the HTML contents from an URL

### Output handlers

[](#output-handlers)

The following output handlers are available:

- StringOutput - Get the PDF contents as a string
- FileOutput - Store the PDF to your file system
- DownloadOutput - Force the browser to download the PDF file
- EmbedOutput - Force the browser to embed the PDF file

Options
-------

[](#options)

```
General Options
    allow                         Allow the file or files from the specified folder to be loaded (repeatable)
b,  book*                               Set the options one would usually set when printing a book
    collate                             Collate when printing multiple copies
    cookie                        Set an additional cookie (repeatable)
    cookie-jar                    Read and write cookies from and to the supplied cookie jar file
    copies                      Number of copies to print into the pdf file (default 1)
    cover*                         Use html document as cover. It will be inserted before the toc with no headers and footers
    custom-header                 Set an additional HTTP header (repeatable)
    debug-javascript                    Show javascript debugging output
H,  default-header*                     Add a default header, with the name of the page to the left, and the page number to the right, this is short for: header-left='[webpage]' header-right='[page]/[toPage]' top 2cm header-line
    disable-external-links*             Do no make links to remote web pages
    disable-internal-links*             Do no make local links
n,  disable-javascript                  Do not allow web pages to run javascript
    disable-pdf-compression*            Do not use lossless compression on pdf objects
    disable-smart-shrinking*            Disable the intelligent shrinking strategy used by WebKit that makes the pixel/dpi ratio none constant
    disallow-local-file-access          Do not allowed conversion of a local file to read in other local files, unless explecitily allowed with allow
d,  dpi                            Change the dpi explicitly (this has no effect on X11 based systems)
    enable-plugins                      Enable installed plugins (such as flash
    encoding                  Set the default text encoding, for input
    forms*                              Turn HTML form fields into pdf form fields
g,  grayscale                           PDF will be generated in grayscale
    ignore-load-errors                  Ignore pages that claimes to have encountered an error during loading
l,  lowquality                          Generates lower quality pdf/ps. Useful to shrink the result document space
B,  margin-bottom             Set the page bottom margin (default 10mm)
L,  margin-left               Set the page left margin (default 10mm)
R,  margin-right              Set the page right margin (default 10mm)
T,  margin-top                Set the page top margin (default 10mm)
    minimum-font-size              Minimum font size (default 5)
    no-background                       Do not print background
O,  orientation                  Set orientation to Landscape or Portrait
    page-height               Page height (default unit millimeter)
    page-offset*                Set the starting page number (default 1)
s,  page-size                     Set paper size to: A4, Letter, etc.
    page-width                Page width (default unit millimeter)
    password                  HTTP Authentication password
    post                         Add an additional post field (repeatable)
    post-file                     Post an aditional file (repeatable)
    print-media-type*                   Use print media-type instead of screen
p,  proxy                        Use a proxy
q,  quiet                               Be less verbose
    redirect-delay                Wait some milliseconds for js-redirects (default 200)
    replace*                      Replace [name] with value in header and footer (repeatable)
    stop-slow-scripts                   Stop slow running javascripts
    title                         The title of the generated pdf file (The title of the first document is used if not specified)
t,  toc*                                Insert a table of content in the beginning of the document
    use-xserver*                        Use the X server (some plugins and other stuff might not work without X11)
    user-style-sheet               Specify a user style sheet, to load with every page
    username                  HTTP Authentication username
    zoom                         Use this zoom factor (default 1)

Headers And Footer Options
    footer-center*                Centered footer text
    footer-font-name*             Set footer font name (default Arial)
    footer-font-size*             Set footer font size (default 11)
    footer-html*                   Adds a html footer
    footer-left*                  Left aligned footer text
    footer-line*                        Display line above the footer
    footer-right*                 Right aligned footer text
    footer-spacing*               Spacing between footer and content in mm (default 0)
    header-center*                Centered header text
    header-font-name*             Set header font name (default Arial)
    header-font-size*             Set header font size (default 11)
    header-html*                   Adds a html header
    header-left*                  Left aligned header text
    header-line*                        Display line below the header
    header-right*                 Right aligned header text
    header-spacing*               Spacing between header and content in mm (default 0)

Table Of Content Options
    toc-depth*                   Set the depth of the toc (default 3)
    toc-disable-back-links*             Do not link from section header to toc
    toc-disable-links*                  Do not link from toc to sections
    toc-font-name*                Set the font used for the toc (default Arial)
    toc-header-font-name*         The font of the toc header (if unset use toc-font-name)
    toc-header-font-size*         The font size of the toc header (default 15)
    toc-header-text*              The header text of the toc (default Table Of Contents)
    toc-l1-font-size*             Set the font size on level 1 of the toc (default 12)
    toc-l1-indentation*            Set indentation on level 1 of the toc (default 0)
    toc-l2-font-size*             Set the font size on level 2 of the toc (default 10)
    toc-l2-indentation*            Set indentation on level 2 of the toc (default 20)
    toc-l3-font-size*             Set the font size on level 3 of the toc (default 8)
    toc-l3-indentation*            Set indentation on level 3 of the toc (default 40)
    toc-l4-font-size*             Set the font size on level 4 of the toc (default 6)
    toc-l4-indentation*            Set indentation on level 4 of the toc (default 60)
    toc-l5-font-size*             Set the font size on level 5 of the toc (default 4)
    toc-l5-indentation*            Set indentation on level 5 of the toc (default 80)
    toc-l6-font-size*             Set the font size on level 6 of the toc (default 2)
    toc-l6-indentation*            Set indentation on level 6 of the toc (default 100)
    toc-l7-font-size*             Set the font size on level 7 of the toc (default 0)
    toc-l7-indentation*            Set indentation on level 7 of the toc (default 120)
    toc-no-dots*                        Do not use dots, in the toc

Outline Options
    dump-outline*                 Dump the outline to a file
    outline*                            Put an outline into the pdf
    outline-depth*               Set the depth of the outline (default 4)

Options marked * may not work on some servers.

```

Known issues and limitations
----------------------------

[](#known-issues-and-limitations)

- Does not work on Windows based systems

Contributing
------------

[](#contributing)

Contributions in any form are welcome. Please consider the following guidelines before submitting pull requests:

- **Coding standard** - It's mostly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) with some differences.
- **Add tests!** - Your PR won't be accepted if it doesn't have tests.
- **Create feature branches** - I won't pull from your master branch.

License
-------

[](#license)

HtmlToPdf is free software distributed under the terms of the MIT license.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~540 days

Total

5

Last Release

1866d ago

Major Versions

1.0.0 → v2.02016-05-18

v2.0.2 → v3.02021-03-30

PHP version history (2 changes)1.0.0PHP &gt;=5.4

v2.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c9a517c825bc80303076ac49ccf7b2f062a12b4ebbe7e07c75da31843da01b3?d=identicon)[julwil](/maintainers/julwil)

---

Top Contributors

[![spiritix](https://avatars.githubusercontent.com/u/2979494?v=4)](https://github.com/spiritix "spiritix (12 commits)")[![julwil](https://avatars.githubusercontent.com/u/34055912?v=4)](https://github.com/julwil "julwil (8 commits)")

---

Tags

phppdfhtmlconverterprinthtmltopdf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/julwil-html-to-pdf/health.svg)

```
[![Health](https://phpackages.com/badges/julwil-html-to-pdf/health.svg)](https://phpackages.com/packages/julwil-html-to-pdf)
```

###  Alternatives

[spiritix/html-to-pdf

Convert HTML markup into beautiful PDF files using the famous wkhtmltopdf library

1932.5k](/packages/spiritix-html-to-pdf)[spiritix/php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome

153472.0k3](/packages/spiritix-php-chrome-html2pdf)[daandesmedt/phpheadlesschrome

A PHP wrapper for using Google Chrome Headless mode. Convert URL or HTML to a PDF / screenshot. Easy to use and OOP interfaced.

92233.1k](/packages/daandesmedt-phpheadlesschrome)[kartik-v/mpdf

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support. This is a fork of the official mPDF library.

39328.4k1](/packages/kartik-v-mpdf)[kiwilan/php-ebook

PHP package to read metadata and extract covers from eBooks, comics and audiobooks.

3414.6k1](/packages/kiwilan-php-ebook)[renatio/dynamicpdf-plugin

October HTML to PDF converter using dompdf library.

3113.4k3](/packages/renatio-dynamicpdf-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
