与ghostscript c-api的接口,包括基于cTypes的高级和低级接口
ghostscript的Python项目详细描述
Author: | Hartmut Goebel <h.goebel@crazy-compiler.com> |
---|---|
Version: | 0.6 |
License: | GNU Public License v3 (GPLv3) |
Homepage: | https://gitlab.com/pdftools/python-ghostscript |
Ghostscript是postscript的著名解释器 语言和pdf格式。这个包实现了 Ghostscript C-API使用ctypes。无论是低级的还是Python的, 提供高级接口。
这个包目前只在gnu/linux下测试。请报告 它是否也适用于你的环境。谢谢。
示例
下面是一个如何使用 python鬼脚本。这实现了一个非常基本的ps2pdf工具:
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)
下面是一个将字符串文档传递给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)
更多示例可以在 分发档案。
要求和安装
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.7或更高版本(使用python 2.7、3.4、3.6和3.6进行测试)
- setuptools用于安装(见下文)
- Ghostscript8.x或更高版本(用9.x测试)
安装python ghostscript
既然这个包是为开发人员准备的,我们假设您已经 有安装python包的经验。
python ghostscript列在PyPI (Python Package Index)上,因此 您可以像往常一样使用pip install ghostscript来安装它。拜托 有关更多信息,请参阅pip手册。
或者我下载并解压 python ghostscript来自http://pypi.python.org/pypi/ghostscript和 运行:
python ./setup.py install