与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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
文件名的java正则表达式限制名称大小和文件扩展名   Mac上的java Android SDK:jspawnhelper意外退出   java SQL Server 2000到Oracle 12c重音字符   在Java中快速比较大数据集中的值和小数据集中的值   java在代码中的许多地方保留对对象的引用   Java规范中私有内部类的jvm访问标志与反射API不一致?   比较2个int数组中匹配的数字   java Apache Commons数学简化回归:get prediction stderr   安卓 Java SDK管理器因命令行输出中的“flashplayerplugin”而崩溃   JavaSQLite:关闭DB时必须关闭游标吗?   泛型Java设计抽象类声明示例说明   java应用程序在添加片段时崩溃   如何在java中使用注释为字段加载值