dev-master
9999999-devA PHP wrapper for electron-pdf
MIT
The Requires
by Silvio Iannone
A PHP wrapper for electron-pdf
electron-pdf-php is a PHP wrapper of electron-pdf.
It simply provides a PHP interface for the electron-pdf
cli tool., (*1)
First install electron-pdf globally:, (*2)
npm install -g electron-pdf
Require electron-pdf-php using composer:, (*3)
composer require silvioiannone/electron-pdf-php
Usage is super easy:, (*4)
$generator = new SI\ElectronPdfPhp\Generator(); $pdf = $generator->fromHtml($html) ->content();
When instantiating a new generator instance the following settings may be passed to the constructor:, (*5)
executable
=> string
- Path to the electron-pdf executable. Default: 'electron-pdf'proxyWithNode
=> bool
- Execute the command using node. This may be necessary in some cases
where the error env: node: command not found
is thrown. Default: falsegraphicalEnvironment
=> bool
- Whether the server has a graphical environment. This is only
valid on Linux machines that have
Xvfb installed. Default: falsemarginsType
=> int
- Specify the type of margins to use:
0
: default margins1
: no margins (electron-pdf default setting)2
: minimum marginsExample:, (*6)
$generator = new SI\ElectronPdfPhp\Generator([ 'executable' => '/usr/local/bin/electron-pdf' ... ]);
Generate a PDF from a URL:, (*7)
// Generate the PDF from a URL $pdf = $generator->from('http://google.com') ->content();
Generate a PDF from HTML:, (*8)
// Generate the PDF from HTML $pdf = $generator->fromHtml('<h1>Test<h1>') ->content();
Save the PDF to a file:, (*9)
$generator->from('http://google.com') ->to('/home/downloads/test.pdf');
Get the PDF contents:, (*10)
$pdf = $generator->from('http://google.com') ->content();
A PHP wrapper for electron-pdf
MIT