Skip to content

Engine extension

NextPDF Cloudflare

Serverless edge rendering via the Cloudflare Browser Rendering API.

Free · Apache-2.0NextPDF ^3.0 || ^5.2 · PSR-18 client ^1.0 · PSR-17 factories ^1.1 · PSR-3 logger ^3.0 · PHP >=8.4 <9.0

NextPDF Cloudflare turns a Cloudflare Worker into a PDF rendering endpoint. Send HTML from your PHP application and receive rendered PDF bytes from the Browser Rendering API. It supports custom fonts through R2 storage, automatic fallback to local Chrome through the Artisan extension, and SSRF and injection hardening.

How it fits

Built into your workflow

Edge rendering through Browser Rendering

Your PHP app sends HTML to a Cloudflare Worker that renders it to PDF at the network edge through the Browser Rendering API. The Worker returns finished PDF bytes over a standard PSR-18 HTTP client. SSRF protection, HTML size limits, meta-refresh blocking, and base64-bomb detection guard every request.

Custom CJK fonts from R2

Load your own fonts, including full CJK typefaces, from a Cloudflare R2 storage bucket straight into the edge renderer. The Worker pulls the font assets it needs so documents in Chinese, Japanese, and Korean render with the typography you ship. Responses come back as application/pdf or application/json with base64-encoded bytes.

Automatic local fallback

Automatic fallback routes rendering to a local Chrome instance driven through Artisan when the edge Worker is unavailable. Edge telemetry surfaces render time, the CF-Ray edge location, and content height for Worker responses. One integration prefers the edge and routes fallback work locally.

Get started

Install

terminal
composer require nextpdf/cloudflare

In code

How it works

Basic edge rendering

php
use NextPDF\Cloudflare\CloudflareHtmlRenderer;
use NextPDF\Cloudflare\CloudflareRendererConfig;

$config = new CloudflareRendererConfig(
    workerUrl: 'https://pdf-renderer.your-subdomain.workers.dev/render',
    apiToken: 'your-api-token',
);

$renderer = new CloudflareHtmlRenderer(
    config: $config,
    httpClient: $httpClient,        // PSR-18 ClientInterface
    requestFactory: $requestFactory, // PSR-17 RequestFactoryInterface
    streamFactory: $streamFactory,   // PSR-17 StreamFactoryInterface
);

$result = $renderer->render('<h1>Hello from the Edge!</h1>');
file_put_contents('output.pdf', $result->pdfData);

Custom fonts from R2

php
$config = new CloudflareRendererConfig(
    workerUrl: 'https://pdf-renderer.your-subdomain.workers.dev/render',
    apiToken: 'your-api-token',
    r2FontBucket: 'pdf-fonts',
);

$result = $renderer->render(
    html: '<div style="font-family: NotoSansCJK;">繁體中文文件</div>',
    fontFiles: ['NotoSansCJKtc-Regular.ttf'],
);

Capabilities

What you get

  • Edge rendering—render HTML to PDF via the Cloudflare Browser Rendering API
  • PSR-18 HTTP—vendor-agnostic; works with Guzzle, Symfony HttpClient, Buzz, etc.
  • Security hardening—SSRF protection, HTML size limits, meta-refresh blocking, base64 bomb detection
  • R2 font support—load custom fonts (CJK, etc.) from Cloudflare R2 buckets
  • Automatic fallback—routes work to local Chrome through the Artisan extension when the Worker is unavailable
  • Binary & JSON—accepts both application/pdf and application/json (base64) responses
  • Edge telemetry—extracts render time, edge location (CF-Ray), and content height metadata

When to use it

Use this for serverless HTML-to-PDF on Cloudflare Workers, with R2 fonts and an automatic local-Chrome fallback through the Artisan extension.