47

I have generated PDFs with figures that have hyperlinks (hyperref to websites, \href) in them. When I compile these figures standalone the hyperlinks work. But when I try to include these PDFs (as figures, not the sources) with \includegraphics the links are lost and only the image is inserted in the document.

Is there a way to include (\includegraphics?) a PDF such that its original links work in the master document?

This question has to do with the externalization (e.g. TikZ or PGFPlots), which also suffers from these drawbacks, i.e. hyper-references are lost.

  • @ diabonas: I saw your solution when I searched "preserving hyperlinks in compiling to Android": tex.stackexchange.com/questions/14620/… Following your "how to use pax" I got stymied following your solution at: > Run pdfannotextractor.pl --install. This downloads and installs > PDFBox, a Java library necessary for using pax. While I can "open" the .pl file and read the code using Notepad++, I can't run it in order to install PDFBox. I read elsewhere that in order to do this requires a webserver CGI script - see file.org/extension/pl# I'm a – user2883866 Oct 18 '13 at 17:09
  • 1
    @alfC Please look at this : tex.stackexchange.com/a/423471 – AlexG Mar 28 '18 at 14:09
25

You can not simply mix two PDF files. You have to preserve PDF document structure. In the simply case links (PDF annotations) are dropped.

You can try the PAX project, which trys to extract and reinsert the PDF annotations.

14

It seems that pdftex always drops all PDF annotations (which includes hyperlinks) from the included file.

The PDF format itself makes it rather difficult to do otherwise. PDF annotations are laid out in a completely different way to how the rest of the content of the page is constructed. They live on a different layer and they are positioned using a different (page-absolute) coordinate system.

  • 4
    Difficult doesn't mean impossible. Plenty of pro PDF tools do it (Acrobat Pro being one of them), so it's sad (pdf)latex doesn't include that feature… – F'x Mar 22 '14 at 20:55
10

It works with luatex. However, it is not considered to be stable. Here a context example:

\setupinteraction [state=start]

\starttext

  \startbuffer [internal]
    \setupinteraction [state=start]
    \starttext
      \useURL [aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]
      \from [aurl]
    \stoptext
  \stopbuffer

  \savebuffer [internal]
  \executesystemcommand {context --purgeall \jobname-internal.tmp}

  \externalfigure [\jobname-internal] [scale=500, interaction=yes]

\stoptext

Explanation:

  • The buffer contains the code for a PDF file with a hyperlink.
  • The \savebuffer writes the content of the buffer internal in an external file.
  • \executesystemcommand runs context on this file to create the PDF file containing the link.
  • Eventually the externalfigure command includes the just created PDF in the current document.

Tested with luatex beta-0.70.1-2011051923 and context 2011.11.04 14:15

  • I am not familiar with LuaTeX but I will try to give it a try, Is this exploiting the fact that the PDF is generated inside the same document? also, Is there a fundamental reason why this can't be translated into LaTeX? – alfC Nov 7 '11 at 6:28
  • 3
    No, it has nothing to do with the fact that the internal PDF is generated on the fly. I used it in the example to make sure that the embedded file contains a file with a valid hyperlink. The functionality could be make available within a LaTeX package. No one felt like writing a package for this, yet. I don't use LaTeX, that's why I can't help you with a LaTeX hack. – Marco Nov 7 '11 at 8:02
  • As of 2017-01-05 it does not work with lualatex 1.0.0 and pdfpages 2016/12/11 v0.5g. – koppor Jan 5 '17 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.