PHP code example of guenbakku / cakepdf

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

    

guenbakku / cakepdf example snippets




use Guenbakku\Cakepdf\Pdf;

// Instance object.
// Different with original Snappy, this libary comes with 
// wkhtmltopdf binary which is installed as composer dependencies. 
// So following setup also automatically set wkhtmltopdf binary's path 
// corresponding to current processor's structure (32 or 64 bit).
$pdf = new Pdf();

// Add html to render to pdf.
// Break page will be inserted automatically by wkhtmltopdf.
$html = '<p>Long html for long pdf</p>';
$pdf->add($html);

// Add each html as a seperated pdf page.
$page = '<p>Page</p>';
$pdf->addPage($page)
    ->addPage($page);

// Render output to display in browser.
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="file.pdf"');
$result = $pdf->render();
echo $result;

// Or render output to pdf file.
$output = '/tmp/cakepdf.pdf';
$pdf->render($output);

// Set options for wkhtmltopdf.
// Basically same with Snappy's interface.
$pdf = new Pdf();
$pdf->setOption('page-size', 'A4')
    ->setOption('orientation', 'Landscape');