基于ctypes的Ghostscript C-API接口,包括高级和低级
项目描述
- 版本:
- 0.7
- 许可证:
GNU通用公共许可证v3或更高版本(GPLv3+)
- 主页:
Ghostscript 是一种知名的PostScript语言和PDF解释器。此包通过 Ghostscript C-API 使用 ctypes 实现接口。提供低级和Pythonic、高级接口。
此包目前仅在GNU/Linux下进行测试。请报告它是否在您的环境中工作。谢谢。
示例
以下是如何使用 python-ghostscript 的高级接口的示例。这是一个非常基本的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)
更多示例可以在发行版归档的 examples 子目录中找到。
需求和安装
- 请注意:
本包适用于开发者。尽管包含了一些可用的示例,但安装说明主要是针对开发者的。
python-ghostscript 需要
Python 3.6或更高版本(已测试Python 3.6–3.9)
setuptools 用于安装(见下文)
Ghostscript 版本 9.0.8或更高版本
安装 python-ghostscript
由于本包适用于开发者,我们假设您有安装Python包的经验。
python-ghostscript 已列在 PyPI (Python包索引) 上,因此您可以使用 pip install ghostscript 像往常一样安装它。有关更多信息,请参阅 pip 的手册。
或者您可以从 http://pypi.python.org/pypi/ghostscript 下载并解压 python-ghostscript 的源代码包,然后运行
python ./setup.py install
项目详情
下载文件
下载适合您平台的应用程序。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
ghostscript-0.7.tar.gz (46.6 kB 查看散列)
构建分发
ghostscript-0.7-py2.py3-none-any.whl (25.3 kB 查看散列)