Browser getting started

Generate a PDF
without leaving the browser

Load the WebAssembly renderer once, convert locally, and keep document content inside the user's browser.

ES modules · JavaScript and TypeScript

Install the npm package

npm install ironpress

The package root is the browser entry point. Your bundler must support ES modules and WebAssembly assets.

Create and download an HTML PDF

Initialize the WASM module before calling exported conversion functions:

import init, { htmlToPdf } from "ironpress";

await init();

const pdf = htmlToPdf("<h1>Hello from the browser</h1>");
const url = URL.createObjectURL(
  new Blob([pdf], { type: "application/pdf" }),
);

const link = document.createElement("a");
link.href = url;
link.download = "output.pdf";
link.click();
URL.revokeObjectURL(url);
Returned type

Browser conversion returns Uint8Array. Wrap it in a Blob for preview, download, upload, or IndexedDB storage.

Render Markdown

import init, { markdownToPdf } from "ironpress";

await init();
const pdf = markdownToPdf("# Release notes\n\nEverything shipped.");

Use a configured converter

A converter keeps page and rendering settings across calls. WASM-owned objects must be freed when they are no longer needed.

import init, { HtmlConverter } from "ironpress";

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();
}

Provide fonts and document assets

The WASM renderer does not read paths. Fetch or import resource bytes in your host application, then pass them to the converter.

const response = await fetch("/fonts/Inter.ttf");
const font = new Uint8Array(await response.arrayBuffer());

const converter = new HtmlConverter();
try {
  converter.addFont("Inter", font);
  const pdf = converter.htmlToPdf(
    '<p style="font-family: Inter">Custom type</p>',
  );
} finally {
  converter.free();
}

Provide images as data URLs in the HTML. Optional CJK and emoji font packs enter through addFontPack as downloaded bytes.

Manage initialization, errors, and memory

  • Await the default initializer before the first conversion.
  • Call free() for every reusable converter.
  • Local paths, direct file output, streaming, and remote fetching are unavailable.
  • Conversion is synchronous after asynchronous WASM initialization.

Initialization and conversion failures surface as JavaScript errors. Catch them at the UI boundary and keep raw untrusted document details out of user-facing messages.

Go further