【发布时间】:2011-04-18 15:39:13
【问题描述】:
我正在尝试用 Java 编写一个 PDF 文件来说出 hello neckbeards 的字样,但是当我运行我的程序时,Adobe Reader 会打开但出现错误提示:
There was an error opening this document.
The file is already open or in use by another application.
这是我的代码:
import java.awt.Desktop;
import java.io.*;
public class count10 {
public static void main(String[] args) throws Exception {
File tempfile = File.createTempFile("report", ".pdf");
FileWriter pfile = new FileWriter(tempfile);
pfile.write("hello neckbeards");
Desktop dtop = null;
if (Desktop.isDesktopSupported()) {
dtop = Desktop.getDesktop();
}
if (dtop.isSupported(Desktop.Action.OPEN)){
String path = tempfile.getPath();
dtop.open(new File(path));
}
}
}
【问题讨论】:
-
正如下面的几个人所提到的,iText 是构建 pdf 文件的好方法。请在进行任何重大开发之前查看 iText 的许可。
-
哇。这不会是家庭作业吧?
-
@neckbeard691) 如果这是家庭作业,请用homework标记。 2) 当您找到解决您的问题的答案时,请通过检查其绿色勾号接受它,靠近投票区。谢谢!
标签: java pdf io pdf-generation