# Attach files to PDF with dvipdfmx

The attachfile package allows files to be embedded within the output PDF of a pdfLaTeX document, and the attachfile2 extends this for dvips use as well.

In an article, the author of dvipdfmx gives a recipe for doing the same thing with that driver instead:

\begin{filecontents*}{example.txt}
this is a text file to be embedded
\end{filecontents*}

\documentclass{article}
\begin{document}
test
\special{pdf:fstream @myfile (example.txt)}%
\special{pdf:ann bbox 0 0 10 10 <<
/Subtype /FileAttachment /FS <<
/Type /Filespec /F (example.txt)
/EF << /F @myfile >> >>
/Name /PushPin >>}
\end{document}


However, when I compile this with latex+dvipdfmx, I get the following warning:

** WARNING ** Could not open file: example.txt
** WARNING ** Interpreting special command fstream (pdf:) failed.
** WARNING ** >> at page="1" position="(168.14, 707.125)" (in PDF)
** WARNING ** >> xxx "pdf:fstream @myfile (example.txt)"
]
** WARNING ** Object @myfile used, but not defined. Replaced by null.


Does anyone know what I'm going wrong? (TeX Live 2010, Mac OS X.) It would be great to be able to embed files using this method, since that would facilitate XeTeX use with the attachfile packages.

Update: things seem to work fine in TeX Live 2009. I'm thinking that this is a bug in the latest version of dvipdfmx. Any confirmation on this?

• And the big followup question is: who's got the time to incorporate this into attachfile2? – Will Robertson Sep 27 '10 at 8:34
• dvipdfmx is now supported in a new version of attachfile2 (2010/09/27 v2.6), which can be found on CTAN. – diabonas May 27 '11 at 11:09

\special{pdf:fstream @myfile (./example.txt)}%