PHP code example of spiritix / php-chrome-html2pdf

1. Go to this page and download the library: Download spiritix/php-chrome-html2pdf library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spiritix / php-chrome-html2pdf example snippets


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>',
]);

$converter->setLaunchOptions([
      'ignoreHTTPSErrors' => true, 
      'headless' => true, 
      'executablePath' => '/usr/bin/google-chrome-stable', 
      'args' => [
        '--no-sandbox',
        '--disable-web-security',
        '--font-render-hinting=none',
        '--proxy-server="direct://"',
        '--proxy-bypass-list=*',
        '--media-cache-size=0',
        '--disk-cache-size=0',
        '--disable-application-cache',
        '--disk-cache-dir=/dev/null',
        '--media-cache-dir=/dev/null'
      ]
   ]
);


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