PHPackages                             kriansa/h2p - 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. kriansa/h2p

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

kriansa/h2p
===========

A simple library to convert HTML files to PDF using PhantomJS

v2.0.0(11y ago)75105.4k↓34.6%35[2 issues](https://github.com/kriansa/h2p/issues)[2 PRs](https://github.com/kriansa/h2p/pulls)MITPHPPHP &gt;=5.3.0

Since Apr 29Pushed 6y ago10 watchersCompare

[ Source](https://github.com/kriansa/h2p)[ Packagist](https://packagist.org/packages/kriansa/h2p)[ Docs](http://github.com/kriansa/h2p)[ RSS](/packages/kriansa-h2p/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

H2P [![Build Status](https://camo.githubusercontent.com/de234061ed5b6328af598798f46031e4279d731811c0bb8ff9849a336570c5a4/68747470733a2f2f6170692e7472617669732d63692e6f72672f6b7269616e73612f6832702e706e67)](https://travis-ci.org/kriansa/h2p) ![Maintenance](https://camo.githubusercontent.com/87386a441039a590276660c21c87c29d1903ff538a6fada13d6a1c21f4fbb685/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f6e6f2f323031342e737667)
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#h2p--)

Convert your HTML files to PDF with ease. Thanks to PhantomJS, you can write CSS3, HTML5 and Javascript and it will convert and print your files just like you see them in your browser.

How to use
----------

[](#how-to-use)

It's very simple, but first you must download the PhantomJS binary file according to your system (Windows, Mac, Linux-X86 or Linux-X86\_64) and put it in the right **bin** folder.

You can download it here:

Getting started
---------------

[](#getting-started)

```
use H2P\Converter\PhantomJS;

$converter = new PhantomJS();

// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert('http://www.google.com/', '/home/user/Documents/page.pdf');
```

If you want to convert a HTML string, do it like so:

```
use H2P\Converter\PhantomJS;
use H2P\TempFile;

$converter = new PhantomJS();
$input = new TempFile('test string to pdf', 'html'); // Make sure the 2nd parameter is 'html'

// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert($input, '/home/user/Documents/page.pdf');
```

Advanced usage
--------------

[](#advanced-usage)

```
use H2P\Converter\PhantomJS;
use H2P\TempFile;
use H2P\Request;
use H2P\Request\Cookie;

$converter = new PhantomJS(array(
    // You should use 'search_paths' when you want to point the phantomjs binary to somewhere else
    // 'search_paths' => shell_exec('which phantomjs'),
    'orientation' => PhantomJS::ORIENTATION_LANDSCAPE,
    'format' => PhantomJS::FORMAT_A4,
    'zoomFactor' => 2,
    'border' => '1cm',
    'header' => array(
        'height' => '1cm',
        'content' => "{{pageNum}} / {{totalPages}}",
    ),
    'footer' => array(
        'height' => '1cm',
        'content' => "{{pageNum}} / {{totalPages}}",
    ),
));

// Create a full custom request
$request = new Request(
    'http://www.google.com/',
    Request::METHOD_POST,
    array('param' => 'value'), // POST params
    array('X-Header' => 'value'), // Custom headers
    array(
        new Cookie('Cookie', 'value', 'domain'), // Create a basic cookie
    )
);

$destination = new TempFile();
$converter->convert($request, $destination);
```

You can find more examples in the **samples** folder.

Composer
--------

[](#composer)

Just put `{ "kriansa/h2p": "dev-master" }` into your require property.

License
-------

[](#license)

- MIT License

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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 ~446 days

Total

2

Last Release

4321d ago

Major Versions

v1.0 → v2.0.02014-07-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/dede651222a48325e775b7da801efa06e33a7ef874f0167809d0d1dfdbc46b9d?d=identicon)[kriansa](/maintainers/kriansa)

---

Top Contributors

[![kriansa](https://avatars.githubusercontent.com/u/962032?v=4)](https://github.com/kriansa "kriansa (13 commits)")[![timmipetit](https://avatars.githubusercontent.com/u/1635904?v=4)](https://github.com/timmipetit "timmipetit (1 commits)")[![vjnrv](https://avatars.githubusercontent.com/u/99794?v=4)](https://github.com/vjnrv "vjnrv (1 commits)")

---

Tags

pdfhtmlphantomjs

### Embed Badge

![Health badge](/badges/kriansa-h2p/health.svg)

```
[![Health](https://phpackages.com/badges/kriansa-h2p/health.svg)](https://phpackages.com/packages/kriansa-h2p)
```

###  Alternatives

[spipu/html2pdf

Html2Pdf is a HTML to PDF converter written in PHP - It uses TCPDF - OFFICIAL PACKAGE

1.8k10.6M45](/packages/spipu-html2pdf)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3685.2M19](/packages/gotenberg-gotenberg-php)[kartik-v/yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.

1605.5M84](/packages/kartik-v-yii2-mpdf)[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1623.1M35](/packages/kartik-v-yii2-export)[spiritix/php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome

153472.0k3](/packages/spiritix-php-chrome-html2pdf)[danielboendergaard/phantom-pdf

A Package for generating PDF files using PhantomJS

72467.9k](/packages/danielboendergaard-phantom-pdf)

PHPackages © 2026

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