All Projects → spiritix → php-chrome-html2pdf

spiritix / php-chrome-html2pdf

Licence: MIT License
A PHP library for converting HTML to PDF using Google Chrome

Programming Languages

PHP
23972 projects - #3 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to php-chrome-html2pdf

puppeteer-report
Convert HTML to PDF by Puppeteer with support of adding a custom header, footer, and page number
Stars: ✭ 90 (+69.81%)
Mutual labels:  htmltopdf, puppeteer, puppeteer-pdf
web-to-pdf
Convert any web technology to PDF (HTML to PDF, html2pdf)
Stars: ✭ 39 (-26.42%)
Mutual labels:  html2pdf, htmltopdf
FlareSolverrSharp
FlareSolverr .Net / Proxy server to bypass Cloudflare protection
Stars: ✭ 62 (+16.98%)
Mutual labels:  puppeteer
protonmail-api
✉ Node.js API for ProtonMail
Stars: ✭ 108 (+103.77%)
Mutual labels:  puppeteer
php-puppeteer
PHP Wrapper of Google Chrome Puppeteer for PDF Generation
Stars: ✭ 24 (-54.72%)
Mutual labels:  puppeteer
screenie-server
A Node server with a pool of Puppeteer (Chrome headless) instances for scalable screenshot generation.
Stars: ✭ 19 (-64.15%)
Mutual labels:  puppeteer
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (-56.6%)
Mutual labels:  puppeteer
screenshot
A screenshot API to convert web to image or PDF. Supports desktop and mobile views.
Stars: ✭ 108 (+103.77%)
Mutual labels:  puppeteer
messages-web
📱 SMS gateway using your own phone!
Stars: ✭ 34 (-35.85%)
Mutual labels:  puppeteer
facebook-login-for-robots
Facebook Login for 🤖 robots
Stars: ✭ 41 (-22.64%)
Mutual labels:  puppeteer
docker-google-lighthouse-puppeteer
Google Lighthouse + Puppeteer / Docker Image
Stars: ✭ 29 (-45.28%)
Mutual labels:  puppeteer
puppeteer-email
Email automation driven by headless chrome.
Stars: ✭ 135 (+154.72%)
Mutual labels:  puppeteer
lab-assistant
A tool to measure performance deltas between two versions of a site
Stars: ✭ 20 (-62.26%)
Mutual labels:  puppeteer
tees
Universal test framework for front-end with WebDriver, Puppeteer and Enzyme
Stars: ✭ 23 (-56.6%)
Mutual labels:  puppeteer
naos
📉 Uptime and error monitoring CLI
Stars: ✭ 30 (-43.4%)
Mutual labels:  puppeteer
gotenberg-js-client
A simple JS/TS client for interacting with a Gotenberg API
Stars: ✭ 90 (+69.81%)
Mutual labels:  pdf-converter
pappet
A command-line tool to crawl websites using puppeteer.
Stars: ✭ 95 (+79.25%)
Mutual labels:  puppeteer
xstate-marionettist
Model based testing with Jest, XState and Puppeteer or Playwright made easy
Stars: ✭ 23 (-56.6%)
Mutual labels:  puppeteer
hotshot
Takes screenshots of DOM elements
Stars: ✭ 19 (-64.15%)
Mutual labels:  puppeteer
TrackPurchase
단 몇줄의 코드로 다양한 쇼핑 플랫폼에서 결제 내역을 긁어오자!
Stars: ✭ 19 (-64.15%)
Mutual labels:  puppeteer

PHP Chrome HTML to PDF

A PHP library for converting HTML to PDF using Google Chrome.

Build Status Code Climate Total Downloads Latest Stable Version Latest Unstable Version License

How it works

This library is based on puppeteer, a headless Chrome Node API which is maintained by the Chrome DevTools team.

It provides a simple PHP wrapper around the Node API, focused on generating beautiful PDF files.

In contrast to other HTML to PDF converters like wkhtmltopdf, the corresponding PHP wrapper or similar libraries, it is based on a current Chrome version instead of outdated and unmaintained WebKit builds. This library therefore fully supports CSS3, HTML5, SVGs, SPAs, and all the other fancy stuff people use these days.

Requirements

  • PHP 7.0+ with enabled program execution functions (proc_open) and 'fopen wrappers'
  • Node.js 10.18.1+ (for older Node.js versions use v.1.4.1)
  • A few OS specific dependencies

Installation

PHP Chrome HTML to PDF can be installed via Composer by requiring the spiritix/php-chrome-html2pdf package in your project's composer.json. Or simply run this command:

composer require spiritix/php-chrome-html2pdf

The required JS packages are installed automatically in the background.

Usage

Using this library is pretty straight forward. Decide for an input and an output handler, pass them to the converter, set some options if you like and depending on the output handler, proceed with the generated PDF file.

use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;

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

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

$converter->setOption('landscape', true);

$converter->setOptions([
    'printBackground' => true,
    'displayHeaderFooter' => true,
    'headerTemplate' => '<p>I am a header</p>',
]);

$output = $converter->convert();
$output->download('google.pdf');

Input handlers

The following input handlers are available:

  • StringInput - Accepts the HTML content as a string
  • UrlInput - Fetches the HTML content from an URL

Output handlers

The following output handlers are available:

  • StringOutput - Returns the binary PDF content as a string
  • FileOutput - Stores the PDF file on the server's file system
  • DownloadOutput - Forces the browser to download the PDF file
  • EmbedOutput - Forces the browser to embed the PDF file

Options

  • scale <[number]> Scale of the webpage rendering. Defaults to 1.
  • displayHeaderFooter <[boolean]> Display header and footer. Defaults to false.
  • headerTemplate <[string]> HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
    • date formatted print date
    • title document title
    • url document location
    • pageNumber current page number
    • totalPages total pages in the document
  • footerTemplate <[string]> HTML template for the print footer. Should use the same format as the headerTemplate.
  • printBackground <[boolean]> Print background graphics. Defaults to false.
  • landscape <[boolean]> Paper orientation. Defaults to false.
  • pageRanges <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
  • format <[string]> Paper format. If set, takes priority over width or height options. Defaults to 'Letter'.
  • width <[string]> Paper width, accepts values labeled with units.
  • height <[string]> Paper height, accepts values labeled with units.
  • margin <[array]> Paper margins, defaults to none.
    • top <[string]> Top margin, accepts values labeled with units.
    • right <[string]> Right margin, accepts values labeled with units.
    • bottom <[string]> Bottom margin, accepts values labeled with units.
    • left <[string]> Left margin, accepts values labeled with units.
  • mediaType <?[string]> Changes the CSS media type of the page. The only allowed values are 'screen', 'print' and null. Passing null disables media emulation.
  • viewport <[array]>
    • width <[number]> page width in pixels.
    • height <[number]> page height in pixels.
    • deviceScaleFactor <[number]> Specify device scale factor (can be thought of as dpr). Defaults to 1.
    • isMobile <[boolean]> Whether the meta viewport tag is taken into account. Defaults to false.
    • hasTouch<[boolean]> Specifies if viewport supports touch events. Defaults to false
    • isLandscape <[boolean]> Specifies if viewport is in landscape mode. Defaults to false.
  • pageWaitFor <[integer]> Timeout in milliseconds to wait for.
  • cookies<[array]> Cookie objects to set.

NOTE headerTemplate and footerTemplate markup have the following limitations:

  1. Script tags inside templates are not evaluated.
  2. Page styles are not visible inside templates.

NOTE By default, this library generates a pdf with modified colors for printing. Use the -webkit-print-color-adjust property to force rendering of exact colors.

Troubleshooting

  • Make sure you've installed all OS specific dependencies.
  • Manually set the path to your Node.js executable using the $converter->setNodePath() method.

Contributing

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

  • Coding standard - It's mostly PSR.
  • Add tests! - Your PR won't be accepted if it doesn't have tests.

License

PHP Chrome HTML to PDF is free software distributed under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].