3

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

\def\attach#1{%
  \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>>}}
\attach{\jobname.tex}
\bye

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

\pdfoutput=1
\pdfcompresslevel=0
\input navigator
\embeddedfile{sourcecode}{test.tex}
A
\bye

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
1

The following code works as required:

\pdfoutput=1
\def\attach#1{%
  \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 >> >>}}
\attach{\jobname.tex}
\bye

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.