PHP code example of dimns / html-to-pdf

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

    

dimns / html-to-pdf example snippets


public HtmlToPdf::__construct ( string $path_to_folder [, array $mpdf_config ] )

  [
      'format'              => 'A4',
      'orientation'         => 'portrait',
      'default_font'        => 'arial',
      'setAutoTopMargin'    => 'stretch',
      'setAutoBottomMargin' => 'stretch',
  ]
  

public HtmlToPdf::create ( string $html_body [, string $html_header = null [, string $html_footer = null ]] ) : string


use DimNS\HtmlToPdf\HtmlToPdf;
use Mpdf\MpdfException;

  Test html to pdf
</h1>
<p>
    <strong>Test</strong> <i>string</i> with <a href="https://domain.tld">link</a>
</p>
HTML;

try {
    echo $htp->create($html_body);
} catch (MpdfException $e) {
    echo $e->getMessage();
}


use DimNS\HtmlToPdf\HtmlToPdf;
use Mpdf\MpdfException;

,
    'orientation'    => 'landscape',
    'defaultCssFile' => '/path/to/style.css',
]);

$html_body = <<<HTML
<h1>
    Test html to pdf with header and footer
</h1>
<p>
    <strong>Test</strong> <i>string</i> with <a href="https://domain.tld">link</a>
</p>
HTML;

$html_header = <<<HTML
<p>
    <strong>This is header</strong>
</p>
<hr>
HTML;

$html_footer = <<<HTML
<hr>
<p>
    <strong>This is footer</strong>
</p>
HTML;

try {
    echo $htp->create($html_body, $html_header, $html_footer);
} catch (MpdfException $e) {
    echo $e->getMessage();
}