Ghostscript compiled to WebAssembly
Note
This is low-level WebAssembly library which part of @privyid/ghoulscript.
This use GS version 10.07.1
yarn add @privyid/ghostscriptimport Module from '@privyid/ghostscript'
const mod = await Module()
const working = '/working'
mod.FS.mkdir(working)
mod.FS.mount(mod.NODEFS, { root: __dirname }, working)
mod.FS.chdir(working)
await mod.callMain([
'-q',
'-dSAFER',
'-dBATCH',
'-dNOPAUSE',
'-sDEVICE=png16m',
'-dGraphicsAlphaBits=4',
'-sOutputFile=out/sammple.png',
'sample.pdf',
])- Clone this repo
- Install Emcripten SDK
- Run
yarn build - Run
yarn test
The Ghostscript WASM build requires the Emscripten SDK and runs inside a container to keep your host clean.
-
Docker with BuildKit enabled (
DOCKER_BUILDKIT=1) -
Git submodule initialised:
git submodule update --init packages/ghostscript/ghostpdl
Builds into dist/:
DOCKER_BUILDKIT=1 docker build \
--target builder \
-f Dockerfile \
. \
--output dist/Or build to a tarball first, then extract:
DOCKER_BUILDKIT=1 docker build \
--target builder \
-f Dockerfile \
. \
-o /tmp/ghostscript-wasm-build.tar
tar -xf /tmp/ghostscript-wasm-build.tar -C packages/ghostscript/The build clones EMSDK 6.0.6 inside the container and runs the same ./build.sh script that CI uses. Full compilation typically takes 10–30 minutes depending on CPU cores.
If you already have EMSDK 6.0.6 installed:
source /opt/emsdk/emsdk_env.sh # or your emsdk activation path
yarn build@jsscheller - for build script.