-
Notifications
You must be signed in to change notification settings - Fork 16
WASM Playground
Paul Gaston GOURON edited this page Apr 18, 2026
·
2 revisions
ironpress compiles to WebAssembly for browser-side PDF generation.
Enable with:
[dependencies]
ironpress = { version = "1.4", features = ["wasm"] }#[wasm_bindgen(js_name = "htmlToPdf")]
pub fn html_to_pdf(html: &str) -> Result<Uint8Array, JsError>
#[wasm_bindgen(js_name = "markdownToPdf")]
pub fn markdown_to_pdf(md: &str) -> Result<Uint8Array, JsError>
#[wasm_bindgen(js_name = "htmlToPdfCustom")]
pub fn html_to_pdf_custom(
html: &str,
page_width: f32, page_height: f32,
margin_top: f32, margin_right: f32,
margin_bottom: f32, margin_left: f32,
) -> Result<Uint8Array, JsError>wasm-pack build --target web --features wasmProduces:
-
pkg/ironpress_bg.wasm: WASM binary (~900 KB) -
pkg/ironpress.js: JS glue code -
pkg/ironpress.d.ts: TypeScript definitions
import init, { htmlToPdf, markdownToPdf } from './ironpress.js';
await init();
const pdfBytes = htmlToPdf('<h1>Hello</h1><p>World</p>');
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
window.open(url);const pdfBytes = markdownToPdf(`
# Euler's Identity
$$e^{i\\pi} + 1 = 0$$
`);Location: playground/index.html
Interactive web app for testing ironpress in the browser.
[Editor Panel] [Preview Panel]
textarea → WASM convert → PDF iframe
↑ ↑
examples blob URL
dropdown
- Split-panel UI: code editor on left, PDF preview on right
- Mode selector: HTML or Markdown
- Example loader with prebuilt templates:
- Simple page
- Invoice
- Report
- Markdown doc
- Math paper (LaTeX formulas)
- Real-time PDF generation via WASM
- PDF download button
- Loading indicator during WASM initialization
| Template | Content |
|---|---|
| Simple page | Basic HTML with heading and paragraph |
| Invoice | Styled invoice with table, flex layout, header/footer |
| Report | Multi-section report with charts, tables, flex metrics |
| Markdown doc | Full Markdown demo with headings, lists, code, links |
| Math paper | LaTeX formulas: quadratic, Gauss sum, Euler, integrals, matrices |
The playground is a single HTML file with no build step. Serve with any static file server:
cd playground
python3 -m http.server 8080The WASM binary must be in the same directory. Build with wasm-pack first.
- WASM compilation adds no runtime overhead beyond the initial load (~100ms)
- PDF conversion runs synchronously on the main thread
- For large documents, consider using a Web Worker to avoid blocking the UI
- The
remotefeature is not available in WASM (no network access from WASM without JS bridges)