如何使用 PDFBox 从 PDF 文档中读取特定页面(给定页码)?
原文由 missingfaktor 发布,翻译遵循 CC BY-SA 4.0 许可协议
如何使用 PDFBox 从 PDF 文档中读取特定页面(给定页码)?
原文由 missingfaktor 发布,翻译遵循 CC BY-SA 4.0 许可协议
//Using PDFBox library available from http://pdfbox.apache.org/
//Writes pdf document of specific pages as a new pdf file
//Reads in pdf document
PDDocument pdDoc = PDDocument.load(file);
//Creates a new pdf document
PDDocument document = null;
//Adds specific page "i" where "i" is the page number and then saves the new pdf document
try {
document = new PDDocument();
document.addPage((PDPage) pdDoc.getDocumentCatalog().getAllPages().get(i));
document.save("file path"+"new document title"+".pdf");
document.close();
}catch(Exception e){}
原文由 Raymond C Borges Hink 发布,翻译遵循 CC BY-SA 3.0 许可协议
8 回答6.6k 阅读
4 回答715 阅读✓ 已解决
2 回答3.4k 阅读
3 回答1.9k 阅读✓ 已解决
1 回答2.2k 阅读✓ 已解决
1 回答2.1k 阅读✓ 已解决
1 回答785 阅读✓ 已解决
这应该有效:
如 本教程的书签部分 所示
2015 年更新,版本 2.0.0 快照
似乎这已被删除并放回原处(?)。 getPage 在 2.0.0 javadoc 中。使用它:
getAllPages 方法已重命名为 getPages