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.4.1
Homepage:

http://bitbucket.org/htgoebel/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 ghostscript

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

ghostscript.Ghostscript(*args)

Here an example for passing a string document to Ghostscript:

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

import ghostscript

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

GS = ghostscript.Ghostscript(*args)
try:
    GS.run_string(doc)
finally:
    GS.exit()

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

  • Python 2.3 or higher (tested with Python 2.6)

  • ctypes when using Python 2.3 or 2.4 (ctypes is already included in Python 2.5 and higher)

  • setuptools or distribute for installation (see below).

  • Ghostscript Version 8.x

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 easy_install or pip as usual. Please refer to the manuals of easy_install resp. pip for further information.

Alternatively you may download and unpack the source package of python-ghostscript from http://pypi.python.org/pypi/ghostscript and run:

python ./setup.py install

Showing your appreciation

Of course, the best way to show your appreciation for the git-flow tool itself remains contributing to the community. If you’d like to show your appreciation in another way, however, consider donating through PayPal: Donate

Project details


Download files

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

Source Distributions

ghostscript-0.4.1.zip (46.2 kB view details)

Uploaded Source

ghostscript-0.4.1.tar.bz2 (28.1 kB view details)

Uploaded Source

File details

Details for the file ghostscript-0.4.1.zip.

File metadata

  • Download URL: ghostscript-0.4.1.zip
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ghostscript-0.4.1.zip
Algorithm Hash digest
SHA256 bf5cc6ac7fdd29bc8caf0094ed8f91e1ca8c17f668c02667acf15076f02fa25f
MD5 42bd242bd134afff770720baff2b2864
BLAKE2b-256 f6563e368fcfee387aaeff3b5d1898b30702ba250d32166ef66936edf06283fd

See more details on using hashes here.

File details

Details for the file ghostscript-0.4.1.tar.bz2.

File metadata

  • Download URL: ghostscript-0.4.1.tar.bz2
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ghostscript-0.4.1.tar.bz2
Algorithm Hash digest
SHA256 72cca4be76efea43feec4146fdbc219418f2162c746472f452236bc2136139a0
MD5 4409b5e46bf53db33e539938e65c46dd
BLAKE2b-256 e63b1fbaaafda0a83b721e6e83f45e27c0581cb678f497568747abed9ed16cd9

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