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
    ->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();

$html = view('pdf.warranty', $fields)->render();

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

use Symfony\Component\Filesystem\Filesystem;

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

$pdf = $snappdf
    ->setHtml('<h1>Hello world!</h1>')
    ->generate();

$filesystem = new Filesystem();
$filesystem->dumpFile('/path/to/your/file.pdf', $pdf);

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

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->generate();

file_put_contents('my.pdf', $pdf);
Storage::disk('s3')->put('my.pdf', $pdf);

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

$pdf = $snappdf
    ->setHtml('<h1>Hello world!</h1>')
    ->generate();

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
echo $pdf;

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

$snappdf
    ->setUrl('https://github.com')
    ->addChromiumArguments('--single-process --tls1')
    ->generate();

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

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

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

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

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

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->waitBeforePrinting(10000)
    ->generate();

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

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

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