Download the PHP package fyrts/chrome-devtools-pdf without Composer
On this page you can find all versions of the php package fyrts/chrome-devtools-pdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package chrome-devtools-pdf
ChromeDevToolsPdf
ChromeDevToolsPdf provides a wrapper around fyrts/chrome-devtools-protocol for fast and predictable generation of PDF files using the Chrome DevTools Protocol.
Setup
Start off by installing a recent version of Chrome/Chromium, then install the package through composer:
You can choose to manage the Chrome process yourself (preferably using a process manager like Supervisord), or have the library fire up a process on request.
To share a single process, start Chrome with the remote-debugging-port
flag and use the connect()
method:
To launch Chrome on demand, use the launch()
method, providing the executable path if needed:
Usage
PDF files can be generated from either publicly accessible URLs, or raw HTML source code.
To receive raw data instead of directly saving a file, use the generate()
method instead:
Change page layout settings by calling setters on the PDF object:
Available options are as follows:
setLandscape(true|false)
– Paper orientation. Defaults to false.setDisplayHeaderFooter(true|false)
– Display header and footer. Defaults to false.setPrintBackground(true|false)
– Print background graphics. Defaults to false.setScale(int|float)
– Scale of the webpage rendering. Defaults to 1.setPaperWidth(int|float)
andsetPaperHeight(int|float)
– Paper width or height in inches. Defaults to 8.5 and 11 inches respectively.setMarginTop(int|float)
,setMarginBottom(int|float)
,setMarginLeft(int|float)
andsetMarginRight(int|float)
– Top, bottom, left or right margin in inches. Defaults to 1cm (~0.4 inches).setPageRanges(string)
– Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.setIgnoreInvalidPageRanges(true|false)
– Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'. Defaults to false.setHeaderTemplate(string)
– HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them (for example, would generate span containing the title):- date: formatted print date
- title: document title
- url: document location
- pageNumber: current page number
- totalPages: total pages in the document
setFooterTemplate(string)
– HTML template for the print footer. Should use the same format as the headerTemplate.setPreferCSSPageSize(true|false)
– Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.setPaperSize(array)
– Array containing paper width and height in inches. Defaults to 8.5 and 11 inches respectively. The following constants are available as presets:- PaperSize::A0, PaperSize::A1, PaperSize::A2, PaperSize::A3, PaperSize::A4, PaperSize::A5, PaperSize::A6, PaperSize::A7 and PaperSize::A8
- PaperSize::JUNIOR_LEGAL
- PaperSize::GOVERNMENT_LETTER
- PaperSize::LETTER
- PaperSize::LEGAL
- PaperSize::TABLOID
- PaperSize::LEDGER
The library can be implemented asynchronously. This can be useful when printing multiple pages. When doing so, use the await()
method to prevent the script from terminating prematurely.