0

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

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

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

4

1 回答 1

3

如果您使用的是 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);
            }
于 2013-04-12T09:37:09.977 回答