Skip to content

Render in the browser or on the edge

Use @pressjet/wasm when the caller already has the document HTML or native tree and needs to produce PDF bytes in-process. Install the WebAssembly package.

Load the module and render HTML

Serve the package's exported engine.wasm at /assets/pressjet.wasm with the media type application/wasm. Compile it once and reuse the renderer for repeated exports.

import { createRenderer } from "@pressjet/wasm";

const module = await WebAssembly.compileStreaming(fetch("/assets/pressjet.wasm"));
const renderer = createRenderer(module);
const { pdf, diagnostics } = await renderer.renderHtml("<h1>Invoice 42</h1>");
console.log(diagnostics);

const url = URL.createObjectURL(new Blob([pdf], { type: "application/pdf" }));
const link = document.createElement("a");
link.href = url;
link.download = "invoice.pdf";
link.textContent = "Download invoice";
document.body.append(link);
window.addEventListener("pagehide", () => URL.revokeObjectURL(url), { once: true });

Use a Web Worker for interactive exports so rendering does not block the page. For edge deployments, use your bundler's WASM module import and return the PDF with Content-Type: application/pdf. Worker and framework examples

Render framework components

React, Preact, Vue, and Svelte adapters turn existing components into static HTML and render that HTML with the engine. Pass compiled print styles separately if your component uses scoped or external CSS.

import { renderPdf } from "@pressjet/wasm/react";

const { pdf, diagnostics } = await renderPdf(renderer, <Invoice number="42" />, {
  stylesheets: ["@page { size: A4 }"],
});

Use the HTML and print CSS reference when choosing layout rules. Check client-side resource limits and isolation before shipping templates that use large images.