I have this code to attach files via dvipdfmx, and it works well:

  \special{pdf:fstream @file (#1)}%
  \special{pdf:ann bbox 0 0 10 10
  <</Type /Annot /Subtype /FileAttachment
  /FS <</Type /Filespec /F (#1.txt)
  /EF <</F @file>> >> /Name /PushPin>>}}

If I use navigator package, I don't see the button to open the file:

\input navigator

This topic is relevant, but I could not make these examples to work in LuaTeX: Attaching files using plain TeX (pdfTeX)

How should the above dvipdfmx code be changed to work with luatex in pdf mode?

  • 2
    See packages attachfile, attachfile2, embedfile. – Heiko Oberdiek Dec 25 '15 at 7:06
  • @HeikoOberdiek: Yes, I saw them, but it seems to me that all of them work only in LaTeX (not plain luatex). And I could not peel the solution from these packages to make it as simple as possible (like in dvipdfmx example). – Igor Liferenko Dec 25 '15 at 7:53
  • Package embedfile also works with plain TeX. Also these packages contain the low level code for driver pdfTeX, which also can be used for LuaTeX. – Heiko Oberdiek Dec 25 '15 at 8:21
  • @HeikoOberdiek: I tried embedfile-example-plain.tex from texlive-latex-base-doc package. It requires to use miniltx. This is not what is needed. Can it work without miniltx? Also, I did not see the button to open the attachment, whereas in my dvipdfmx example such button appears in the document. – Igor Liferenko Dec 25 '15 at 8:27
  • 1
    Replace (#1.txt) by (\pdfescapestring{#1.txt}). – Heiko Oberdiek Dec 28 '15 at 17:40

The following code works as required:

  \immediate\pdfobj stream file {#1}%
  \pdfannot width 10pt height 10pt depth 0pt {
    /Subtype /FileAttachment
    /C [ 0 0.5 0 ]
    /FS << /F (#1.txt)
    /Type /Filespec
    /EF << /F \the\pdflastobj\space 0 R >> >>}}

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.