我正在尝试通过org.apache.pdfbox.multipdf.Splitter
拆分pdf文档,并且需要在此单个页面PDDocument
上执行某些文件操作,
如何在Java中将PDDocument
转换为File Object?
最佳答案
很简单。我正在使用1.8.16
try {
PDDocument document = PDDocument.load(new File(filename));
// do what ever you want
document.save(newfilename);
} catch (IOException | BadSecurityHandlerException | CryptographyException e) {
e.printStackTrace();
}
finally {
if(document != null )
try {
document.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//return tmpFile != null ? tmpFile.getAbsolutePath() : null;
return tmpFilename;
}