Search code examples
javascriptpythonpdfacrobatacrobat-sdk

Acrobat JavaScript - convert JavaScript page links to "real links"


The situation:
I have ~1,000,000 PDF files. I am using Acrobat JavsScript to search for certain keywords in each of the PDFs, and then give the keyword a link by setAction("this.pageNum = n"). The pageNum value, n, is generated by my script, too. The result is that the user can go to page number n directly by clicking the link.

The problem:
I do not want the links to trigger JavaScript actions. Instead, I want to them to be "real links". Each of the "real link" should point to the same page number as the JavaScript action does. The reason is that I want users to be able to use the links with a PDF reader that does not allow JavaScript (e.g. SumatraPDF or Chrome browser).

  • It would be ideal if the solution is implemented in Acrobat JavaScript, so that I can integrate into my script. If not possible,
  • It would also be great if the solution can be implemented in Python, since the problem is part of a larger Python application I am developing.
  • If still not possible, a solution in any programming language will suffice.

What I have tried:
I have looked up the entire "JavaScript for Acrobat API Reference". The Link object does not have a "go to page reference" property (unlike, using HTML as an analogy, the "a" tag has an "href" property). It seems to me that the Link object only allows setAction() method - but please correct me if I am wrong.

Similar question? Someone has asked a similar question, but both the question and answer was rather vague (no offense, please), so I'm asking again. Convert javascript links in PDF to real annotations


Solution

  • At the end I used a script from this site:

    http://try67.blogspot.de/2011/09/convert-javascript-links-to-real-web.html

    Its a java tool which does exactly that - if you need a quick solution.

    It seems that JAVA will be the approach to interpret the javascript inside the PDF. Pythons PDF does