renderreportv0.7.0renderreport.casoon.de

Wasm and Cloudflare Workers

Compile the engine to wasm32 and render PDFs inside a JavaScript host without a file system.

With the wasm feature the engine compiles to wasm32-unknown-unknown and exports two functions through wasm-bindgen. The Wasm engine reads no system fonts and no packs from disk; it renders with the bundled Fira Sans.

Build

cargo build --release --target wasm32-unknown-unknown --no-default-features --features wasm
wasm-bindgen target/wasm32-unknown-unknown/release/renderreport.wasm --out-dir pkg --target web

--no-default-features leaves out barcodes, which a Worker rarely needs. Add it back with --features wasm,barcodes if your reports use the barcode component.

render

Takes a render request as a JSON string and returns the PDF bytes. Errors are thrown as strings (invalid RenderRequest JSON: …, render failed: …).

import { initSync, render } from './pkg/renderreport.js';
import wasmModule from './pkg/renderreport_bg.wasm'; // bundler-provided WebAssembly.Module

initSync({ module: wasmModule });

const pdf = render(JSON.stringify(request)); // Uint8Array

render_wordsearch

Builds a complete word search document from a small request: an explanation page, the puzzle and the solution, each on its own page. The grid is generated by the same word-search component as everywhere else.

import { render_wordsearch } from './pkg/renderreport.js';

const pdf = render_wordsearch(JSON.stringify({
  title: 'Animals',
  words: ['CAT', 'DOG', 'GUINEA PIG'],
  translations: ['Katze', 'Hund', 'Meerschweinchen'],
  language: 'en',
}));
Field Default Notes
title – Required
words – Required; spaces are kept in the word list, not in the grid
description per language Line above the grid
translations [] One entry per word, null to skip; turns the word list into a vocabulary table
width, height 12 Grid size in letters
allow_diagonal true
allow_reverse false Words may also read right to left and bottom to top
seed 42 Same seed, same grid
columns_word_list 3 Columns of the plain word list
language de de, en, fr or es; labels and explanation text

Edit this page on GitHub · Docs for v0.7.0