npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wasmedia/wghostscript

v0.2.0

Published

Ghostscript compiled to WebAssembly for browsers

Downloads

603

Readme

wghostscript

pipeline status latest release license: AGPL 3.0 Ghostscript WebAssembly playground npm

Ghostscript compiled to WebAssembly for browsers, with broad PDF/PostScript feature support and three API layers (gsapi_* C bindings, CLI, and a high-level functional TypeScript API).

Try it in the browser: ghostscript.wasmedia.org, with PDF rendering, compression, PDF/A and PDF/X conversion, text extraction and PostScript → PDF, all client-side in a Web Worker.

This is the sibling of wimagemagick — the two projects deliberately do not overlap: wimagemagick excludes Ghostscript-based features (PDF rendering), and wghostscript covers them.

Install

npm install @wasmedia/wghostscript
import { initWGhostscript } from "@wasmedia/wghostscript";

const gs = await initWGhostscript();
const pages = await gs.ops.renderPdf(pdfBytes, { dpi: 150 }); // Map of PNGs
const text = await gs.ops.extractText(pdfBytes);

Full API: docs/api.md. Works in Node, in plain browser ES modules and workers, and with bundlers; Vite's dev server, Vite module workers and webpack need a line or two of config, see Using a bundler.

Status

Pre-1.0 and working: Ghostscript (current stable, tracked automatically) compiled to WASM, with the three API layers, a Web Worker entry, and a test suite covering the py-pdf sample corpus and veraPDF-validated PDF/A output. See briefs/INITIAL.md for the design brief.

Feature scope

Included

  • PDF → image rendering (rasterizing PDF pages to PNG, JPEG, TIFF, etc.)
  • PDF transformation (compression, flattening, PDF/A and PDF/X conversion, merging, splitting)
  • PostScript interpretation (rendering .ps input)
  • Font handling / text extraction

Excluded

  • Printer / CUPS output devices (not meaningful in a browser)
  • X11 / GTK display devices
  • Network / HTTP fetching from inside Ghostscript (security)
  • Tesseract OCR integration (compose with a separate WASM OCR build instead)
  • Multi-threading (single-threaded only — no SharedArrayBuffer / COOP/COEP requirement)

Technical requirements

  • Ghostscript version: Always target the current stable release. CI automation polls the official Artifex mirror (ArtifexSoftware/ghostpdl-downloads) GitHub Releases API and triggers a build when a new stable tag appears.
  • Scope: Ghostscript only (PostScript + PDF interpreter), not full GhostPDL (no PCL/XPS).
  • API surface (three layers):
    1. Low-level gsapi_* C bindings via cwrap/ccall.
    2. CLI-style interface via callMain() (["-sDEVICE=png16m", "-o", "out.png", "input.pdf"]).
    3. High-level functional TypeScript API: renderPdf, compressPdf, extractText, psToPdf, convertPdf, etc.
  • Toolchain: Emscripten inside Docker.
  • Output: Single .wasm + JS glue bundle, plus an npm-distributable package (@wasmedia/wghostscript).
  • File I/O: Both Emscripten MEMFS and direct ArrayBuffer/Blob passing.
  • Web Workers: Supported (and recommended for non-trivial work).
  • Browser support: Chrome and Safari at minimum.
  • Build: Single-threaded + SIMD — works on any site without special headers.
  • Fonts: URW base 35 fonts are compiled into the WASM (Ghostscript's %rom% file system), so standard fonts work offline with no setup.

Delegate libraries

The libraries Ghostscript bundles in its source tree, compiled in with it:

  • libjpeg (IJG) — JPEG output and DCT streams in PDFs
  • libpng — PNG output
  • libtiff — TIFF output
  • zlib — Flate streams in PDFs
  • OpenJPEG — JPEG 2000 streams in PDFs
  • jbig2dec — JBIG2 streams in PDFs
  • lcms2mt — colour management / ICC profiles
  • FreeType — font rendering

libidn, libpaper, IJS, CUPS and Tesseract are turned off (native/scripts/build-ghostscript.sh).

Architecture

Two layers, mirroring wimagemagick:

  1. native/ — C/WASM compilation. Cross-compiles Ghostscript and delegate libraries to WASM via Emscripten inside Docker. Output: dist/wghostscript.{js,wasm}.
  2. src/ — TypeScript wrapper:
    • loader.ts — initWGhostscript(), loads the WASM module
    • api.ts — gsapi_* bindings via cwrap/ccall
    • cli.ts — CLI-style execute() via callMain()
    • operations.ts — high-level functional API (renderPdf, compressPdf, extractText, psToPdf, convertPdf)
    • filesystem.ts — MEMFS + ArrayBuffer/Blob helpers
    • worker.ts — Web Worker entry point
    • types.ts — shared types
    • index.ts — public re-exports

Prior art

| Project | Status | Notes | |---------|--------|-------| | @okathira/ghostpdl-wasm | Active (v1.1.0, Nov 2025) | Most credible reference build; minimal delegate set (BMP/JPEG/PNG/PS/TIFF only); CLI-via-callMain | | @jspawn/ghostscript-wasm | Stale (last release 2022) | Basic npm package | | ochachacha/ps-wasm | Active | Browser-extension-style; PostScript viewing focus | | laurentmmeyer/ghostscript-pdf-compress.wasm | Demo | PDF compression demo (Web Worker example) |

Gaps wghostscript fills:

  • Three API layers (gsapi_* + CLI + high-level functional TS API). Existing options stop at CLI-via-callMain.
  • Maximum practical delegate set with color management and JPEG2000.
  • Documented SIMD build.
  • TypeScript-first wrapper layer.

Build & test

See docs/building.md once it lands. Short version:

npm run build           # native WASM (Docker) + TypeScript
npm run build:native    # WASM only
npm run build:ts        # TypeScript only
npm test
npm run test:watch
npm run test:browser    # headless Chrome end-to-end test of the playground
npm run playground      # local dev server hosting examples/browser

License

AGPL-3.0-or-later, matching upstream Ghostscript. Downstream users accept the copyleft obligations: any application using this package over a network must release its source under AGPL.