PHP code example of ivanpepelko / php-wkhtmltopdf

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

    

ivanpepelko / php-wkhtmltopdf example snippets




use WkHtmlToPdf\WkHtmlToPdf;

bin/wkhtmltopdf');
$pdf->setInputPath('html/invoice.html')
    ->setOutputPath('pdf/invoice.pdf')
    ->useRecommendedOptions()
    ->convert()
;



use WkHtmlToPdf\WkHtmlToPdf;

bin/wkhtmltopdf');

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='hello.pdf'");

echo $pdf->setInputHtml('
        <!DOCTYPE html>
            <html>
                <head><title>Hello world!</title></head>
                <body><h1>Hello</h1><p>world!</p></body>
            </html>
        </html>
        ')
        ->useRecommendedOptions()
        ->convert()
        ->output()
;


$pdf->setFooterCenterText($text)
    ->setHeaderLeftText($text)
    ->setFooterSpacing($spacing)
    ->setHeaderFontName($name)
    ->setFooterHtml($html); // etc, you get the point


$pdf->addHeaderFooterVar('var1', 'value2')
	->addHeaderFooterVars(['var3' => 'value4']);


$pdf->setCacheDir($dir);

composer