I'm embedding an external file in my pdf with \usepackage{attachfile2} and\textattachfile[color=1 1 1]{description}{file.pdf}. How can I make the text look the same as it would if I had used the hyperref package and done something like \hyperref{file.pdf}{description}? (By look the same, I mean black text, cyan border that disappears on printing, hand icon on mouse over, name of file in a box on hover (at least in acrobat/reader).)
- 2,135
-
Similar question: https://tex.stackexchange.com/q/19025/9075 – koppor Feb 26 '18 at 08:35
-
Related: How do I make an attached non-pdf file display like a link? – koppor Mar 05 '18 at 18:40
1 Answers
I'd replace attachfile2 with a combination of embedfile and hypgotoe:
Instead of \textattachfile[color=0 0 0]{file.pdf}{description}, you'll have to use \embedfile{file.pdf}. This command does not create any visible entry, it just adds the file to the resulting PDF file (and Adobe Reader's attachment tab), so you can use the macro anywhere in your document.
In order to produce the clickable link, use the extended functionality of hypgotoe's \href command: To make "description" a link to the embedded file.pdf, the correct syntax is
\href{gotoe:embedded=file.pdf}{description}
(More information can be found in the hypgotoe manual.) The appearance of the links can be controlled with \hypersetup using the keys gotoecolor and gotoebordercolor.
A minimal example:
\documentclass{article}
\usepackage{embedfile}
\usepackage{hypgotoe}
\embedfile{file.pdf}
\begin{document}
\href{gotoe:embedded=file.pdf}{description}
\end{document}
Note that this solution only works with pdf(la)tex and only for embedded PDF files.
- 25,784
-
The problem with this solution is that it requires you to provide the file names you are embedding in two locations. – vy32 Sep 03 '11 at 15:11
-
2@vy32 You can avoid specifying the file name twice by creating a new macro for this purpose:
\newcommand*{\embedfileandcreatelink}[2]{\embedfile{#1}\href{gotoe:embedded=#1}{#2}}Use it like\embedfileandcreatelink{file.pdf}{description}– diabonas Sep 06 '11 at 16:17 -
-
3@vy32 You can safely use
\embedfileanywhere in your document. The list of embedded files the PDF file contains is written at the very end of the document. – diabonas Sep 07 '11 at 09:57 -
2
-
@JasonGross Not with the GoToE links used in this answer, I'm afraid. There might be a solution using JavaScript, even though this will probably work only in Adobe Reader/Acrobat (not sure whether GoToE links are supported by more PDF viewers, though). I guess this would warrant a new question. – diabonas Feb 28 '15 at 05:35
-
-
At least for evince 13.8.2 and okular 0.24.2 on Ubuntu Linux 16.04.5 I can report that these links will not trigger any action. – math Aug 20 '18 at 14:41
-
@math Yes, unfortunately Poppler, the PDF library used by these programs, does not support GoToE links. Generally, many of these interactive PDF features only work with Adobe Acrobat Reader. – diabonas Aug 20 '18 at 14:47
-
This works with Adobe Reader. However I could not make it work with Edge. – Maesumi Sep 11 '22 at 03:14