Skip to content

Engine extension

NextPDF Cloudflare

Serverless edge rendering via the Cloudflare Browser Rendering API.

Free · Apache-2.0NextPDF ^3.0 · PSR-18 client ^1.0 · PSR-17 factories ^1.1 · PSR-3 logger ^3.0 · PHP 8.4+

NextPDF Cloudflare turns any Cloudflare Worker into a PDF rendering endpoint. Send HTML from your PHP application, receive rendered PDF bytes back — no local headless browser required. Supports custom fonts via R2 storage, automatic fallback to local Chrome (Artisan extension), and SSRF/injection hardening out of the box.

How it fits

Built into your workflow

Edge rendering, no local browser

Your PHP app sends HTML to a Cloudflare Worker that renders it to PDF at the network edge through the Browser Rendering API. No headless browser runs on your own server, and 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

When the edge Worker is unreachable, rendering falls back automatically to a local Chrome instance driven through Artisan, so a request never simply fails. Edge telemetry surfaces render time, the CF-Ray edge location, and content height when the Worker does respond. You keep one integration that prefers the edge and degrades to local rendering on its own.

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
  • Auto fallback — falls back to local Chrome (Artisan extension) when the Worker is unreachable
  • 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

Reach for this when you want serverless HTML-to-PDF with no local headless browser — rendering happens on Cloudflare Workers, with R2 fonts and an automatic local-Chrome (Artisan) fallback.