# How to preserve hyperlinks in included pdf?

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.

-

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.

-
although using a Java from PAX is far from ideal I will mark this as accepted answer until a better option appears. – alfC Apr 5 '11 at 7:36
For an example on how to use `pax`, see Embedding a pdf file with clickable external links into a LaTeX document – diabonas Feb 16 '12 at 14:37

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.

-

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
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