HTML and cloud templates
Render pre-built HTML with fromHtml() or publish a BladePDF template and call fromTemplate() with context.
Render HTML from Twig, Latte, Symfony, Slim, Mezzio, or a custom PHP application through one framework-agnostic SDK.
composer require bladepdf/php
use BladePDF\BladePdf;
$bladePdf = BladePdf::create(
$_ENV['BLADEPDF_API_KEY']
);
$result = $bladePdf
->fromHtml($html)
->format('A4')
->showBackground()
->render();
$result->save(__DIR__.'/invoice.pdf');
The core package contains the render builder, transport, asset pipeline, results, webhook verification, and public exception model.
Render pre-built HTML with fromHtml() or publish a BladePDF template and call fromTemplate() with context.
Configure paper, margins, headers, footers, backgrounds, readiness, media, metadata, storage, and webhooks.
Resolve local HTML and CSS dependencies from explicitly allowed filesystem roots.
Access PDF bytes, base64 output, stored URLs, request ids, and file saving through RenderResult.
Submit a stored render with a reference and signed webhook for completion handling.
Use BladePdf::create() for normal setup or inject a RenderClient and AssetResolver for advanced applications and tests.
Automatic filesystem reads begin only after you configure allowed roots. The resolver discovers document dependencies while enforcing canonical path boundaries.
use BladePDF\Assets\AssetResolverOptions;
use BladePDF\BladePdf;
$bladePdf = BladePdf::create(
apiKey: $_ENV['BLADEPDF_API_KEY'],
assetOptions: new AssetResolverOptions(
documentRoot: __DIR__.'/public',
searchRoots: [
__DIR__.'/public',
__DIR__.'/storage/pdf-assets',
],
),
);
$result = $bladePdf
->fromHtml($html)
->render();
Resolve common HTML attributes, srcset, inline styles, style blocks, CSS url(), and @import dependencies.
Traversal, absolute paths outside allowed roots, and symlink escapes are rejected.
Use withAsset() when the caller intentionally grants one file outside the configured roots.
Dependencies are deduplicated and rewritten to stable request-scoped asset references.
JavaScript referenced by script src and external SVG files are attached as opaque files. JavaScript imports, fetch(), runtime URLs, SVG contents, and dependencies inside SVG are not inspected.
Synchronous and asynchronous requests share the same fluent render configuration.
pdf()
Access the rendered PDF string from the synchronous RenderResult.
save()
Write the PDF to a selected path and receive an exception if the write cannot complete.
base64()
Create a base64 representation when the application needs an encoded payload.
storePdf()->async()
Submit a stored render and receive a RenderSubmission with its request id and reference.
Your application owns template rendering and passes the completed HTML document to BladePDF.
Render a Twig template to a string, then pass that HTML to fromHtml().
Use Latte for template rendering and send the completed document HTML.
Construct the SDK in your service container and use it from controllers, handlers, jobs, or services.
Create BladePdf directly and integrate it wherever the application produces document HTML.
Framework compatibility means the generic SDK works in those applications; it does not imply a dedicated framework bundle.
The package exposes common document settings and operational metadata without relying on framework globals.
Add HTML header and footer sources and configure wait conditions, media emulation, backgrounds, and font readiness.
Render a published cloud template with structured context when the document is managed in BladePDF.
Verify raw webhook bodies through the framework-agnostic SignatureVerifier.
Handle status codes, request ids, response bodies, missing assets, access denial, and file-write failures through typed exceptions.
The guides cover setup, asset roots, transport configuration, fluent methods, results, async renders, and webhooks.
Install the framework-agnostic package, configure the files your document can use, and send its HTML.
composer require bladepdf/php