读写PDF的TOC [英] Reading and writing the TOC for a PDF

查看:173
本文介绍了读写PDF的TOC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是将由其他过程生成的PDF加上一个封面"作为前缀.

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

我编写了一个相对简单的Ant任务来连接PDF文档列表,这很好用,但是在过程中未保留TOC.通过TOC,我的意思是..

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 ..

理想情况下,两个TOC都将保留并针对它们的新偏移量进行调整,但是我看不到在iText API中读写TOC(左手)的方法.有人可以吗?

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.

推荐答案

我是关于iText的书的作者此处找到此示例.如您所见,您需要SimpleBookmark对象从现有文档中提取书签.请确保您移动页码,否则您的链接将指向错误的页面.最后,使用setOutlines()方法将新的ArrayList<HashMap<String, Object>>添加到PdfCopy对象.

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 ;-)

这篇关于读写PDF的TOC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆