Download Html2pdf Php Library

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

If you are experiencing issues with this library, you might give its precursor a try.It is based on outdated libraries but has been around for a few years.Schneider electric unity pro crack.

How it works

This library is based on puppeteer, a headless Chrome Node API which ismaintained 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 correspondingPHP wrapper or similar libraries, it is based on a current Chrome versioninstead 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.

Download Html2pdf Php Library

Download spipu/html2pdf. More information about spipu/html2pdf. Files in spipu/html2pdf. Please rate this library. Is it a good library?

Requirements

  • PHP 7.0+ with enabled program execution functions (proc_open) and 'fopen wrappers'
  • Node.js 6.4+
  • A few OS specific dependencies

Installation

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

The required JS packages are installed automatically in the background.

Usage

Html2pdf Php Image

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.

Input handlers

The following input handlers are available:

Html2pdf Php Examples

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

Output handlers

The following output handlers are available: Origin key generator free download. Minecraft download kostenlos deutsch vollversion.

  • 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.

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.

A very important topic for many web applications is to create PDF files from PHP and to download it to a client. Very often, this is used to generate invoices, to export certain information or to let the user generate special reports. Many PHP frameworks use their own PDF tools and there are also different PHP modules out there. A very easy and good option is to generate PDF files directly from HTML Code. This can be done with HTML2PDF and this is a free software which is developed under LGPL license.

HTML2PDF

HTML2PDF computes PDF files directly from HTML Code. The generated PDF file is stored on your server and can be downloaded by a client. This is very simple, you only need the free to use HTML2PDF library which can be downloaded here.

This library can be used in your PHP file after including:

require_once('./library/Html2pdf/html2pdf.class.php');
Image

In a PHP script you can easily convert static HTML Code to PDF. All you have to do is to call these lines of code:

2
4
$content='<html><body><h1>Einfaches Beispiel</h1></body></html>';
$html2pdf=newHTML2PDF($mode,'A4','de',true,'UTF-8',array(10,10,10,10));
$html2pdf->Output($filename.'.pdf');

Download Html2pdf.class.php

First we define some HTML Code. Basically you only need to use the same HTML Code that you use for displaying your site. This HTML Code can also use CSS Code which also works for your PDF file. Then we create a new HTML2PDF class with some params. We can define different things:

Php
  • mode (L for landscape and P for portrait format)
  • page size (for example A4)
  • encoding (very important for HTML code!)
  • border (you can define blank space at the border of the page – for printers)

Then we set the HTML code for the class and the last line creates a PDF file with the given filename. The directory should have the right write permissions!

That’s it! A good solution is to create special CSS stylesheets for printing HTML code, I personally create a area with the website logo and some header and footer information.

Advantages

The main advantage is, that you do not need to learn different PDF tools of different frameworks. Also you do not need to write complicated source code for PDF elements. With HTML it is far easier, because you can test your sites directly in your browser. For a web developer, this is much simpler. The only difficult thing may be to write a CSS stylesheet for all PDF outputs, but a web designer can also do it for you if CSS is a problem. This CSS can be used for multiple projects.

ähnliche Artikel:

Share
Posted on