Rasura

Install

One package for the browser and Node, one crate family for Rust. No native build step in either.

JavaScript

Shell
npm install rasura

The package ships an ES module, a CommonJS shim, a WebAssembly module and hand-written TypeScript declarations. There is no postinstall script and no native build step. CI proves that by packing the tarball, installing it into an empty directory with --ignore-scripts, and editing a PDF with it.

JavaScript
import { Pdf } from 'rasura'
const doc = await Pdf.open(await file.arrayBuffer())

By default this starts a Worker and does the parsing off the main thread. Pass { worker: false } to run inline, which is useful in tests and when debugging, and runs exactly the same code.

Rust

The facade crate re-exports everything most callers need. The layers below it are published separately and are usable on their own if you want the object model without the document model.

TOML
[dependencies]
rasura = "0.1"
Rust
use rasura::{Document, SaveOptions};
let mut doc = Document::open(std::fs::read("in.pdf")?)?;
println!("{} pages", doc.page_count());

Bundlers and hosts

The .wasm file is a separate asset. Most bundlers resolve it from the package automatically. If yours does not, or if you serve it from a CDN, point at it explicitly:

JavaScript
const doc = await Pdf.open(bytes, {
wasmUrl: '/assets/rasura_wasm_bg.wasm',
})

Two things a host can get wrong

Serve .wasm with the application/wasm content type, or streaming compilation falls back to a slower path and some engines refuse it outright. And if you set a content-security policy, it needs wasm-unsafe-eval in script-src. Both failures look like the module never loading.

Rasura does not need SharedArrayBuffer, so it does not need COOP and COEP headers. That is what lets it run on static hosts such as GitHub Pages.