3
votes

I have a PDF document to which I want to add internal hyperlinks. Specifically, page 1 contains a table of contents which I want to make clickable. My idea is to create rectangular boxes in predetermined locations on page 1, which should link to pages 2, 3, ...

I found this post which talks about adding internal hyperlinks using the method I described above. http://bugs.ghostscript.com/show_bug.cgi?id=691531

However, when I try to use this technique in my file, the script just ADDS pages with the rectangle and hyperlink. I need it to overlay the hyperlink on the existing contents of my first page.

3

3 Answers

3
votes

You can do this with Ghostscript, using the pdfmark operator.

For some introduction to the pdfmark topic, see also Thomas Merz's PDFmark Primer.

For an example to achieve a similar thing, see this answer: Merge PDF's with PDFTK with Bookmarks?

Alternatively, you could...

  1. ...use qpdf to expand all (compressed) internal PDFstreams into ASCII,
  2. ...edit the PDF source code (using the knowhow acquired from the PDFmark Primer),
  3. ...use qpdf again to re-compress the PDF streams.
2
votes

This is what I used:

Ghostscript function call from MATLAB:

-o output.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress original.pdf script.ps

Postscript code saved in script.ps:

[ /Rect [10 10 50 50]
/Page 2
/SrcPg 1
/Subtype /Link
/ANN pdfmark
0
votes

There is currently (as of 2020) a piece of freeware for Windows that allows adding hyperlinks. PDF X-Change Editor, which has a free demo version, allows manually drawing hyperlinks on the page (arbitrary rectangles) and setting the target location (page). It is offered at no cost but it is not "free as in libre" software.