我正在尝试通过org.apache.pdfbox.multipdf.Splitter
拆分pdf文档,并且需要在此单页PDDocument
上执行某些文件操作,
如何将 PDDocument
转换为 Java 中的文件对象?
最佳答案
非常简单。我使用的是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;
}
关于java - 我需要将 PDDocument 转换为文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39202300/