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.8
License:

GNU General Public License v3 or later (GPLv3+)

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],
    "-f",  sys.argv[2]
    ]
ghostscript.Ghostscript(*args)

Here an example for passing a string document to Ghostscript:

# documents passed to ghostscript need to be bytes
doc = b"""%!
/Helvetica findfont 20 scalefont setfont
50 50 moveto
(Hello World) show
showpage
quit
"""

import ghostscript

args = """test.py
     -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=/tmp/out.pdf
     """.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 https://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.8.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

ghostscript-0.8-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file ghostscript-0.8.tar.gz.

File metadata

  • Download URL: ghostscript-0.8.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for ghostscript-0.8.tar.gz
Algorithm Hash digest
SHA256 a299e60eabc926f463e22fbeabeb7932c903f83295d55e906bee4d5950ea327b
MD5 3971a9623a0b889aebdbb016a412a40e
BLAKE2b-256 7d6a150c1222786be666ea4b742089a4444ede5b4cd89d334ad346619554d406

See more details on using hashes here.

File details

Details for the file ghostscript-0.8-py3-none-any.whl.

File metadata

  • Download URL: ghostscript-0.8-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for ghostscript-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0a9ae42586076258930ceabb5fcc6aa60858d168935c0c481fe28010efc25c03
MD5 09c1f92db7788285579f32bff4a4b572
BLAKE2b-256 1d1d4d48ad94693dfc2ba963e14bbd93234de81a857f69dd8d14455bbd1faaa7

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