API Returning PDFs · 6 min read

Delivery Methods

After configuring a render, call render() to generate the PDF. The returned RenderResult keeps the PDF bytes locally and gives you helper methods for browser responses, downloads, local files, and base64 output.

Raw PDF bytes

render() returns a RenderResult. Call pdf() on the result when you need the generated PDF as a binary string.

Raw bytes
php
 1$result = BladePDF::fromView('pdf.invoice', $data)->render();
 2
 3$pdf = $result->pdf();

Inline browser response

response() on the rendered result returns a Laravel response with Content-Disposition: inline.

Inline
php
 1return BladePDF::fromView('pdf.invoice', $data)
 2    ->render()
 3    ->response('invoice.pdf');

Download response

download() on the rendered result returns a Laravel response with Content-Disposition: attachment.

Download
php
 1return BladePDF::fromTemplate('invoice.standard', $context)
 2    ->render()
 3    ->download('invoice.pdf');

Save locally

save() writes the returned PDF bytes to a local path and returns that path.

Local disk
php
 1$path = BladePDF::fromView('pdf.report', $data)
 2    ->render()
 3    ->save(storage_path('app/reports/report.pdf'));

Base64 output

Use base64Pdf() or base64() when another API expects the PDF as base64 text.

Base64
php
 1$encoded = BladePDF::fromHtml($html)
 2    ->render()
 3    ->base64Pdf();

Store the generated PDF

storePdf() stores the generated PDF in BladePDF after rendering. With synchronous delivery, render() still returns the PDF bytes and the result includes the stored PDF URL when storage succeeded.

Stored PDF
php
 1$result = BladePDF::fromTemplate('invoice.standard', $context)
 2    ->reference('INV-2026-0042')
 3    ->storePdf()
 4    ->render();
 5
 6$result->storedPdfUrl(); // Signed URL for the stored PDF, or null
 7
 8return $result->response('invoice.pdf');

The stored PDF URL is also available later from the dashboard and render events. Result helper responses such as response() and download() return only the PDF to your user; they do not forward the stored URL as an HTTP header.

Queue an async render

async() returns a RenderSubmission after BladePDF has parsed, validated, and accepted the render within your workspace capacity. It does not wait for PDF generation, but it can still wait for an available concurrency slot before acceptance. Because no PDF bytes are returned, storePdf() is required.

Async delivery
php
 1$submission = BladePDF::fromTemplate('invoice.standard', $context)
 2    ->reference('INV-2026-0042')
 3    ->storePdf()
 4    ->webhook('https://example.com/bladepdf/webhook', 'whsec_request_secret')
 5    ->async();
 6
 7$submission->requestId;
 8$submission->reference;

See Async Renders for acceptance guarantees, failure handling, storage requirements, and the raw REST contract.

Method summary

Method Returns Use for
render()RenderResultGenerate the PDF synchronously and keep the result locally.
$result->pdf()stringManual storage, emails, custom responses.
$result->storedPdfUrl()?stringRead the signed URL returned for a synchronous storePdf() render.
$result->response()Illuminate\Http\ResponseOpen in browser.
$result->download()Illuminate\Http\ResponseForce save dialog.
$result->save()stringWrite to local disk path.
$result->base64Pdf()stringEmbed in JSON or third-party APIs.
async()RenderSubmissionQueue a stored render and handle completion through events.
Was this page helpful?
Let us know if something's missing or unclear.