与ghostscript c-api的接口,包括基于cTypes的高级和低级接口
python3-ghostscript的Python项目详细描述
Author: | Hartmut Goebel <h.goebel@crazy-compiler.com> |
---|---|
Version: | 0.5dev |
Copyright: | GNU Public License v3 (GPLv3) |
Homepage: | http://bitbucket.org/htgoebel/python-ghostscript |
Ghostscript,是postscript的著名解释器 语言和pdf格式。这个包实现了 Ghostscript C-API使用ctypes。无论是低级的还是Python的, 提供高级接口。
这个包目前只在gnu/linux下测试。请报告 它是否也适用于你的环境。谢谢。
示例
下面是一个如何使用 python鬼脚本。这实现了一个非常基本的ps2pdf工具:
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)
下面是一个将字符串文档传递给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()
更多示例可以在 分发档案。
要求和安装
Please note: | This package is meant for developers. Even if there are some usable examples included, installations instructions are meant for developers. |
---|
python ghostscript需要
- Python2.3或更高版本(使用python 2.6测试)
- ctypes使用python 2.3或2.4时(cTypes已经 包含在Python2.5及更高版本中)
- setuptools或distribute用于安装(见下文)。
- Ghostscript版本8.x
安装python ghostscript
既然这个包是为开发人员准备的,我们假设您已经 有安装python包的经验。
python ghostscript列在PyPI (Python Package Index)上,因此 您可以像往常一样使用easy_install或pip安装它。拜托 请参阅《简易安装手册》。pip进一步 信息。
或者我下载并解压 python ghostscript来自http://pypi.python.org/pypi/ghostscript和 运行:
python ./setup.py install