ghostscriptwazero

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

README

ghostscriptwazero

Go library with Ghostscript (currently 10.5.1), built to WASM, run with Wazero with fake memory filesystem.

This is NOT a generic WASM/WASI ghostcript port! This is just for wazero. Ghostscript is using setjmp/longjmp, it's not really clear how to use that in generic WASI.

This is mostly just making sense as a part of my PDF-to-PDFA conversion tool. But the whole thing can be use as ghostscript in the backend, from go, without cgo, on all go platforms!

It works on all platforms where Go works; it was tested on Linux, Windows and Mac.

The build of the wasm is a bit crazy, as it uses a custom fork of emscripten that produces wasm that only works in wazero, and it uses a patched ghostscript. The patched emscripten is necessary for setjmp/longjmp support; patched ghostscript to remove some indirect calls.

Note that only PDF-to-PDFA is really tested. I am accepting issues when something else doesn't work, but only if you attach the input files.

How to use

See pdf2pdfa3b, which is a library + a cmd tool that tries to convert from PDF to PDF/A 3b.

You first need to init new GS runtime with ghostscriptwazero.New(), which creates a new runtime. Then you can use it with .Run() or .BasicRun(). Each run creates a new fake directory in memory. There is no read or write from disk; all files are either in memory or embeded in the binary.

License

NOTE THAT THE WHOLE THING IS AFFERO GPL, because Ghostscript itself is Affero GPL. This can be a problem for your backend, consult your copyright lawyers.

If you want a GPLv3 version, you can use GS version 9.06 (it's safe as it is contained with no access to FS) - see here https://github.com/karelbilek/ghostscript-9.06 - but I don't want to maintain it.

License:

Affero GPL

Copyright

(C) 2023 Karel Bilek, Jeroen Bobbeldijk (https://github.com/jerbob92)

Ghostscript license details are in build/ghostpdl/ submodule. The current GS version is 10.05.1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotWriteInitialFile   = errors.New("cannot write initial file")
	ErrRunningGhostscriptModule = errors.New("error running ghostscript module")
	ErrCannotReadResultFile     = errors.New("cannot read result file")
)

Functions

This section is empty.

Types

type ErrMissingFile

type ErrMissingFile struct {
	ResultFileName string
	StdOut         string
	StdErr         string
}

func (*ErrMissingFile) Error

func (e *ErrMissingFile) Error() string

type ErrRunningGhostscript

type ErrRunningGhostscript struct {
	Err    error
	StdOut string
	StdErr string
}

func (*ErrRunningGhostscript) Error

func (e *ErrRunningGhostscript) Error() string

func (*ErrRunningGhostscript) Unwrap

func (e *ErrRunningGhostscript) Unwrap() error

type File

type File struct {
	Path    string
	Content []byte
}

type GS

type GS struct {
	// contains filtered or unexported fields
}

func NewGS

func NewGS(ctx context.Context) (*GS, error)

func (*GS) BasicRun

func (gs *GS) BasicRun(ctx context.Context, in []byte, opts []string) ([]byte, string, error)

func (*GS) Run

func (gs *GS) Run(ctx context.Context, stdOut, stdErr io.Writer, args []string, files []File) (map[string]File, error)

Directories

Path Synopsis
cmd command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL