Pdf Facade
The Pdf Facade provides a convenient static proxy to the PdfDocumentInterface binding registered by the TcpdfServiceProvider. All configuration values from config/tcpdf-next.php are applied automatically.
use Yeeefang\TcpdfNext\Laravel\Facades\Pdf;Creating a Document
Pdf::create() resolves a fresh Document instance from the container with all config defaults pre-applied:
$pdf = Pdf::create();
$pdf->addPage()
->setFont('Helvetica', '', 12)
->cell(0, 10, 'Hello from Laravel!')
->save(storage_path('app/hello.pdf'));Every call to create() returns a new instance. Documents are never shared across calls.
Fluent API
All Document methods are available through the Facade and return static for chaining:
$pdf = Pdf::create()
->setTitle('Quarterly Report')
->setAuthor('Finance Team')
->setMargins(left: 15, top: 20, right: 15)
->addPage()
->setFont('Helvetica', 'B', 18)
->cell(0, 12, 'Q1 2026 Report')
->ln()
->setFont('Helvetica', '', 11)
->multiCell(0, 6, $reportBody);Configuration Binding
The Facade reads defaults from config/tcpdf-next.php. You can override any setting per-document:
// Uses config defaults (A4 portrait, Helvetica 11pt)
$default = Pdf::create();
// Override page format for this document only
$receipt = Pdf::create()
->setPageFormat('A5')
->setMargins(left: 10, top: 10, right: 10);See Configuration for the full reference.
Facade Class Reference
namespace Yeeefang\TcpdfNext\Laravel\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @method static \Yeeefang\TcpdfNext\Core\Document create()
* @method static void fake()
* @method static void assertCreated()
* @method static void assertCreatedCount(int $count)
*
* @see \Yeeefang\TcpdfNext\Core\Document
*/
class Pdf extends Facade
{
protected static function getFacadeAccessor(): string
{
return \Yeeefang\TcpdfNext\Contracts\PdfDocumentInterface::class;
}
}Testing with Pdf::fake()
Replace the real binding with a fake for assertions without generating actual PDF bytes:
use Yeeefang\TcpdfNext\Laravel\Facades\Pdf;
public function test_invoice_generates_pdf(): void
{
Pdf::fake();
$response = $this->get('/invoices/42/pdf');
$response->assertOk();
Pdf::assertCreated();
Pdf::assertCreatedCount(1);
}The fake records every method call, so you can inspect the fluent chain:
Pdf::fake();
$this->get('/invoices/42/pdf');
Pdf::assertCreated(function ($pdf) {
return $pdf->getTitle() === 'Invoice #42'
&& $pdf->getPageCount() >= 1;
});Next Steps
- HTTP Responses — Deliver PDFs to the browser securely
- Queue Jobs — Offload generation to background workers
- Configuration — All available config keys