Install the npm package
Create an ESM project and install the shared browser and Node.js package:
npm init -y
npm pkg set type=module
npm install ironpress
Import server-side code from ironpress/node. The root ironpress entry remains browser-oriented.
Create an HTML PDF
The Node.js initializer locates the WASM asset shipped inside the package. Your application does not resolve or read that asset.
import { writeFile } from "node:fs/promises";
import init, { htmlToPdf } from "ironpress/node";
await init();
const pdf = htmlToPdf("<h1>Hello from Node.js</h1>");
await writeFile("output.pdf", pdf);
Conversion returns Uint8Array. Node.js can write it directly or convert it with Buffer.from(pdf).
Render Markdown
import { writeFile } from "node:fs/promises";
import init, { markdownToPdf } from "ironpress/node";
await init();
const pdf = markdownToPdf("# Release notes\n\nEverything shipped.");
await writeFile("release-notes.pdf", pdf);
Use a configured converter
Initialize once, then create reusable converter policies. Always free WASM-owned converter objects.
import init, { HtmlConverter } from "ironpress/node";
await init();
const converter = new HtmlConverter();
try {
converter.pageSize("Letter");
converter.marginSides(36, 48, 36, 48);
converter.header("Quarterly report");
converter.footer("Page {page} of {pages}");
const pdf = converter.htmlToPdf("<h1>Results</h1>");
} finally {
converter.free();
}
The initializer is idempotent. Concurrent or repeated calls resolve to the same initialized runtime.
Provide fonts and assets as bytes
Node.js may read application files, but the portable converter accepts document resources as caller-provided data rather than paths.
import { readFile } from "node:fs/promises";
const font = await readFile("assets/Inter.ttf");
const converter = new HtmlConverter();
try {
converter.addFont("Inter", font);
const pdf = converter.htmlToPdf(
'<p style="font-family: Inter">Custom type</p>',
);
} finally {
converter.free();
}
Encode image bytes as data URLs in the HTML. Optional CJK and emoji packs enter through addFontPack.
Understand the portable WASM contract
- The Node.js entry loads only the package's own WASM binary.
- Document local paths and remote HTTP resources are unavailable.
- The converter has no direct file output, streaming writer, or async render call.
- Host code may write returned bytes with normal Node.js APIs.
Initialization errors identify a missing or invalid packaged WASM asset and preserve the underlying cause. Conversion failures surface as JavaScript errors.