1. Go to this page and download the library: Download zentiq-labs/fast-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/ */
zentiq-labs / fast-pdf example snippets
use ZentiqLabs\FastPdf\FastPdf;
$pdf = new FastPdf();
// From a raw HTML string
$pdf->fromHtml('<html><body><h1>Hello World</h1></body></html>')
->save('/var/www/output.pdf');
// From a PHP template file
$pdf->fromFile(__DIR__ . '/templates/invoice.php', ['invoice' => $invoice])
->landscape()
->download('invoice.pdf'); // streams + exits
// Sends Content-Disposition: attachment and calls exit()
$pdf->fromFile('/templates/receipt.php', $data)->download('receipt-001.pdf');
// Sends Content-Disposition: inline and calls exit()
$pdf->fromFile('/templates/receipt.php', $data)->stream('receipt-001.pdf');
use ZentiqLabs\FastPdf\Enums\PaperSize;
$pdf->fromHtml($html)->paperSize(PaperSize::Letter)->output();
$pdf->fromHtml($html)->paperSize('legal')->landscape()->output();
use ZentiqLabs\FastPdf\FastPdf;
$pdf = new FastPdf(['binary' => '/usr/bin/chromium']);
$pdf->fromHtml('<h1>Core PHP</h1>')->save('/tmp/output.pdf');
use ZentiqLabs\FastPdf\FastPdf;
public static function fastPdf(bool $getShared = true): FastPdf
{
if ($getShared) {
return static::getSharedInstance('fastPdf');
}
return new FastPdf(['binary' => env('FAST_PDF_BINARY')]);
}
public function __construct(private readonly FastPdf $pdf) {}
public function export(): Response
{
$bytes = $this->pdf->fromHtml($html)->output();
return new Response($bytes, 200, ['Content-Type' => 'application/pdf']);
}
// app/Providers/AppServiceProvider.php
use ZentiqLabs\FastPdf\FastPdf;
$this->app->singleton(FastPdf::class, fn () => new FastPdf([
'binary' => config('services.chromium.binary'),
]));
// In a plugin bootstrap file
df;
function zentiq_pdf(): FastPdf
{
static $instance;
return $instance ??= new FastPdf(['binary' => defined('CHROMIUM_BIN') ? CHROMIUM_BIN : null]);
}
// Framework-agnostic — inspect headers and body yourself
$response = $pdf->fromHtml($html)->toInlineResponse('report.pdf');
foreach ($response->headers as $name => $value) {
header("{$name}: {$value}");
}
echo $response->body;
// Or let PdfResponse emit directly
$pdf->fromHtml($html)->toDownloadResponse('invoice.pdf')->send();
$r = $pdf->fromHtml($html)->toDownloadResponse('invoice.pdf');
return new Response($r->body, 200, $r->headers); // Symfony
return new \Laminas\Diactoros\Response($r->body, 200, $r->headers); // PSR-7
$pdf = FastPdf::fake();
$pdf->fromHtml('<h1>Invoice #42</h1>')->output();
$pdf->fromView('invoices.pdf', ['id' => 42])->save('/tmp/out.pdf'); // hypothetical
// Assert at least one render occurred
$pdf->assertRendered();
// Assert an exact number of renders
$pdf->assertRenderedCount(1);
// Assert a specific HTML fragment was rendered
$pdf->assertRenderedHtmlContains('Invoice #42');
// Inspect all recorded calls
$calls = $pdf->renderedCalls(); // array of ['html' => ..., 'options' => ...]
// Not needed in most tests, but available if you must assert on the bytes
use ZentiqLabs\FastPdf\Testing\FakePdfEngine;
$engine = new FakePdfEngine();
$engine->returns('%PDF-1.5 custom');
$pdf = new FastPdf([], $engine);