ArtifexSoftware/ghostpdl

GitHub: ArtifexSoftware/ghostpdl

GhostPDL 是一个集成了 PostScript、PDF、PCL、XPS 解释器和多格式图像处理能力的统一文档渲染与转换引擎。

Stars: 246 | Forks: 78

# Ghostscript 系列产品 GhostPDL 包含了完整的 Artifex 文档处理套件: 一个统一的解释器包和一个共享的图形库,用于渲染、 转换和处理所有主要页面描述语言和多种图像格式的文档。 它将 Ghostscript (PostScript/PDF)、GhostPDF、GhostPCL (PCL/PXL)、 GhostXPS (XPS) 和 GhostPDL 整合在一个源码树中。 ## 目录 1. 本仓库包含的内容 2. 获取预编译二进制文件 3. 环境要求 4. 快速入门 5. 核心功能 6. 命令行示例 7. 语言绑定 8. 从源码编译 9. 文档 10. 许可证 11. 本仓库包含的内容 GhostPDL 是整个 Ghostscript 产品系列的源码发行版总集。 每个解释器都构建于同一个共享的 Ghostscript 图形库之上, 可以单独或一起编译。 Ghostscript PostScript Level 3 和 PDF 解释器及渲染器 GhostPDF 独立的基于 C 语言的 PDF 解释器(自 9.55 版本起默认使用) GhostPCL PCL5 和 PCL/XL (PXL) 解释器 GhostXPS XPS (XML Paper Specification) 解释器 GhostPDL 多语言框架;自动检测 PS、PDF、PCL、XPS 以及图像格式 当作为 GhostPDL 运行时,解释器会利用文件签名和启发式算法自动检测 输入语言——对于混合语言的作业流无需任何标志。 同时支持 PJL (Printer Job Language) 组帧来分隔作业。 2. 获取预编译二进制文件 对大多数用户而言,预编译二进制文件是快速上手的最快途径。 只有在将 Ghostscript 作为库嵌入或自定义构建时,才需要进行源码编译。 Linux (Debian/Ubuntu): ``` sudo apt-get install ghostscript ``` macOS (MacPorts): ``` sudo port install ghostscript ``` macOS (Homebrew): ``` brew install ghostscript ``` Windows: ``` Download the installer from: https://github.com/ArtifexSoftware/ghostpdl-downloads/releases Both 32-bit and 64-bit command-line executables are provided. ``` 验证安装: ``` gs --version or on Windows: gswin64c --version ``` 3. 环境要求 运行环境: 操作系统 Linux、macOS、Windows、BSD 及其他类 Unix 平台 架构 x86、x86-64、ARM 等(取决于具体平台的构建) 构建依赖项(仅限源码编译): C 编译器 GCC、Clang 或 MSVC(Visual Studio 2015 或更高版本) make / nmake Unix 上使用 GNU make;Windows 上通过 Visual Studio 使用 nmake autoconf 从 git 检出版本构建时需要(运行 autogen.sh) FreeType 内置于 freetype/ 目录;也接受使用外部版本 libjpeg, zlib, libpng 内置或由系统提供 libtiff 可选;TIFF 输出所需 OpenJPEG 可选;支持 JPEG 2000 所需 注意:pcl/urwfonts/ 目录下的 PCL/XL 字体是 GhostPCL 运行所必需的, 其分发遵循 AFPL 许可证,禁止商业用途。它们不是自由软件。 详情请参阅源码发行版中的 pcl/COPYING.AFPL 文件。 4. 快速入门 将 PDF 转换为 PNG 图像(每页一张): ``` gs -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 \ -sOutputFile=page_%03d.png input.pdf -dBATCH -dNOPAUSE Run non-interactively and exit when done -sDEVICE=png16m 24-bit color PNG output device -r300 300 DPI output resolution -sOutputFile=page_%03d.png Numbered output files ``` 将 PostScript 转换为 PDF: ``` gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ -sOutputFile=output.pdf input.ps Or use the convenience wrapper: ps2pdf input.ps output.pdf ``` 将 PDF 转换为单个 JPEG: ``` gs -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 \ -sDEVICE=jpeg -r150 -sOutputFile=page1.jpg input.pdf ``` 5. 核心功能 PostScript 完整的 PostScript 语言 Level 3 解释器 PDF 读取并渲染 PDF 1.0-2.0;通过 pdfwrite 设备写入 PDF (9.55+ 版本:基于 C 语言的全新解释器) PCL / PXL 通过 GhostPCL 支持 PCL5 和 PCL/XL(HP 打印机语言) XPS 通过 GhostXPS 支持 XML Paper Specification 图像格式 输入:JPEG (JFIF/EXIF)、PNG、TIFF、JBIG2、JPEG 2000、 PWG。输出:PNG、JPEG、TIFF、BMP、PCX、PBM/PGM/PPM 等 光栅化 以任意 DPI 渲染为光栅图像;支持抗锯齿控制 PDF 输出 将 PostScript、PCL、XPS 和图像转换为 PDF; 压缩并优化现有的 PDF PostScript 输出 将 PDF 转换回 PostScript Level 2 N-up 拼版 将多页内容拼版到同一张纸上;适用于所有输入类型 OCR 将扫描的光栅图像转换为可搜索的 PDF (自 9.53 版本起) PDF 压缩 在无损画质的前提下减小 PDF 文件大小 语言检测 GhostPDL 自动识别输入语言 PJL 支持 支持 PJL (Printer Job Language) 组帧用于作业分隔 可嵌入库 将 libgs 链接为共享/静态库;支持提供 Python、Java 和 C# 绑定的 gsapi C 接口 色彩管理 支持 ICC 配置文件;CMYK、RGB、Gray、DeviceN 字体支持 Type 1、TrueType、OpenType、CFF;支持字体替换和内嵌 6. 命令行示例 渲染特定页面范围: ``` gs -dBATCH -dNOPAUSE -sDEVICE=png16m -r150 \ -dFirstPage=2 -dLastPage=5 \ -sOutputFile=page_%d.png input.pdf ``` 以灰度模式渲染: ``` gs -dBATCH -dNOPAUSE -sDEVICE=pnggray -r300 \ -sOutputFile=page_%03d.png input.pdf ``` 压缩/优化 PDF: ``` gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook \ -sOutputFile=compressed.pdf input.pdf -dPDFSETTINGS options: /screen 72 dpi /ebook 150 dpi /printer 300 dpi /prepress 300 dpi, color-preserving /default ``` 转换受密码保护的 PDF: ``` gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ -sPDFPassword=secret -sOutputFile=unlocked.pdf input.pdf ``` 将 XPS 转换为 PDF (GhostXPS): ``` gxps -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ -sOutputFile=output.pdf input.xps ``` 将 PCL 转换为 PDF (GhostPCL): ``` gpcl6 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \ -sOutputFile=output.pdf input.pcl ``` 获取帮助并列出可用设备: ``` gs -h ``` 7. 语言绑定 gsapi C 接口将完整的 Ghostscript 引擎作为一个可嵌入的库公开提供。 官方绑定包含在仓库的 demos/ 目录下。 C psi/iapi.h gsapi_new_instance, gsapi_init_with_args, gsapi_exit Python demos/python/gsapi.py gsapi_new_instance(), gsapi_run_file() Java demos/java/ GSAPI, GSInstance C# demos/csharp/ GhostAPI.ghostapi (静态方法) Python 示例: ``` import gsapi instance = gsapi.gsapi_new_instance(0) gsapi.gsapi_set_arg_encoding(instance, gsapi.GS_ARG_ENCODING_UTF8) gsapi.gsapi_init_with_args(instance, [ "gs", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite", "-sOutputFile=output.pdf", "input.ps" ]) gsapi.gsapi_exit(instance) gsapi.gsapi_delete_instance(instance) ``` C# 示例: ``` using GhostAPI; IntPtr instance; ghostapi.gsapi_new_instance(out instance, IntPtr.Zero); ghostapi.gsapi_set_arg_encoding(instance, (int)gsEncoding.GS_ARG_ENCODING_UTF8); string[] args = { "gs", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite", "-sOutputFile=output.pdf", "input.ps" }; ghostapi.gsapi_init_with_args(instance, args.Length, args); ghostapi.gsapi_exit(instance); ghostapi.gsapi_delete_instance(instance); ``` 线程注意事项:除非使用 GS_THREADSAFE 编译,否则同一时间只能有一个活动的 Ghostscript 实例。 8. 从源码编译 Unix / Linux / macOS: ``` # 1. Clone canonical repository git clone git://git.ghostscript.com/ghostpdl.git cd ghostpdl # 2. 生成 configure script # (仅限 git checkout;release tarballs 不需要) ./autogen.sh # 3. Configure ./configure # 4. Build make # 5. Install (可选) sudo make install ``` 若要构建为共享库而非可执行文件: ``` make so # builds libgs.so / libgs.dylib ``` 9. 文档 文档目录: https://ghostscript.readthedocs.io 如何使用 Ghostscript (命令行参考): https://ghostscript.readthedocs.io/en/latest/Use.html 从源码编译: https://ghostscript.readthedocs.io/en/latest/Make.html GhostPDL 框架: https://ghostscript.readthedocs.io/en/latest/GPDL.html 语言绑定 (C, Python, Java, C#): https://ghostscript.readthedocs.io/en/latest/LanguageBindings.html 输出设备: https://ghostscript.readthedocs.io/en/latest/Devices.html PDF 转换: https://ghostscript.readthedocs.io/en/latest/VectorDevices.html 色彩管理: https://ghostscript.readthedocs.io/en/latest/GhostscriptColorManagement.html 源代码架构: https://ghostscript.readthedocs.io/en/latest/Develop.html 更新日志: https://ghostscript.readthedocs.io/en/latest/News.html Bug 跟踪器: https://bugs.ghostscript.com Discord (#ghostscript): https://artifex.com/discord/artifex 权威 git 仓库: https://cgit.ghostscript.com/ghostpdl.git 二进制文件下载: https://ghostscript.com/releases 第三方库列表: https://ghostscript.readthedocs.io/en/latest/thirdparty.html 10. 许可证 GhostPDL 提供两种许可证选项: GNU AGPL v3 (https://www.gnu.org/licenses/agpl-3.0.html) 对开源软件免费。任何使用、分发或以网络服务形式提供对 Ghostscript 访问的应用程序,都必须在兼容的开源许可证下发布其完整的源代码。 商业许可证 如果无法满足 AGPL 合规要求,专有应用程序必须使用此许可证。请联系 Artifex 进行许可授权: https://artifex.com/contact/ghostscript 第三方库 关于内置第三方库(FreeType、libjpeg、zlib、OpenJPEG 等)的完整列表、它们的版本及许可证,请参阅以下页面维护的信息: https://ghostscript.readthedocs.io/en/latest/thirdparty.html
标签:JS文件枚举, PDF, PostScript, 客户端加密, 文档处理, 格式转换, 渲染引擎, 逆向工具, 页面描述语言