PHP code example of crawly / html-to-pdf

1. Go to this page and download the library: Download crawly/html-to-pdf 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/ */

    

crawly / html-to-pdf example snippets




use Crawly\HtmlToPdf;

$html = file_get_contents('my.html');

$htp = new HtmlToPdf($html);

$htp->setBaseUrl('http://www.detran.mg.gov.br')
    ->safeStripTags()
    ->sanitizeHtmlHeader()
    ->sanitizeHtmlText()
    ->setOptions([
         'commandOptions' => [
             'useExec' => false,
         ],
         'javascript-delay' => '10000',
         'ignoreWarnings' => false
    ])
    ->customTransform(function ($html) {
        return str_replace('abrir-fechar-table', 'abrir-fechar-table aberto', $html);
    });

$pdfBase64 = $htp->convert();