I'm embedding an external file in my pdf with \usepackage{attachfile2} and \textattachfile[color=1 1 1]{description}{file.txt}. How can I make the text look the same as it would if I had used the hyperref package and done something like

\textattachfile[color=0 0 0]{description}{file.txt}


I'm looking for something that includes the non-printing border, but only opens the file when clicked. I suppose I'd be ok with some hacky code that modifies the internals of hyperref or attachfile2. (I haven't figured out myself how to redefine \Hy@StartlinkName to use, e.g., user instead of goto link, because I don't know what /A and /Subtype to pass to user. I also haven't figured out how to modify the internals of attachfile2 to behave more like hyperref.)

Note: the solution to my previous question only works for embedded pdf files.


You can create a link to an embedded file using the JavaScript function exportDataObject. The following code creates a new command \embeddedfilelink{<file>}{<text>} that creates a link to an embedded file specified by its file name with the given link text. The code is taken from hypgotoe and modified to create a JavaScript action instead of a GoToE action.



% How do I make an attached non-pdf file display like a link?
% (http://tex.stackexchange.com/q/230581)
         /JS(this.exportDataObject({cName: "#1", nLaunch: 2}))%



appearance of link to embedded file

Clicking the link opens the embedded file after confirming the obligatory security warning

Adobe Reader security warning when trying to open an embedded file

Note that this solution only works with readers supporting JavaScript, which probably few viewers other than Adobe Reader/Acrobat do.

| improve this answer | |
  • Good one..... :-) – karlkoeller Feb 28 '15 at 10:34
  • Gives me the error: Package xcolor Error: Undefined color '0 .5 .5' – fars Jun 8 '19 at 1:09

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.