[英]PDFBox does not remove first page
I am trying to remove the first page of every PDF document in a folder. 我正在尝试删除文件夹中每个PDF文档的首页。
My code: 我的代码:
File folder = new File("//home//linux//Desktop//f");
File[] fileParts = folder.listFiles();
PDDocument document = null;
for (File pdf : fileParts) {
try {
document = PDDocument.load(pdf, "");
if (document.isEncrypted()) {
document.setAllSecurityToBeRemoved(true);
System.out.println("decrypted");
}
document.removePage(0);
document.save(pdf.getName());
document.close();
} catch (Exception e) {
System.out.println("error: " + e.getMessage() + "\n" + e);
}
}
The code does not show any error or problem, but it does not remove the first page. 该代码不显示任何错误或问题,但不会删除第一页。 Is there something I am missing?
我有什么想念的吗?
Change this line 更改此行
document.save(pdf.getName());
to this: 对此:
document.save(pdf.getAbsolutePath());
Reason: your current code saved the PDF in the current directory of your application, not in //home//linux//Desktop//f
. 原因:您当前的代码将PDF保存在应用程序的当前目录中,而不是
//home//linux//Desktop//f
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.