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');
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');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.