Node.js SDKPublic API

Node.js SDK reference

The package uses named exports in ESM and CommonJS. TypeScript declarations are bundled with the package.

BladePdf client

APIResult
new BladePdf(options)Configured native BladePDF client and asset resolver.
BladePdf.fromDependencies({ client, assetResolver })SDK using an injected RenderClient and optional resolver.
fromHtml(html, { baseDirectory? })HTML render builder.
fromTemplate(templateId, context?)Cloud-template render builder.

PendingRender

HTML methods are headerHtml() and footerHtml(). Template context methods are context() and mergeContext().

PDF and readiness methods include pdfOptions(), format(), paperSize(), margins(), landscape(), portrait(), printBackground(), transparentBackground(), scale(), pageRanges(), taggedPdf(), preferCssPageSize(), waitForFonts(), outline(), emulateMedia(), waitUntil(), and waitForFunction().

Request methods include reference(), templateName(), metadata(), storePdf(), webhook(), resolveAssets(), assetFile(), and assetData().

Results and submissions

Method or typeAPI
render() / RenderResultReadonly pdf: Buffer, optional storedPdfUrl/requestId, toBase64(), and asynchronous save().
renderStream() / RenderStreamResultOne-shot Node Readable plus optional stored URL and request ID.
renderToFile() / RenderFileResultSafely committed path plus optional stored URL and request ID.
submit() / RenderSubmissionRequired requestId and optional reference.
RenderRequestReadonly transport snapshot passed to RenderClient implementations and test fakes.

Errors

Catch BladePdfError. Specific classes are MissingApiKeyError, InvalidRenderConfigurationError, AssetNotFoundError, AssetAccessDeniedError, UnableToWritePdfError, and RenderFailedError.

RenderFailedError exposes readonly statusCode, requestId, responseBody, and standard cause. Its message includes only a bounded response excerpt. Caller cancellation remains a standard AbortError.

Webhook signatures

verifyWebhookSignature() accepts exact raw body bytes, timestamp and signature header values, secret, optional tolerance, and optional current Unix timestamp for deterministic tests.

Verifier
typescript
 1const valid = verifyWebhookSignature({
 2  rawBody,
 3  timestamp: request.headers['bladepdf-timestamp'],
 4  signature: request.headers['bladepdf-signature'],
 5  secret,
 6});