PyGhostscript

DOWNLOAD PyGhostscript

PyGhostscript is an extension for Python that natively binds (through ctypes) to the Ghostscript interpreter library, so if you don’t want to run Ghostscript through os.system calls to the interpreter, you can just call it up here using the handy GhostScript class inside the module to perform some of the more common actions in a clean manner.

I did this mainly as a challenge to myself. Originally there was a need to do this, but then that need went away before the project was complete. However, I didn’t want this code to go to waste.  So if you find this useful then great!

Documentation is included in the /doc folder in the zip.  It was generated using pydoc, so please excuse the insane color coding.

Running ghostscript.py from the command line will execute a small test program at the bottom to determine if it’s working right on your system.

A few notes:

  • This was originally written on Windows to use gsdll32.dll. I have made provisions in the code so that it should, in theory, work just fine on Linux, most of the UNIX environments out there, and OS X. If not, please let me know and I will make modifications to do so.
  • This is by no means feature complete and at parity with Ghostscript’s own interpreter library. There’s a ton of other features I’d like to add in, like PDF/X-3 and PDF/A support, and piecemeal PostScript command parsing. For now, you can convert PostScript to PDF, and PDF to PostScript quite easily.
  • It’s safest to instantiate a class of GhostScript in your code as you need it, perform an action, then instantiate a new one for another operation. It appears to be least cranky when it works that way (see the sample program at the bottom of ghostscript.py for details of proper operation).
  • You will need a copy of one of the newer versions of Ghostscript (>8.60) and its associated shared libraries installed on your system. This does not come with any.

One thought on “PyGhostscript

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.