2017 © Pedro Peláez
 

library h2p

A simple library to convert HTML files to PDF using PhantomJS

image

kriansa/h2p

A simple library to convert HTML files to PDF using PhantomJS

  • Monday, November 20, 2017
  • by kriansa
  • Repository
  • 10 Watchers
  • 74 Stars
  • 52,653 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 37 Forks
  • 7 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

H2P Build Status Maintenance

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., (*1)

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., (*2)

You can download it here: http://phantomjs.org/download.html, (*3)

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:, (*4)

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

$converter = new PhantomJS();
$input = new TempFile('<b>test string to pdf</b>', '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

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., (*5)

Composer

Just put { "kriansa/h2p": "dev-master" } into your require property., (*6)

License

  • MIT License

The Versions

20/11 2017

dev-master

9999999-dev http://github.com/kriansa/h2p

A simple library to convert HTML files to PDF using PhantomJS

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Daniel Garajau

html pdf phantomjs

20/07 2014

v2.0.0

2.0.0.0 http://github.com/kriansa/h2p

A simple library to convert HTML files to PDF using PhantomJS

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Daniel Garajau

html pdf phantomjs

29/04 2013

v1.0

1.0.0.0 http://github.com/kriansa/h2p

A simple library to convert HTML files to PDF using PhantomJS

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Daniel Garajau

html pdf phantomjs