PHP code example of beganovich / snappdf

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

    

beganovich / snappdf example snippets


$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setHtml('<h1>Hello world!</h1>')
    ->save('/path/to/your/file.pdf');

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->save('/path/to/your/file.pdf');

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->save('/path/to/your/file.pdf');

$snappdf = new \Beganovich\Snappdf\Snappdf();

$fields = [...];

// Render method returns HTML string (template compile)
$html = view('pdf.warranty', compact('fields'))->render();

$pdf = $snappdf
    ->setHtml($html)
    ->save('/path/to/your/file.pdf');

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->generate();

file_put_contents('my.pdf', $pdf); // for local storage

Storage::disk('s3')->put('my.pdf', $pdf); // for remote storage

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->addChromiumArguments('--single-process --tls1')
    ->generate();

$snappdf = new \Beganovich\Snappdf\Snappdf();

$snappdf->getChromiumArguments(); // ['--headless', '--disable-gpu', '--disable-translations']
$snappdf->clearChromiumArgument('--headless'); // ['--disable-gpu', '--disable-translations']

$snappdf = new \Beganovich\Snappdf\Snappdf();

// $snappdf->getChromiumArguments() = [ '--headless', '--disable-gpu', ... ]

$snappdf->setChromiumPath('/path/to/your/chrome')
    ->clearChromiumArguments();

// $snappdf->getChromiumArguments() = []

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->setKeepTemporaryFiles(true)
    ->generate();

file_put_contents('my.pdf', $pdf);

fastcgi_param SNAPPDF_EXECUTABLE_PATH '/usr/bin/chromium';
fastcgi_param SNAPPDF_SKIP_DOWNLOAD true;