您可以在闭源 Java 软件中提供 Ghostscript 替代方案
将 PostScript、EPS 和 XPS 转换为 PDF 以及来自纯 Java 库的图像,无需 JNI、本机转换器二进制或 Copyleft 义务。
您需要在 Java 应用程序中转换 PostScript、EPS 或 XPS 文件。Artifex 工具能够很好地完成这项工作,并且可以免费下载:Ghostscript 解释 PostScript 和 EPS,GhostXPS 则处理 XPS。随后,您的法律团队阅读许可证,项目便停了下来。
即使许可已经解决,您的运营团队可能会问为什么每个主机和容器现在都需要一个与其架构和 C 运行时相匹配的本机库。
本页解释了这两个限制、选项(包括与我们无关的选项)以及如果 Aspose.Page 合适的话如何迁移。
许可证的实际要求是什么
自 2013 年 2 月版本 9.07 起,Ghostscript 已获得 GNU Affero 通用公共许可证 v3 的双重许可。在此之前,它是 GPL v3。 Artifex Software 拥有版权并出售商业许可证作为 AGPL 合规性的替代方案。 同样的双重许可也涵盖更广泛的 GhostPDL 源代码树,其中包括 GhostXPS 解释器,因此以 XPS 代替 PostScript 进行处理并不会改变许可问题。
AGPL 的 Copyleft 条款可以要求在 AGPL 下发布衍生作品的完整相应源代码。它还扩展到通过网络向用户提供的软件,因此从未发布 JAR 的 Java Web 应用程序或 SaaS 后端不会自动超出其范围。
重要的细微差别:链接与付费
一个常见的立场是,通过 `ProcessBuilder` 调用 `gs` 可以避免 Copyleft,因为应用程序未链接到库。这是真正有争议的领土。对于流程边界是否具有决定性,或者组合程序的通信和设计的密切性是否更重要,指导意见有所不同。
常见的Java包装器`ghost4j`又有所不同:它通过JNA绑定Ghostscript C API并将本机库加载到JVM进程中而不是脱壳。
We are not your lawyers, and this page is not legal advice.您的法律团队必须评估您的产品的构建、提供和分销方式。对于很多团队来说,不确定性本身就是他们不愿意承担的成本。
判例法
在 *Artifex Software, Inc. v. Hancom, Inc.* 案中,Artifex 声称 Hancom 在未购买商业许可证或未遵守 GPL 的来源披露要求的情况下,将 GPL 许可的 Ghostscript 纳入 Hancom Office。
在 25 April 2017 上,U.S. District Court for the Northern District of California 驳回了 Hancom 的驳回动议。该裁决允许 Artifex 继续处理违反合同和侵犯版权的问题。双方于 2017 年 12 月达成和解。
The significance is narrow: an open source licence is enforceable.该裁决并未决定每次集成或单独进程调用都会创建衍生作品。
您的选择
There are three honest routes, and only one of them involves us.
1. 从Artifex购买商业许可证
Artifex sells a commercial licence so companies can use Ghostscript in closed-source products.这是合法的、受支持的路由,当您依赖 Ghostscript 的完整功能集时,它可能是正确的选择。 It resolves the licensing question, though the native dependency remains.
如果出现以下情况,请选择此选项: 您可以使用 Ghostscript 作为完整的 PostScript 或 PDF 解释器或 RIP,包括分色、打印设备、PDF 输入或复杂的 RIP 工作流程。
2.更换元件
如果要求更窄——将 PS、EPS 或 XPS 文件转换为 PDF 或图像——专用的商业库可以覆盖它,而无需相同的许可或本机部署问题。
如果出现以下情况,请选择此选项: your usage is conversion and rendering, and you prefer a Maven dependency to a native binary on every host.
3. 删除该功能
If format conversion is a rarely used convenience, removing it may cost less than either licence.
如果出现以下情况,请选择此选项: the feature is not important enough to justify a commercial licence or a migration.
Aspose.Page 适合什么地方,不适合什么地方
如果您需要以下功能,Aspose.Page 是一个不错的选择:
- Convert PostScript (PS) and EPS files to PDF.
- Convert XPS and OXPS documents to PDF.
- Render any of those formats to PNG, JPEG, TIFF or BMP.
- 合并多个 PS 或 XPS 文档。
- Create and edit XPS documents programmatically.
- Read and write XMP metadata in EPS files.
- Crop, resize and transform EPS files.
- 在闭源商业产品、服务器、容器或托管平台内运行转换,无需安装本机转换器。
Aspose.Page is the wrong tool if you need:
- 具有设备级控制的完整 PostScript 解释器或 RIP。
- PDF files as input — use Aspose.PDF , which is a different product.
- CMYK 分色或印前级打印设备输出。
- Ghostscript 的
pdfwrite蒸馏器行为准确再现。
如果您在第二个列表中,Artifex 商业许可证更适合。其成本将低于无法达到同等水平的迁移。
What a native converter costs you in a container
从 Java 使用 Ghostscript 的每种方式最终都有相同的要求:无论代码在哪里运行,都必须提供本机二进制文件及其共享库。XPS 输入需要同一 GhostPDL 构建中的 `gxps` 二进制文件,因此支持 XPS 会增加第二个本机依赖项,而不是避免本机依赖。
`ghost4j`通过JNA绑定Ghostscript C API,并将其加载到JVM进程中。 `ProcessBuilder` 和 `im4java` 改为 shell,但它们仍然需要二进制文件。 The continuing costs are:
- 生产中的
UnsatisfiedLinkError。 该库可能丢失、为错误的架构构建或链接到不同的 C 运行时。 - 基础镜像锁定。 针对 glibc 构建的 Ghostscript 软件包不能与 Alpine 上的 musl 互换。
- CVE 修补。 Ghostscript 漏洞成为修补和映像重建节奏的一部分。
- Process stability. Because
ghost4jloads Ghostscript in-process, a native crash takes the JVM down rather than producing a Java exception you can catch. - Environment drift. Developer machines, CI runners and production nodes all need compatible native versions. See the technical guide for Docker and serverless deployment .
A pure-Java library removes the native converter from those concerns. You must still configure headless mode and provide the font environment required by your documents.
Ghostscript versus Aspose.Page for Java
- Licence — Ghostscript: AGPL v3, or commercial from Artifex. Aspose.Page: commercial only.
- Source disclosure — Ghostscript: required when the AGPL applies. Aspose.Page: not required.
- Network and SaaS — Ghostscript: network use is within AGPL scope. Aspose.Page: commercial deployment is covered by the purchased licence.
- Implementation — Ghostscript: native C binary. Aspose.Page: pure Java library.
- Java 集成 — Ghostscript:JNA 包装器,例如
ghost4j、直接 JNA 或进程调用。 Aspose.Page:Maven 或 Gradle 依赖项和直接 API。 - Native install — Ghostscript: required on every host. Aspose.Page: no native converter install.
- Deployment — Ghostscript: binary plus shared libraries in every image. Aspose.Page: JAR with the application.
- CVE surface — Ghostscript: its native interpreter and dependencies join your patching scope. Aspose.Page: library updates only.
- Base image — Ghostscript: constrained by compatible native packages and C runtime. Aspose.Page: not constrained by the converter.
- 输入格式 — Ghostscript:PS、EPS、PDF 等;XPS 需要 GhostXPS,它是同一 GhostPDL 源代码树中的独立解释器。Aspose.Page:在一个库中支持 PS、EPS、XPS 和 OXPS。
- 输出和范围 — Ghostscript:PDF 加上许多光栅和打印设备作为完整的解释器和 RIP。 Aspose.Page:PDF、PNG、JPEG、TIFF 和 BMP 用于转换、渲染和文档操作。
- Pricing — Ghostscript: commercial pricing is quoted by Artifex. Aspose.Page: published tiers from US$599.
迁移
PostScript or EPS to PDF
Java 转换替换 `gs` pdfwrite 命令
import com.aspose.eps.PsDocument;
import com.aspose.eps.device.PdfSaveOptions;
PsDocument document = new PsDocument("input.ps");
PdfSaveOptions options = new PdfSaveOptions(true);
options.setAdditionalFontsFolders(new String[] { "/opt/fonts" });
document.saveAsPdf("output.pdf", options);
for (Exception ex : options.getExceptions())
{
System.out.println(ex.getMessage());
}
// Recoverable conversion problems remain available for logging.替换:`gs -sDEVICE=pdfwrite -o output.pdf input.ps`
PostScript 或 EPS 到图像
Java 转换替换 `gs` png16m 命令
import java.nio.file.Files;
import java.nio.file.Path;
import com.aspose.eps.PsDocument;
import com.aspose.eps.device.ImageSaveOptions;
PsDocument document = new PsDocument("input.ps");
ImageSaveOptions options = new ImageSaveOptions();
byte[][] imagesBytes = document.saveAsImagesBytes(options);
for (int i = 0; i < imagesBytes.length; i++)
{
Files.write(Path.of("page_" + i + ".png"), imagesBytes[i]);
}
for (Exception ex : options.getExceptions())
{
System.out.println(ex.getMessage());
}
// The default output format is PNG; one byte array is returned per page.替换:`gs -sDEVICE=png16m -o page_%d.png input.ps`
XPS 至 PDF
Java XPS 到 PDF 转换
import com.aspose.xps.XpsDocument;
import com.aspose.xps.rendering.PdfSaveOptions;
XpsDocument document = new XpsDocument("input.xps");
PdfSaveOptions options = new PdfSaveOptions();
document.saveAsPdf("output.pdf", options);
// gs does not read XPS; the Artifex equivalent is gxps.`gs` 不读取 XPS。Artifex 中对应的是 GhostPDL 的 `gxps`,采用相同的双重许可。
您需要哪个许可证?
这些公布的价格于 2026 年 10 月 26 日进行了检查。请在 [Aspose.Page for Java 定价页面](https://purchase.aspose.com/pricing/page/java) 上确认当前定价。
- 内部工具,一名开发人员和一个部署位置: Developer Small Business — US$599。
- 嵌入分发给客户的产品或公共 Web 应用程序中: Developer OEM — US$1,797。
- 作为您销售的 SDK 或 API 的一部分进行分发: Developer SDK — US$11,980。
- 团队或更广泛的组织部署: 站点许可证可用;请参阅定价页面。
对于商业产品或公共 Web 应用程序内提供的 Ghostscript 替代品,Developer OEM 通常是正确的层。它涵盖一名开发人员、无限的部署位置和外部分发。
永久许可证包括一年的更新,并可享受折扣续订。
在提交之前尝试一下
未经许可的评估输出带有水印。 30 天免费临时许可证消除了评估限制,因此您可以在购买之前测试自己的文件。
带上您最困难的 PostScript 文件。如果转换不正确,最好在评估时发现,而不是购买后发现。