BladePDF:: Facade
The BladePDF facade creates a pending render. Choose a source with fromView(), fromHtml(), or fromTemplate(), then chain options, metadata, and assets. Call render() for a synchronous RenderResult, or async() for an accepted background render.
Import
1use BladePDF\Laravel\Facades\BladePDF;
Source methods
| Method | Meaning |
|---|---|
BladePDF::fromView(string $view, array $data = []) |
Render a local Laravel view into HTML, then send that HTML. |
BladePDF::fromHtml(string $html) |
Send an already-rendered HTML string. |
BladePDF::fromTemplate(string $templateId, array $context = []) |
Render a dashboard-managed cloud Blade template with JSON context. |
Data and context
withData() merges additional local view data. On a cloud template render, it behaves like withContext() and merges JSON context.
1BladePDF::fromView('pdf.invoice')
2 ->withData(['invoice' => $invoice])
3 ->render()
4 ->pdf();
5
6BladePDF::fromTemplate('invoice.standard')
7 ->context(['invoice' => $invoice->toArray()])
8 ->withContext(['locale' => 'en'])
9 ->render()
10 ->pdf();
Metadata
| Method | Allowed on | Purpose |
|---|---|---|
reference(?string $reference) |
HTML and cloud templates | Correlate renders with your own model id, order number, or invoice uuid. |
templateName(?string $templateName) |
HTML only | Dashboard display name for ad-hoc/local HTML renders. |
metadata(array $metadata) |
Depends on keys | Accepts reference and template_name. |
Headers and footers
These methods are only valid for fromView() and fromHtml().
withHeader(string $view, array $data = [])withHeaderHtml(string $html)withFooter(string $view, array $data = [])withFooterHtml(string $html)
Assets
Attach request-scoped assets manually, override a cloud asset for a single render, or disable automatic local asset resolution when you want to keep HTML/CSS references untouched.
1BladePDF::fromHtml('<img src="asset:///logo.png">')
2 ->withAsset(public_path('images/logo.png'), 'logo.png')
3 ->render()
4 ->pdf();
5
6BladePDF::fromTemplate('invoice.standard', $context)
7 ->overrideAsset('logo.png', public_path('tenant-logo.png'))
8 ->render()
9 ->pdf();
10
11BladePDF::fromView('pdf.invoice', ['invoice' => $invoice])
12 ->withoutAssetResolution()
13 ->render()
14 ->pdf();
Render options
Use fluent methods for common options and withOptions() for lower-level fields.
1BladePDF::fromView('pdf.report', $data)
2 ->format('A4')
3 ->landscape()
4 ->margins(12, 12, 16, 12, 'mm')
5 ->showBackground()
6 ->waitUntil('networkidle0')
7 ->emulateMedia('print')
8 ->render()
9 ->pdf();
Delivery methods
render(): RenderResultgenerates the PDF synchronously.$result->pdf(): stringreturns raw PDF bytes.$result->storedPdfUrl(): ?stringreturns the signed stored PDF URL for synchronousstorePdf()renders.$result->response(?string $filename = 'document.pdf')returns an inline Laravel response.$result->download(?string $filename = 'document.pdf')returns an attachment response.$result->save(string $path): stringwrites the PDF to local disk.$result->base64Pdf(): stringand$result->base64(): stringreturn base64-encoded PDF bytes.async(): RenderSubmissionqueues a stored render and returns its request id and reference after acceptance.
Cloud persistence
storePdf() stores the generated PDF in BladePDF. It is optional before render() and required before async(). Synchronous stored renders expose a signed URL through $result->storedPdfUrl(); dashboard render data and webhook payloads include the stored PDF URL after the render event is recorded.
Webhooks
Use webhook() when a single asynchronous render should notify a specific endpoint. The endpoint is used only for that render and does not create or update a dashboard webhook endpoint.
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 'pdf.rendered',
6 ])
7 ->async();
| Method | Purpose |
|---|---|
render(): RenderResult | Generate a PDF synchronously; the result contains local bytes and an optional stored PDF URL. |
async(): RenderSubmission | Queue a render after requiring storePdf(); returns requestId and optional reference. |
webhook(string $url, string $secret, array $events = ['pdf.rendered', 'pdf.failed']) | Attach a signed callback endpoint to an asynchronous render. |
withWebhook(...) | Alias for webhook(). |