Sort of “off-topic” for this site, you may think. But bear with me, that in a few days this article will be very important…
The PDF standard accept being used as a “container,” accepting attachments. This feature allows us to work with forms that can be completed by the PDF reader, but the files that can be attached are not limited to that: for example, we may want to distribute a programming manual in PDF format, attaching to certain pages some scripts, or maybe… well, in a few days we’ll see another example. Maybe.
Of course, such advanced option can be used from the proprietary Adove software, but what happens if we want to attach something to a PDF in Linux?
For this, we have PDFtk.
Note: PDFtk as a command-line utility is free/libre software, but there is also a free, but non-libre, user interface for it that only works on Windows. Check the project website for more information.
PDFtk allows us to do everything we can imagine in PDF files and even more: merge files, divide them, add or remove pages… and of course, it allows us to attach files to a PDF.
By opening a virtual terminal in the folder that contains both, the PDF and the “to be attached” file, we can write
pdftk my-pdf.pdf attach_files file-to-attach.xyz to_page <number> output output-file.pdf
<number> is the page number where we want the attachment to appear. For example, if we want to attach the script.sh file to page 27 of the manual.pdf file, creating the file manual_plus.pdf we need to write
pdftk manual.pdf attach_files script.sh to_page 27 output manual_plus.pdf
I do not recommend using the original file as the destination: in a test, the program gave me an error and deleted the destination file…
Now, opening the new PDF in, for example, Okular, we will find that the attachment is marked with a “pin” on the chosen page and that by selecting “Revisions” we can see it and, with a right click, download it.
There is a really old GUI for PDFtk called PDFtk-qgui, but it seems unmaintained and, last time I tried it, it was “problematic.”