Reading and writing the TOC for a PDF

元气小坏坏 提交于 2020-02-05 08:54:12

问题


My requirement is to prefix a PDF generated by some other process with a single 'cover page'.

I've written a relatively simple Ant task to concatenate a list of PDF documents, and this works well, but the TOC is not preserved in the process. By TOC I mean ..

Ideally, both TOCs would be preserved, and adjusted for their new offsets, but I can see no means of reading or writing the TOC (the left hand one) in the iText API. Can anyone?

M.


回答1:


I'm the author of the book about iText and in the context of this book, I've written an example that explains how to concatenate PDFs while preserving the bookmarks (aka the outline tree). You can find this example here. As you can see, you need the SimpleBookmark object to extract the bookmarks from the existing documents. Make sure that you shift the page numbers, or your links will point at the wrong pages. Finally add the new ArrayList<HashMap<String, Object>> to the PdfCopy object using the setOutlines() method.

Once again, we've found proof that reading documentation saves time ;-)



来源:https://stackoverflow.com/questions/15759406/reading-and-writing-the-toc-for-a-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!