常见问题 — Aspose.PDF FOSS for Java

常见问题 — Aspose.PDF FOSS for Java

常见问题

需要哪个 Java 版本?

Aspose.PDF FOSS for Java 需要 Java 11 或更高版本。建议在生产环境中使用 JDK LTS 发行版(11、17、21)。

该库可以免费使用吗?

是的。Aspose.PDF FOSS for Java 使用 MIT 许可证。无需商业协议、API 密钥或激活。

如何将该库添加到 Maven 项目中?

将以下内容添加到你的 pom.xml:

<dependency>
  <groupId>org.aspose</groupId>
  <artifactId>aspose-pdf-foss</artifactId>
  <version>26.8.0</version>
</dependency>

我该如何创建一个新的 PDF 文档?

使用 Document 类且不带参数:

try (Document doc = new Document()) {
    doc.getPages().add();
    doc.save("output.pdf");
}

我该如何获取现有文档的页数?

打开文档并在 pages 集合上调用 size():

try (Document doc = new Document("input.pdf")) {
    int count = doc.getPages().size();
}

我该如何合并两个 PDF 文件?

使用 PdfFileEditor.concatenate():

PdfFileEditor editor = new PdfFileEditor();
editor.concatenate("first.pdf", "second.pdf", "merged.pdf");

我该如何加密 PDF?

使用 facades 包中的 PdfFileSecurity 与 DocumentPrivilege 和 KeySize:

try (PdfFileSecurity security = new PdfFileSecurity("input.pdf", "secured.pdf")) {
    DocumentPrivilege priv = DocumentPrivilege.getForbidAll();
    priv.setAllowPrint(true);
    security.encryptFile("user", "owner", priv, KeySize.x256);
}

我该如何对数据应用 AES 加密?

使用 AESCipher 的静态方法进行原始字节级 AES 加密和解密:

byte[] ciphertext = AESCipher.encrypt(key, plaintext);
byte[] decrypted  = AESCipher.decrypt(key, ciphertext);

源代码在哪里?

源代码和问题追踪器可在 https://github.com/aspose-pdf-foss/Aspose.PDF-FOSS-for-Java 获取。

另请参阅

 中文