Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

Example

share|improve this question
    
I'm not 100% clear what you want to do, and I've never played with the PDF file attach/embed stuff (since it seems like only Adobe supports it properly anyway), but perhaps the hypgotoe package can be useful. It seems to allow you to attach the file once, but then link to it from multiple places in the PDF. –  Lev Bishop May 26 '11 at 14:10
    
@Lev: You can attach files to PDFs similar like attachments to emails. I would like that the image in question is also listed as exportable attachment. –  Martin Scharrer May 26 '11 at 14:19
    
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. <– This depends on the PDF viewer (and underlying PDF toolkit). On MacOS, for instance, almost all PDF viewers can copy&paste arbitrary vectorized content from a PDF file into a new PDF. However, I am not aware of any Windows or Linux tool that does the job. –  Daniel May 26 '11 at 22:07
    
If that is the case, it is interesting that MacOS does this while others don't. If included PDF where copiable as vector graphics in general, there would be not a great need for this feature. –  alfC Aug 4 '11 at 9:08
add comment

2 Answers

up vote 10 down vote accepted

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:

\documentclass{article}
\usepackage{embedfile}
\begin{document}
\embedfile[id={foo}]{tst.pdf}% Embed the file and give it a ID (foo) to refer to it later
Some text
\setbox0=\vbox to 3 in { % Give a message to people who don't see the reference
To see the correct image, please:
   0)~ensure you are using Adobe Reader 9.0 or later; 
   1)~set the preference ``Show reference XObject Targets'' (on the 
     ``Page Display'' tab) to ``Always''; 
   2)~Add the path of this PDF file to the ``Privileged Locations'' box on the
      ``Security (Enhanced)'' tab}
\pdfxform attr {/Ref <</F \embedfilegetobject{foo}{Filespec}/Page 0 >>}0
\pdfrefxform\pdflastxform
\end{document} 

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.

share|improve this answer
add comment

It seems the PDF spec allows this. The key are reference XObjects (section 8.10.4 of 32000-1:2008). One would have to include the PDF as an embedded file (section 7.11.4) and then construct an XObject with minimal content that /Refs the embedded file. You'd still have some overhead for the ref XObject and you'd rely on clients handling ref XObjects correctly.

This should be possible with pdftex but probably needs heavy trickery with \pdfliteral.

share|improve this answer
    
To clarify this: I want to attach a file (e.g. a PDF image) to the document PDF, so that it appears in the "attachment" section of the PDF. You can attach any file e.g. using the attachfile package. I now want to display the same file and don't want to have it stored as two different xobjects. –  Martin Scharrer May 26 '11 at 16:59
    
It could be interesting to try to get this to work, but it will only help for the case that the attached image is a PDF, not any other image file (not clear if that's an important limitation for the OP). Also, I think it'll be necessary to ask people who receive your documents to set the adobe pdf viewer preference "Show reference XObject targets" (under "Page display") to the non-default value "Always", otherwise they'll only see your "minimal content". (Probably most people using non-adobe viewers would have the same problem). –  Lev Bishop May 27 '11 at 0:21
    
OK, see my edit. It can be done, but this is quite limiting. –  Lev Bishop May 27 '11 at 2:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.