PHP code example of danielboendergaard / phantom-pdf

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

    

danielboendergaard / phantom-pdf example snippets


$pdf = new PdfGenerator;

// Set a writable path for temporary files
$pdf->setStoragePath('storage/path');

// Saves the PDF as a file (optional)
$pdf->saveFromView($html, 'filename.pdf');

// Returns a Symfony\Component\HttpFoundation\BinaryFileResponse
return $pdf->createFromView($html, 'filename.pdf');


$pdf->setBinaryPath('/some/path/phantomjs');

$pdf->useScript('`/path/to/script');

'providers' => [
  PhantomPdf\Laravel\LaravelServiceProvider::class,
]

'aliases' => [
  'PDF' => PhantomPdf\Laravel\PDFFacade::class,
]

class SampleController extends Controller
{
  public function index()
  {
    return PDF::createFromView(view('index'), 'filename.pdf');
  }

  // Save the pdf to disk
  public function save()
  {
      PDF::saveFromView(view('index'), 'path/filename.pdf');
  }

  // Usa via injection
  public function foo(PdfGenerator $pdf)
  {
    return $pdf->createFromView(view('path'), 'filename.pdf');
  }
}