Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:

I've been scouring the net looking for good, open-source tools that I could use on Linux to set bookmarks in some PDFs that I have (I don't have the source to the PDFs). These are PDFs to which I refer often, so having some good bookmarks would be a real plus. I knew there were some PDF manipulation perl modules, but was hoping for something pre-built. Thus far, no such luck. If you know of such tool, please only /msg me in the chatterbox or something, because that is definitely off-topic here. I only provide this as background.

Having given up on that, I turned to CPAN and Perlmonks. Two modules jump out: PDF::API2 and PDF::Reuse. Of the two, it's PDF::Reuse that seems far simpler. I started down that road, and actually produced a PDF with bookmarks. However, it uses JavaScript in its bookmarks, which may work fine with Acrobat Reader, but do not work very well with Xpdf. So, the basic question is - has anyone managed to get PDF::Reuse to create non-JavaScript bookmarks? For the inevitable, "what have you tried" (well, maybe not inevitable, since I seem to often be the one asking ;-}) here's the code:

#!/usr/bin/perl use strict; use warnings; my %opts; use Getopt::Long; GetOptions(\%opts, 's|src=s', 'd|dst=s', 'o|outline=s', ); use PDF::Reuse; prFile($opts{d}); prDoc($opts{'s'}); prBookmark([ { text => 'TOC', act => '4, 0, 0', } ]); prEnd();
The bookmark I'm setting actually exists - page 4. But when I click on it, I get "Error: Unknown link action type: 'JavaScript'" since xpdf probably doesn't support JavaScript.

Note that for those who are going to suggest trying PDF::API2, I've also largely given up on PDF::Reuse, and have gotten to the same point (a hardcoded bookmark in a copy of the PDF), although with way more code. Well, way more code that I have to write - probably similar amounts of code to the CPU :-) I was just looking to see if there was something obvious I've been missing.

PS: Props to holli. It's his merging pdf-files: pdf-merger.pl node that has gotten me this far. PDF::API2 is underdocumented, and I've been using holli's code to get this far.

Replies are listed 'Best First'.
Re: Non-JS PDF bookmarks with PDF::Reuse
by idsfa (Vicar) on Mar 30, 2006 at 01:53 UTC
Re: Non-JS PDF bookmarks with PDF::Reuse
by aquarium (Curate) on Mar 30, 2006 at 03:02 UTC
    this isn't perl but, it may give you what you want (bookmarking)...use pdf2html to convert your docs to html...then you're free to use insert placeholders and create bookmarks with a browser
    the hardest line to type correctly is: stty erase ^H