Go-powered PDF generation for Node.js and the browser (WASM).
npm install fojoimport { createPdf } from 'fojo'
import { writeFile } from 'node:fs/promises'
const bytes = await createPdf('Hello from fojo')
await writeFile('out.pdf', Buffer.from(bytes))fojo uses a bundled, platform-specific native binary under dist/bin/* and runs it via child_process.spawn.
Supported (Node) platforms:
- Linux x64
- macOS arm64
- Windows x64
The browser build fetches fojo.wasm from /fojo.wasm and expects the Go WASM runtime (wasm_exec.js) to be loaded (it provides the global Go constructor).
- Copy
node_modules/fojo/dist/wasm/fojo.wasmto your app’s public root asfojo.wasm. - Copy Go’s
wasm_exec.jsinto your app (from$(go env GOROOT)/misc/wasm/wasm_exec.js) and load it before your bundle (for example:<script src="/wasm_exec.js"></script>).
import { createPdf } from 'fojo'
const bytes = await createPdf('Hello from the browser')
const blob = new Blob([bytes], { type: 'application/pdf' })
const url = URL.createObjectURL(blob)
// Example download
const a = document.createElement('a')
a.href = url
a.download = 'out.pdf'
a.click()
URL.revokeObjectURL(url)The Node.js wrapper invokes the bundled CLI binary. You can run it directly:
./node_modules/fojo/dist/bin/<platform>/fojo "Some text" out.pdfPrereqs: Node.js + Go (see go/go.mod for the Go version).
npm test
npm run lint
npm run buildMIT