What is the smallest possible PDF?

Out of curiosity, seeing the smallest GIF , what is the smallest possible valid PDF file?

+50
optimization pdf pdf-generation
Jun 24 '13 at 15:52
source share
3 answers

This is an interesting problem. Taking it by the book, you can start with this:

%PDF-1.0 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj xref 0 4 0000000000 65535 f 0000000010 00000 n 0000000053 00000 n 0000000102 00000 n trailer<</Size 4/Root 1 0 R>> startxref 149 %EOF 

which is 291 bytes of PDF joy. Acrobat opens it, but he complains somewhat. It has one page, and it is 3/72 "square, the minimum allowed by the specification.

However, Acrobat X no longer bothers with the cross-reference table, so we can accept this:

 %PDF-1.0 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj trailer<</Size 4/Root 1 0 R>> 

The acrobat complains, but opens it. Now we are at 178 bytes. Turns out you don't need this / size in the trailer. Now we are at 172:

 %PDF-1.0 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj trailer<</Root 1 0 R>> 

It turns out you don't need all these stylish elements / words in dictionaries:

 %PDF-1.0 1 0 obj<</Pages 2 0 R>>endobj 2 0 obj<</Kids[3 0 R]/Count 1>>endobj 3 0 obj<</MediaBox[0 0 3 3]>>endobj trailer<</Root 1 0 R>> 

Now we are at 138 bytes.

It also turns out that when the specification says “should be an indirect reference” and / Count is required and the “should” heading should be% PDF-1.0, they make free offers. This is the smallest thing I could do and open it in Acrobat X:

 %PDF-1. trailer<</Root<</Pages<</Kids[<</MediaBox[0 0 3 3]>>]>>>>>> 

70 bytes.

Now my editor uses the Windows discipline newline, but Acrobat accepts Windows, Mac, or Unix conventions, so using the hex editor I replaced \ r \ n with \ r and deleted the last new line altogether, which leaves me with 67 bytes

 25 50 44 46 2D 31 2E 0D 74 72 61 69 6C 65 72 3C 3C 2F 52 6F 6F 74 3C 3C 2F 50 61 67 65 73 3C 3C 2F 4B 69 64 73 5B 3C 3C 2F 4D 65 64 69 61 42 6F 78 5B 30 20 30 20 33 20 33 5D 3E 3E 5D 3E 3E 3E 3E 3E 3E 

I tried to remove the last dictionary (→), but Acrobat did not. Reading PDF embedded in Google Chrome (FoxIt) will not open it.

Like PostScript (HA! See what I did there?), If you agree to "restore" the Acrobat file, it types up to 3550 bytes, most of which are additional metadata, but reserve a number of clear specifications for the violation.

+68
Jun 24 '13 at 16:55
source share

I thought I was creating a small pdf file that displays "Hello World". The text is in the lower left corner. Sorry for the font with 9 points, any larger one will cost an extra byte :)

172 bytes for Adobe Reader X (if they are saved with lines only for the translation line and without a trailing newline or zero byte):

 %PDF-1. 1 0 obj<</Kids[<</Parent 1 0 R/Resources<<>>/Contents 2 0 R>>]>>endobj 2 0 obj<<>>stream BT/ 9 Tf(Hello World)' ET endstream endobj trailer<</Root<</Pages 1 0 R>>>> 

120 bytes for Google's built-in PDF viewer:

 %PDF 1 0 obj<</Pages<</Kids[<</Contents<<>>stream BT 9 Tf(Hello World)' ET endstream>>]>>>>endobj trailer<</Root 1 0 R>> 

To easily see this in Chrome, paste this URI into the address bar (SO will not allow me to link to it, and it will not work at all in other browsers):

 data:application/pdf,%25PDF%201%200%20obj%3C%3C%2FPages%3C%3C%2FKids%5B%3C%3C%2FContents%3C%3C%3E%3Estream%0ABT%209%20Tf(Hello%20World)'%20ET%20endstream%3E%3E%5D%3E%3E%3E%3Eendobj%20trailer%3C%3C%2FRoot%201%200%20R%3E%3E 
+9
Jun 10 '14 at 17:28
source share

I could not open a welcome example of the world.

For a small file with text content:

 %PDF-1.2 9 0 obj << >> stream BT/ 9 Tf(Test)' ET endstream endobj 4 0 obj << /Type /Page /Parent 5 0 R /Contents 9 0 R >> endobj 5 0 obj << /Kids [4 0 R ] /Count 1 /Type /Pages /MediaBox [ 0 0 99 9 ] >> endobj 3 0 obj << /Pages 5 0 R /Type /Catalog >> endobj trailer << /Root 3 0 R >> %%EOF 
+5
Aug 21 '15 at 14:02
source share



All Articles