Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

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.

share|improve this answer
    
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
    
@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
    
@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
    
Ah, okay. Thanks! –  vy32 Sep 9 '11 at 23:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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