# Attach a file with different name

I would like to attach a file to a PDF document like \attachfile or \textattachfile does, but I want the attached file to be renamed. As far as I have seen, the packages attachfile and attachfile2 do not provide this feature.

With the packages embedfile and navigator I could embed files and select new names for storage. But I would like to have an annotation inside my text like \attachfile does. Is there some working combination of both or some raw PDF wizadry to access the embedded files?

Here is an MWE:

\begin{filecontents*}{foo.bar}
\documentclass{article}
\begin{document}
Foo.
\end{document}
\end{filecontents*}
%
\documentclass{article}
\usepackage{xcolor}
\usepackage[color=red]{attachfile2}
\usepackage{embedfile}

\begin{document}

\begin{enumerate}

\item Attachment of the file 'foo.bar':
\textattachfile{foo.bar}{Embedded file with original name}

\item Embedding of 'foo.bar' as 'usefulname.tex'.
\embedfile[ucfilespec={usefulname.tex}]{foo.bar}

\item How to attach 'foo.bar' as 'usefulname.tex' and get an
annotation on the page as in the first case?

\end{enumerate}

\end{document}


The documentation of attachfile2 mentions the option ucfilespec and it worked for me, but only if I didn't include the file also with the original name:

\begin{filecontents*}{foo.bar}
\documentclass{article}
\begin{document}
Foo.
\end{document}
\end{filecontents*}
%
\documentclass{article}
\usepackage{xcolor}
\usepackage[color=red]{attachfile2}
\usepackage{embedfile}

\begin{document}

\begin{enumerate}

\item Attachment of the file 'foo.bar':
% \textattachfile{foo.bar}{Embedded file with original name}

\item Embedding of 'foo.bar' as 'usefulname.tex'.
\embedfile[ucfilespec={usefulname.tex}]{foo.bar}

\item How to attach 'foo.bar' as 'usefulname.tex' and get an
annotation on the page as in the first case?
\textattachfile[ucfilespec={usefulname2.tex}]{foo.bar}{Embedded file with changed name}
\end{enumerate}

\end{document}


• Yes, that's it. :-) This option slipped my attention when I searched the documentation for something like that. – Thomas F. Sturm Oct 23 '15 at 10:11