Official framework-agnostic PHP SDK

Generate PDFs from PHP.
Use the framework you already have.

Render HTML from Twig, Latte, Symfony, Slim, Mezzio, or a custom PHP application through one framework-agnostic SDK.

PHP 8.2+ Framework agnostic Composer package
Install composer require bladepdf/php
invoice.php php
use BladePDF\BladePdf;

$bladePdf = BladePdf::create(
    $_ENV['BLADEPDF_API_KEY']
);

$result = $bladePdf
    ->fromHtml($html)
    ->format('A4')
    ->showBackground()
    ->render();

$result->save(__DIR__.'/invoice.pdf');
PHP SDK

PDF rendering for any PHP application.

The core package contains the render builder, transport, asset pipeline, results, webhook verification, and public exception model.

Sources

HTML and cloud templates

Render pre-built HTML with fromHtml() or publish a BladePDF template and call fromTemplate() with context.

Options

Fluent PDF configuration

Configure paper, margins, headers, footers, backgrounds, readiness, media, metadata, storage, and webhooks.

Assets

Local asset resolution

Resolve local HTML and CSS dependencies from explicitly allowed filesystem roots.

Results

Typed result objects

Access PDF bytes, base64 output, stored URLs, request ids, and file saving through RenderResult.

Async

Stored background renders

Submit a stored render with a reference and signed webhook for completion handling.

DI

Injectable dependencies

Use BladePdf::create() for normal setup or inject a RenderClient and AssetResolver for advanced applications and tests.

Local assets

Give each document access to the files it uses.

Automatic filesystem reads begin only after you configure allowed roots. The resolver discovers document dependencies while enforcing canonical path boundaries.

assets.php php
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();

HTML and CSS discovery

Resolve common HTML attributes, srcset, inline styles, style blocks, CSS url(), and @import dependencies.

Canonical root security

Traversal, absolute paths outside allowed roots, and symlink escapes are rejected.

Explicit asset access

Use withAsset() when the caller intentionally grants one file outside the configured roots.

Deterministic assets

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.

Delivery

Use the PDF immediately or submit it in the background.

Synchronous and asynchronous requests share the same fluent render configuration.

pdf()

PDF bytes

Access the rendered PDF string from the synchronous RenderResult.

save()

File output

Write the PDF to a selected path and receive an exception if the write cannot complete.

base64()

Encoded output

Create a base64 representation when the application needs an encoded payload.

storePdf()->async()

Background render

Submit a stored render and receive a RenderSubmission with its request id and reference.

PHP workflows

Render HTML from your existing application layer.

Your application owns template rendering and passes the completed HTML document to BladePDF.

Twig

Render a Twig template to a string, then pass that HTML to fromHtml().

Latte

Use Latte for template rendering and send the completed document HTML.

Symfony, Slim, and Mezzio

Construct the SDK in your service container and use it from controllers, handlers, jobs, or services.

Custom PHP applications

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.

SDK capabilities

Configure the complete render request in PHP.

The package exposes common document settings and operational metadata without relying on framework globals.

Headers, footers, and readiness

Add HTML header and footer sources and configure wait conditions, media emulation, backgrounds, and font readiness.

Cloud templates and context

Render a published cloud template with structured context when the document is managed in BladePDF.

Signed webhook verification

Verify raw webhook bodies through the framework-agnostic SignatureVerifier.

Structured transport errors

Handle status codes, request ids, response bodies, missing assets, access denial, and file-write failures through typed exceptions.

FAQ

PHP SDK questions.

Does bladepdf/php require Laravel?
No. It is the framework-agnostic core package and can be used directly from any PHP 8.2 or later application.
Can I use Twig or Latte templates?
Yes. Render the template to an HTML string in your application, then pass that string to fromHtml().
Does BladePDF read my .env file or global configuration?
No. Pass the API key and options explicitly. The SDK does not load environment files or framework configuration.
How are local files protected?
Automatic discovery uses configured canonical roots and rejects traversal and symlink escapes. withAsset() is an explicit grant for a selected file.
Can PHP submit asynchronous renders?
Yes. Enable storage with storePdf(), configure an optional signed webhook, and call async().

Render your first PDF from PHP.

Install the framework-agnostic package, configure the files your document can use, and send its HTML.

composer require bladepdf/php