Author: Hartmut Goebel <>
Version: 0.5dev
Copyright: GNU Public License v3 (GPLv3)

Ghostscript is a well known interpreter for the PostScript language and for PDF. This package implements a interface to the Ghostscript C-API using ctypes. Both a low-level and a pythonic, high-level interface are provided.

This package is currently tested only under GNU/Linux. Please report whether it works in your environment, too. Thanks.


Here is an example for how to use the high-level interface of python-ghostscript. This implements a very basic ps2pdf-tool:

import sys
import locale
import ghostscript

args = [
    "ps2pdf", # actual value doesn't matter
    "-dNOPAUSE", "-dBATCH", "-dSAFER",
    "-sOutputFile=" + sys.argv[1],
    "-c", ".setpdfwrite",
    "-f",  sys.argv[2]

# arguments have to be bytes, encode them
encoding = locale.getpreferredencoding()
args = [a.encode(encoding) for a in args]


Here an example for passing a string document to Ghostscript:

doc = b"""%!
/Helvetica findfont 20 scalefont setfont
50 50 moveto
(Hello World) show

import ghostscript

args = b"""
     -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=/tmp/out.pdf
     -c .setpdfwrite""".split()

with ghostscript.Ghostscript(*args) as gs:

More examples can be found in the examples subdirectory of the distribution archive.

Requirements and Installation

Please note:This package is meant for developers. Even if there are some usable examples included, installations instructions are meant for developers.

python-ghostscript requires

Installing python-ghostscript

Since this package is meant for developers, we assume you have experience in installing Python packages.

python-ghostscript is listed on PyPI (Python Package Index), so you can install it using pip install ghostscript as usual. Please refer to the manuals of pip for further information.

Alternatively you my download and unpack the source package of python-ghostscript from and run:

python ./ install