Friday, July 2, 2010

Quickly apply “Inherit Zoom” to all bookmarks in a PDF file

I often compile PDF reports totaling 1,000 to 2,000 pages, and am always creating hierarchical bookmarks for these files. One of my beefs is that often, clicking a bookmark will change the magnification setting to “fit width” from whatever you had it set at. Ideally, clicking a bookmark should default to just leaving the zoom level at whatever the reader is currently set to use (“Inherit zoom”). I’ve found no way in Acrobat to set the default behaviour for newly-created bookmarks, and changing these links one at a time in Acrobat is extremely tedious.

Thankfully, there is a solution provided by Martin Backschat:

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.

I don’t have UltraEdit but I was able to make this work using Notepad++. The exact search/replace text was slightly different for my PDF files (note the added space) but the principle is the same:

  1. In Notead++, click the TextFX menu, then TextFX QuickFind/Replace (the standard find/replace tool will not help you here). Make sure you check the “Regular Expr” check box on the right.
  2. Use "R /XYZ(.*)]" (without quotes) as your search string and "R XYZ]" as your replace string and replace all instances.
  3. Do it again using "R /Fit(.*)]" as your search string and the same replace string as above.


Rob said...

Hey I tried this using Notepad++ on a pdf that has a bunch of bookmarks with different zoom levels. The find/replace didn't find any matches to the strings.

Rob said...

This was using the TextFX find/replace. Any suggestions to get it to work? It would be great if I could get it to work

Shane said...

Thanks for the tip. For the folks running into trouble with Notepad++, just remove the space between the "R" and "/" in "R /XYZ(.*)]", it should be "R/XYZ(.*)]" same thing applies to the repalcement text.

Joshua said...

I couldn't get it to work using Notepad++, but came up with another solution using JPDFBookmarks...

Daniel Kraus said...

I wrote a small java application which is based on the PDF Clown library. It allows you to easily apply various bookmark configurations, such as 'Inherit zoom', to multiple PDF files within a desired directory.

This is my first public project and due to the fact that I'm taking my exams in the next couple of weeks, I'm running out of time. But afterwards, which should be in mid-February, I'll keep on developing.

In the meantime, feel free to use the application and give some feedback.

Werner Heckel said...

Thanks Daniel. Your tool was a great help.

N. Jones said...


Thanks for the java app. It works like a charm! Great time-saver too.

SergioUrra said...

@Joshua, thanks a lot. I did use JPDFBookmarks. Really nice app.

Jonnie Tyler said...

Thank you Daniel!