Pressjet
← All articles
Integration

Put Export PDF inside a Node app

Build a packing slip from application data and hand the resulting bytes to the user.

A warehouse operator has already picked the order and confirmed its contents. When they click Export PDF, the application has the order number, the customer’s display name and every line item. A local render lets the Node process use those values directly and return a packing slip in the same request.

Build the slip where the order lives

The TypeScript SDK’s builders describe the document. In a Linux Node application with the SDK and matching renderer installed, renderLocal starts the native binary for one export and resolves with PDF bytes. The Node examples run locally. Python, Go and PHP generate the same slip through the HTTP service. Choose JSON to see the exact request body for POST /v1/generate.

import { writeFile } from "node:fs/promises";
import { document, page, text } from "pressjet";
import { renderLocal } from "pressjet/local";

const order = { id: "0041", items: ["4 proof sets", "1 cover sheet"] };
const slip = document({ title: "Packing slip " + order.id },
  page({ size: "A4", style: { padding: 40 } },
    text({ style: { fontSize: 22 } }, "Packing slip " + order.id),
    ...order.items.map(item => text({}, item))
  )
);
const bytes = await renderLocal(slip);
await writeFile("packing-slip.pdf", bytes);

Wire the result to the download action

In the existing authenticated order route, load the authorized order, build the same tree and set the response content type to application/pdf. A Content-Disposition attachment filename based on the internal order ID lets the operator recognize it in Downloads. Return the bytes only after rendering succeeds, so an invalid layout produces an application error instead of a partial PDF.

Test the packaged app on its target architecture. A tagged SDK release can select an optional native package for Linux x64 or ARM64. A source build can point PRESSJET_BINARY at the matching executable. Keep the optional package when bundling, and embed any PNG or JPEG bytes in the document. To cancel abandoned work, pass the request’s abort signal to renderLocal.

For an acceptance test, open the resulting slip and check that “0041” keeps its leading zeros and both items appear in source order. Repeat with an order long enough to span several pages. That second fixture tests the behavior the short example can’t show.

Local SDK setup and options · Document nodes and pagination

Read nextGive every invoice amount a column headerAll articles ↗