[pdftex] Attaching and dettaching a file to a PDF (this time with pdftosrc)

Antonio Lou alou at mazars.es
Tue Apr 16 21:06:46 CEST 2002


Hi

Still trying to embed the contents of a file into a PDF, I tested the
following code from Than:

\newcommand{\embedfile}[1]{
  \immediate\pdfobj
     stream attr {/Type /SourceFile /SourceName (#1)}
     file{#1}
\pdfcatalog{/SourceObject \the\pdflastobj\space 0 R}
}

and tried to extract it with his pdftosrc binary.  This extracts the file
from the PDF, but there is still there the unwanted final byte.

Could it be a problem with the embedding routine in pdftex?  I'm testing
this in a W2K box; are there similar problems in Unixes?


Toni


> Hello
>
> I'm trying to attach _and_ dettach external files to a PDF in order to
get
> self-contained files for distribution.  So far I have hacked a few LaTeX
> macros to do the job:
>
> \newcommand{\insertfile}[2]{
>  % #1: File path to insert
>  % #2: Text to show
>  \immediate\pdfobj stream
>     attr {/Type /EmbeddedFile}
>     file {#1}
>  \makefileannotation{#2}{\the\pdflastobj}
> }
>
> \newcommand{\makefileannotation}[2]{
>  % #1: Text to show
>  % #2: Reference to the embedded file object
>  \immediate\pdfobj{
>    << /F (#1)
>       /Type /Filespec
>       /EF << /F #2\space 0 R >>
>    >>
>   }
>  \fileannotation{#1}{\the\pdflastobj}
> }
>
> \newcommand{\fileannotation}[2]{
>  % #1: Text to show
>  % #2: Reference to the /Filespec object
>  \pdfannot{
>      /Subtype /FileAttachment
>      /Contents (#1)
>      /C [ 0 0.60001 1 ]
>      /FS #2\space 0 R
>  }
> }
>
> So, you can say  \insertfile{C:/temp/test.xml}{test.xml}  and you get the
> file <C:/temp/test.xml> embedded with an annotation in the PDF that
enables
> you to dettach it (I think this only works with Acrobat > 5).
>
> However, when I open the embedded file from inside the PDF via the
built-in
> dettach tool , I get a byte at the end of the file (11111111) that wasn't
> there before doing the attachment.  Any ideas?  I'm using pdftex Version
> 3.14159-1.00a-pretest-20010806 (MiKTeX 2.1)
>
>
> Thanks,
>
> Toni





More information about the pdftex mailing list