gpt4 book ai didi

java - 写入 PDF 文档后使用 iText 打开它们

转载 作者:行者123 更新时间:2023-12-01 23:53:42 26 4
gpt4 key购买 nike

我在 JFrame 中使用 iText 和 Document 类来编写 PDF,但如果我尝试在创建后使用 Runtime 类来运行它,我会收到一个异常,因为锁仍然在其上,并且如果我运行,我将无法打开它解锁它,我的 JFrame 上面有一个锁定 token 。如果我想写入 PDF,如何打开它?

Document d = new Document();
.... code
d.close();
Runtime.getRuntime().exec("D:/PDFChartStuff.pdf");

为什么这篇文章不符合 stackoverflow 的“质量标准”?

最佳答案

如果您使用的是 Windows,则可以使用 rundll32 启动 pdf 文件。

尝试这样的事情

String pdfFile="D:/PDFChartStuff.pdf";
if (pdfFile.toString().endsWith(".pdf")) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + pdfFile);
} else {
//For cross platform use
Desktop desktop = Desktop.getDesktop();
desktop.open(pdfFile);
}

关于java - 写入 PDF 文档后使用 iText 打开它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15956650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com