使用 PDFBox 从 PDF 文档中读取特定页面

新手上路,请多包涵

如何使用 PDFBox 从 PDF 文档中读取特定页面(给定页码)?

原文由 missingfaktor 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 982
2 个回答

这应该有效:

 PDPage firstPage = (PDPage)doc.getAllPages().get( 0 );

本教程的书签部分 所示

2015 年更新,版本 2.0.0 快照

似乎这已被删除并放回原处(?)。 getPage 在 2.0.0 javadoc 中。使用它:

 PDDocument document = PDDocument.load(new File(filename));
PDPage doc = document.getPage(0);

getAllPages 方法已重命名为 getPages

 PDPage page = (PDPage)doc.getPages().get( 0 );

原文由 Nicolas Modrzyk 发布,翻译遵循 CC BY-SA 3.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 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题