问题描述
我在写与Apache PDFBox的一个简单的Java应用程序。
我有几个,其中PDF文件的最后一页是在previous网页内容的索引。
I'm writing a simple Java Application with Apache PDFBox.I have a several PDFs where the last page is the index of the content in the previous pages.
我需要指数(最后一页)成为PDF文件的第一页。
I need the index (last page) became the first page of the PDF file.
这可能吗?
我还发现,听起来比Apache PDFBox的更好库,但在这种情况下,我不知道如果我能做到我需要的东西要么
I've also discovered the http://itextpdf.com/ library that sound better than Apache PDFBox, but in this case i don't know if i can do the thing i need either
也许我可以用这一点:的
Or maybe i can use this: http://saaspose.com/docs/display/pdf/How+to+Move+Page+within+a+Pdf+Document+%28Java+SDK%29
推荐答案
通过PDFBox的,你可以打开原始PDF成PDDocument,然后使用getDocumentCatalog()。getAllPages()获得的页面的列表。重新排列你想要的顺序列表,每个页面写出到新文档。
With PDFBox you can open the original PDF into a PDDocument, then use getDocumentCatalog().getAllPages() to get a list of of the pages. Rearrange the list in the order you want, and write out each page to the new documents.
PDDocument newDoc = new PDDocument();
PDDocument oldDoc = PDDocument.load (args[0]);
List allPages = oldDoc.getDocumentCatalog().getAllPages();
// Code to rearrange the list goes here
for ( int curPageCnt = 0; curPageCnt < allPages.size(); curPageCnt++ )
{
newDoc.addPage( ( PDPage )allPages.get ( curPageCnt ) );
} // end for
这篇关于阿帕奇PDFBox的:将最后一页第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!