Typed fluent builder
Sources, PDF options, metadata, webhooks, results, and errors are represented by exported TypeScript types.
Render HTML, server-side templates, or BladePDF cloud templates with a TypeScript-first SDK built for Node.js applications.
npm install @bladepdf/node
import { BladePdf } from '@bladepdf/node';
const bladePdf = new BladePdf({
apiKey: process.env.BLADEPDF_API_KEY!,
});
const result = await bladePdf
.fromHtml(html)
.format('A4')
.printBackground()
.render();
await result.save('invoice.pdf');
Build the render request, resolve local assets, and choose the delivery method through one typed interface.
Sources, PDF options, metadata, webhooks, results, and errors are represented by exported TypeScript types.
Use the same named exports from modern ESM applications or existing CommonJS services.
Attach referenced stylesheets, images, fonts, JavaScript files, SVGs, and nested CSS dependencies from approved roots.
Buffer a result, pipe a Node.js Readable, write atomically to disk, or submit a stored background render.
Send pre-rendered HTML from any server-side template engine or render a published BladePDF cloud template with context.
The package targets Node.js 22 and later, uses native platform APIs, and has no runtime dependencies.
Configure the filesystem roots that belong to the document. The SDK discovers required files, attaches them to the request, and rewrites their document references.
const html = [
'<link rel="stylesheet" href="/build/invoice.css">',
'<img src="/images/logo.svg#mark">',
].join('\n');
const bladePdf = new BladePdf({
apiKey,
assets: {
documentRoot: '/srv/app/public',
searchRoots: [
'/srv/app/public',
'/srv/app/storage',
],
},
});
await bladePdf
.fromHtml(html)
.renderToFile('invoice.pdf');
CSS url() values and @import rules are resolved recursively, including fonts and images referenced by imported stylesheets.
Automatic discovery is limited to configured canonical roots, with traversal and symlink escapes rejected.
Only assets referenced by the document or added explicitly with assetFile() and assetData() are attached.
Query strings and fragments stay in rewritten HTML or CSS references, while multipart asset names remain clean.
JavaScript is attached only when referenced by script src; imports, fetch(), and runtime URLs are not inspected. External SVG files are attached as opaque files and their contents are not traversed.
All delivery methods use the same source, PDF options, asset pipeline, metadata, and cancellation signal.
render()
Receive a RenderResult containing the complete PDF Buffer, request id, and optional stored URL.
renderStream()
Pipe a one-shot Readable through normal Node.js backpressure-aware stream utilities.
renderToFile()
Stream to a temporary sibling and replace the destination only after the PDF completes successfully.
storePdf().submit()
Submit a stored asynchronous render and receive its request id and reference.
The SDK accepts HTML strings, so template rendering remains part of your Node.js application.
Build or load the complete document markup and pass it directly to fromHtml().
Render the template in your application, then pass the resulting HTML string to BladePDF.
Send server-rendered markup with an optional base directory for relative local assets.
Call fromTemplate() with typed context when the published template lives in BladePDF.
Template engines and web frameworks remain application choices; the SDK does not add direct dependencies on them.
The Node.js package exposes the controls needed to integrate rendering into services, jobs, and HTTP handlers.
Cancel delivery with AbortSignal and configure request timeouts and retry behavior for supported transient failures.
Supply a custom fetch implementation or construct BladePdf from your own RenderClient and AssetResolver.
Each delivery call captures its own immutable request state, so a builder can be reused safely.
Handle configuration, asset, write, and transport failures through exported error classes and request metadata.
The guides cover installation, configuration, API reference, assets, delivery, background renders, and webhook verification.
Install the official package, send HTML, and choose a Buffer, stream, file, or background result.
npm install @bladepdf/node