7

I would like to generate a PDF file via PDFTeX that is also a Windows Executable at the same time (the resulting file is a polyglot).

For this, I need the PDF file, among other thing, to start with the 'MZ' letters.

Can I do that via a specific macro or package?

Ange
  • 190

1 Answers1

9

Your "polyglot" is not a valid PDF file. A canonical PDF file starts with the PDF header (%PDF-1.x). However Acrobat Reader and some other PDF viewers are less strict, from the implementation notes in the PDF specification:

3.4.1, "File Header"
13. Acrobat viewers require only that the header appear somewhere within the first 1024 bytes of the file.

A canonical PDF file ends with %%EOF in the last line. Again, Acrobat Reader is less strict:

3.4.4, "File Trailer"
18. Acrobat viewers require only that the %%EOF marker appear somewhere within the last 1024 bytes of the file.

Thus there is some room to add a wrapper for other formats.

However, you cannot add something at the beginning or the end with pdfTeX. But something can be added inside the PDF file:

\begingroup
  \pdfcompresslevel=0\relax
  \immediate\pdfobj stream file{foo.bar}\relax
\endgroup

Then the contents of file foo.bar can be found uncompressed inside the PDF file.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Heiko Oberdiek
  • 271,626
  • It is a valid file from my (malware analyst) perspective: it's rendered as expected, without any errors, by all readers (linux ones, sumatra, firefox, chrome, adobe). – Ange Feb 25 '14 at 07:38