cp bookmakes to another pdf file

其实这事不好。

看电子书的时候,有的没有Bookmake书签,或者叫目录也成。这样读起来就非常疲劳,经常一恍惚就根本不知道读到哪里了,上下文都弄不清怎么办。这种问题尤其对于一本1500页的电子书来说更严重。想办法自己加书签吧,reader根本不提供这个功能。这能自立更生了。

对于apress的电子书(我在写这些的时候内心很痛苦,作为一个第三世界的民工,这个出版社的书我一直是看电子版),如果电子书没有书签,可以从apress的官方网站上下载目录,这个目录恰好就包含书签。这样的话只要把这个书签拷贝到我们之前的电子书里就可以了。

于是需要一个能够读写pdf文件的库,我找到一个pdfbox,它现在是apache incubator中的一个项目,貌似签到apache之后还没有一个正式的release。上一个release可以在sourceforge上项目原来的页面找到,版本号我不记得了。

最近比较怀旧直接用Java写。其实很简单,pdfbox都已经建模了,只要取出来、放进去、写下来(ZB一些应该是get出来,set进去,write下来)就可以了。以下是个sample

[codesyntax lang="java" lines="fancy"]
public class Main {

/**
* @param args
*/
public static void main(String[] args) throws Exception{

FileInputStream ctfile = new FileInputStream(“E:\\cs_content.pdf”);
PDFParser parser = new PDFParser(ctfile);
parser.parse();
PDDocument ctpdf = parser.getPDDocument();

PDDocument rlpdf = PDDocument.load(“E:\\cs.pdf”);

PDDocumentOutline outline = ctpdf.getDocumentCatalog().getDocumentOutline();
rlpdf.getDocumentCatalog().setDocumentOutline(outline);

FileOutputStream out = new FileOutputStream(“E:\\cs_out.pdf”);
COSWriter writer = new COSWriter(out);
writer.write(rlpdf);
writer.close();
}
}
[/codesyntax]

非常简单,就不解释了。只是有一个小小的问题(其实相当严重),Apress的目录文件里bookmark是没有设置destination的(这也是ZB的说法,其实就是点了没反应)。我想了一下如果要让书签真正起到作用要去读pdf的目录页面,那里面有页码,虽然这个页码和pdf的页码有时候会有一个固定的偏移。不过读pdf似乎有那么一点麻烦,因为里面有不少控制字符。

暂时就是这样。不知道有没有其他什么更好的办法。

This entry was written by Sunng , posted on Wednesday March 25 2009at 12:03 pm , filed under 把戏 and tagged , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

7 Responses to “cp bookmakes to another pdf file”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word