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


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


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


Note that this solution only works with pdf(la)tex and only for embedded PDF files.

  • The problem with this solution is that it requires you to provide the file names you are embedding in two locations. – vy32 Sep 3 '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 6 '11 at 16:17
  • I thought that \embedfile{} had to go in the preamble. Does it not? – vy32 Sep 7 '11 at 1:08
  • 3
    @vy32 You can safely use \embedfile anywhere in your document. The list of embedded files the PDF file contains is written at the very end of the document. – diabonas Sep 7 '11 at 9:57
  • 1
    Is there a way to get this to work with non-pdf files? – Jason Gross Feb 28 '15 at 3:56

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.