If one and the same image is included in a PDF multiple times it is only stored only once as an PDF object. Now I like to also attach an image which is shown in the document to the PDF to allow users to copy the file. I'm aware that it is sometimes possible to copy images from the PDF anyway, but AFAIK this is limited to raster images like PNG and JPG, and not possible for included PDF images/diagrams.
I'm aware of the packages like embedfile
and attachfile
, but the tricky part is: Is it possible to display and attach/embed an already used image as PDF attachment without having it stored twice in the PDF?
Or in other words, the other way around: I like to add an image file as PDF attachment and then display this image file also in the document, without storing it again. AFAIK the PDF format should support this, but exactly how is the question. I don't mind a solution which uses some \pdfobj
code.
Here a minimal example so that people can understand it better:
\documentclass{article}
\usepackage{graphicx}
\usepackage{embedfile}
\begin{document}
% Used twice, but only stored once:
\includegraphics[width=\textwidth]{tiger.pdf}
\includegraphics[width=\textwidth,angle=45]{tiger.pdf}
% Also added as attachment:
\embedfile{tiger.pdf}
% This should reuse the image file above, but adds `tiger.pdf` a second time
\end{document}
Best Answer
I followed Martin Schröder's idea to use reference XObjects. Here is an example to show that it can be done, in a very limited way, for embedded PDF files only:
For non-PDF files, this isn't possible: when a file is embedded in the PDF, the "embedded file stream" contains the complete, say, PNG file including metadata, and other "chunks". When you include an image for display, then only the image data itself is included as the image data stream (what would live in the PNG IDAT chunk), and the other information, metadata, etc, is represented in PDF syntax. I don't think there will be any way around this.