@thinkthinksyn/pdfcpu-wasm
v0.2.0
Published
pdfcpu WebAssembly module — edit PDFs from the browser or Node.js
Maintainers
Readme
@thinkthinksyn/pdfcpu-wasm
Standalone npm package for the pdfcpu WebAssembly build. It exposes the full pdfcpu API (validate, optimize, merge, split, encrypt, watermark, extract, etc.) to TypeScript/JavaScript, entirely in-memory.
Install
npm install @thinkthinksyn/pdfcpu-wasmUsage
import { Pdfcpu } from "@thinkthinksyn/pdfcpu-wasm/pdfcpu.ts";
const pdfcpu = await Pdfcpu.create("/pdfcpu.wasm");
const pdf = new Uint8Array(await (await fetch("doc.pdf")).arrayBuffer());
const opt = pdfcpu.optimize(pdf);
if (opt.ok) {
// opt.data is a Uint8Array with the optimized PDF
}See example/optimize.ts for a complete Deno/Node example.
Build locally
# Requires Go 1.25+
./build.shOutput lands in dist/:
| File | Purpose |
|---|---|
| pdfcpu.wasm | Compiled WASM binary (~19 MB / ~5 MB gzip'd) |
| wasm_exec.js | Go WASM runtime glue |
| version.json | pdfcpu dependency version and build metadata |
Automated upstream updates
.github/workflows/update.yml runs daily and on manual dispatch. It:
- Queries the latest stable release of
pdfcpu/pdfcpu - Compares it with the version currently packaged
- If newer, bumps
go.mod/go.sum - Rebuilds the WASM binary
- Bumps
package.jsonversion to match the upstream release - Publishes
@thinkthinksyn/pdfcpu-wasmto npm - Commits the updated files back to this repo
Setup
- Create the npm package
@thinkthinksyn/pdfcpu-wasmat https://www.npmjs.com/. - Add an
NPM_TOKENsecret to this repo:- Generate a Granular Access Token with Read and write access to
@thinkthinksyn/pdfcpu-wasmand Bypass two-factor authentication enabled. - Add it at
Settings → Secrets and variables → Actions → New repository secret.
- Generate a Granular Access Token with Read and write access to
- Make sure the default
GITHUB_TOKENhas Read and write permissions (Settings → Actions → General → Workflow permissions).
Manual run
gh workflow run update.yml -f pdfcpu_version=v0.13.0 -f dry_run=trueThis checks out the specified upstream version, builds the WASM, but skips npm publish and the git push.
Repo layout
.
├── .github/workflows/update.yml # Upstream update automation
├── main.go # Go WASM entry point
├── pdfcpu.ts # TypeScript bindings
├── build.sh # Local build script
├── package.json # npm metadata
├── go.mod / go.sum # Go module files
├── dist/ # Build output (tracked for npm/distribution)
└── example/optimize.ts # Usage exampleLicense
Apache-2.0 (same as pdfcpu).
