Skip to main content

Interface to the Ghostscript C-API, both high- and low-level, based on ctypes

Project description

Author:

Hartmut Goebel <h.goebel@crazy-compiler.com>

Version:
0.5dev
Homepage:

https://gitlab.com/pdftools/python-ghostscript

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.

Example

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",
    "-sDEVICE=pdfwrite",
    "-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]

ghostscript.Ghostscript(*args)

Here an example for passing a string document to Ghostscript:

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

import ghostscript

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

with ghostscript.Ghostscript(*args) as gs:
    gs.run_string(doc)

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 http://pypi.python.org/pypi/ghostscript and run:

python ./setup.py install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghostscript-0.5.dev0.linux-x86_64.tar.gz (18.1 kB view details)

Uploaded Source

Built Distributions

ghostscript-0.5.dev0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

ghostscript-0.5.dev0-py2.py3-none-any.whl (15.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ghostscript-0.5.dev0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for ghostscript-0.5.dev0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 2ac0003e96d20871a01e3ff5e444b7dfb9651e471b0b26a5990a9ad97cbb5afc
MD5 95889574abbbf358506ced7ca4647c8c
BLAKE2b-256 9400b7a251046919bc7086415ca952ea3fb2df85a996340905453472cb20c990

See more details on using hashes here.

File details

Details for the file ghostscript-0.5.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for ghostscript-0.5.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 616767fdf22fae7dc2de377332b4542725ab76295a83d33954ef8a6bbb7dffb3
MD5 6f5d6dc59a4bd8362b4fb942182c1b30
BLAKE2b-256 974a0e1585213909bc5691cce7cc6c8d7ba2fb560f66b8d66bc1cb0f8a21e756

See more details on using hashes here.

File details

Details for the file ghostscript-0.5.dev0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ghostscript-0.5.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ed9d62de412299117dbeaab8b0e143c8af1ca66e2eb30a7f7754ef89e48bd854
MD5 e34cf1cce1c522a55495137ca5fe48a9
BLAKE2b-256 e8be6046ddf8ff957c639d942893ff3afb68fe7d0db21546b62f48055d44e6e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page