Convert the zoom level of all links in a PDF

I have a PDF document. The document consists of several chapters, sections, etc. The text contains links to other chapters or sections; eg:

  • In chapter 15 we will see that ...
  • The term ... referred to in section 7.1, ...

Links are β€œlinks”; that is, when you click on them, it goes to the corresponding text.

However, the links change the PDF zoom level to "Fit Page", as shown in the following dialog box (photo taken in Adobe Acrobat):

link properties

I do not like this behavior and prefer that the zoom level does not change. To do this, there is the option "Inherit scale".

The problem is that there are too many links in the document to change them manually. Therefore, I want to somehow programmatically change the zoom level of all links in the PDF to "Inherit Scale".

Is it possible to use iText or similar libraries?

+4
source share
2 answers

You can try the Docotic.Pdf Library for this. To complete your task, follow these steps:

  • List the actions somehow.
  • Reset the level of scaling of actions to 0 (this means that the scaling remains unchanged)

The Reset zoom function is common and might look something like this:

private static void resetActionZoom(PdfAction action) { PdfGoToAction goToAction = action as PdfGoToAction; if (goToAction == null) return; // process only actions with FitPage zoom level if (goToAction.View.Zoom != PdfZoom.FitPage) return; goToAction.View.SetZoom(0); // now zoom will remain unchanged after click by link } 

Here is an example that lists all the actions in a PDF document and reset the zoom level for each:

 PdfDocument pdf = new PdfDocument("path_to_your_file.pdf"); foreach (PdfAction action in pdf.Actions) resetActionZoom(action); pdf.Save("UpdateAllActions.pdf"); 

Another (and more accurate) way is to list all the links on each page and update related actions in the same way:

 PdfDocument pdf = new PdfDocument("path_to_your_file.pdf"); foreach (PdfPage page in pdf.Pages) { foreach (PdfWidget widget in page.Widgets) { PdfActionArea actionArea = widget as PdfActionArea; if (actionArea == null) continue; resetActionZoom(actionArea.Action); } } pdf.Save("UpdatePageLinks.pdf"); 
+4
source

Foxit Reader Settings / Display the page check "Prohibit changing the current zoom factor at run time" Go to destination actions (these actions can be started from bookmarks) "

0
source

All Articles