PDF Bookmark Hacks

Update note: Here’s a more recent blog posting on PDF hacks. All scripts, including the ones mentioned above, are contained in the ZIP archive with perl scripts

I found out that you can do – quite simply – two very useful hacks on PDF documents with bookmarks:

Apply “Inherit Zoom” to all Bookmarks

I like to see, by default, the whole page, and set this accordingly in my Acrobat preferences. Some bookmark links, when clicked, modify the current zoom settings, e.g. put you in 100% or worse, in 200%. To modify this annoyance you can directly modify the PDF document in your Text editor.

With UltraEdit, for example, I load the PDF document and open the “Search and Replace” box, enable “Regular Expressions” and replace all occurrences of “R/XYZ*]” with “R/XYZ]”, and then also all occurrences of “R/Fit*]” with “R/XYZ]”. Now safe the document.

With the Perl scripting language, this hack is applied with

perl -pe 's#R/(XYZ.*?|Fit.*?)\]#R/XYZ\]#g#' in.pdf >out.pdf

The next time you open the modified document with Acrobat you will get a message that the document is being repaired. Just safe it again with Acrobat and everything is fine.

Close all Bookmark Folders (recursively, nested)

Unfortunately, PDF documents with a huge folder hierarchy of bookmarks have all folders opened. This creates a large list and I cannot find anything at glance. How can I close all folders, also the nested ones? To modify this annoyance you can directly modify the PDF document in your Text editor.

With Search and Replace, for example, I specify the PDF document, enable “Regular Expressions” and replace all occurrences of “\/Count +[0-9]\/Parent” with “/Count -%1/Parent”.

With Perl, this hack is applied with

perl -pe 's#/Count ([0-9]+)/Parent#/Count -$1/Parent#g#' in.pdf >out.pdf

The next time you open the modified document with Acrobat you will get a message that the document is being repaired. Just safe it again with Acrobat and everything is fine.

Note: Always make a backup of your PDF document before modifying it, since sometimes the hacks just don’t work and you end up with a document that Acrobat cannot repair.

7 Comments »

  1. Stephen said

    Hi, I just tried the perl command to change all bookmarks to “Inherit Zoom”. Did it with terminal on Mac OS X. The resulting document works in Adobe Acrobat nicely, but none of the bookmarks work in Mac OS X’s Preview application. Too bad.😦

    I cannot believe Adobe still does not have a way to be able to set a default bookmark to INherit Zoom so that you can then add several hundred to a document and they will all be set that way.

  2. gen said

    I don´t understand how i can do that. I don´t know how to program in perl.

    You could tell me how i can do with a simple pdf document.

    PLEASE.

    Thanks.

  3. sdgsdfg sdfasdf said

    What kind of regular expressions are those? I’ve tried UltraEdit but no success.
    Also I’ve installed ActivePerl (Windows XP) but something seems to go wrong. I’ve changed the delimiter ‘ into ”

    perl -pe “s#R/(XYZ.*?|Fit.*?)\]#R/XYZ\]#g#” mod.pdf >out.pdf

    this will run but the pdf is corrupt / incomplete. Reader 7 throws a few errors. I don’t have Acrobat.

    Too bad!

    Regards

    PS: you probably meant “save” instead of “safe”.

  4. maba said

    This blog posting is quite outdated. Have look at the update note; it refers to a more recent and working hack.

  5. reid said

    any ideas on how to apply “Inherit Zoom” to Named Destinations?

  6. ax said

    you might move the update note to the top of your post so people don’t try the outdated stuff first before seing it.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: