API Facade reference · 10 min read

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

PHP
php
 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.

Data
php
 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.

Assets
php
 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.

Options
php
 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(): RenderResult generates the PDF synchronously.
  • $result->pdf(): string returns raw PDF bytes.
  • $result->storedPdfUrl(): ?string returns the signed stored PDF URL for synchronous storePdf() 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): string writes the PDF to local disk.
  • $result->base64Pdf(): string and $result->base64(): string return base64-encoded PDF bytes.
  • async(): RenderSubmission queues 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.

Per-request webhook
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        'pdf.rendered',
 6    ])
 7    ->async();
Method Purpose
render(): RenderResultGenerate a PDF synchronously; the result contains local bytes and an optional stored PDF URL.
async(): RenderSubmissionQueue 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().
Was this page helpful?
Let us know if something's missing or unclear.