user2320861
user2320861

Reputation: 1431

Trouble making my first PDF

I've been reading through the PDF spec for the past couple hours and this is what I've come up with. But it's not rendering in OSX Preview:

%PDF-1.3

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 /Parent 2 0 R /Resources <<>> /MediaBox [0 0 500 500] /Contents 4 0 R >>
endobj

4 0 obj
BT
/F13 12 Tf (Hello World!) Tj 
ET
endobj

xref
0 5 
0000000000 65535 f
0000000010 00000 n
0000000059 00000 n
0000000119 00000 n
0000000221 00000 n

trailer 
<< /Size 5 /Root 1 0 R >>
startxref
267
%%EOF

I'm sure it's something with my text object, but I'm having trouble figuring it out.

Upvotes: 2

Views: 111

Answers (1)

dwarring
dwarring

Reputation: 4883

After a few corrections, the following renders for me on xpdf 3.0

%PDF-1.3

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 /Parent 2 0 R /Resources << /Font << /F13 5 0 R >> /MediaBox [0 0 500 500] >> /Contents 4 0 R >>
endobj

4 0 obj
<< /Length 46 >>
stream
BT
/F13 12 Tf 100 250 Td (Hello World!) Tj
ET
endstream
endobj

5 0 obj
<< /BaseFont /Helvetica /Encoding /MacRomanEncoding /Name /F13 /Subtype /Type1 /Type /Font >>
endobj

xref
0 6
0000000000 65535 f 
0000000010 00000 n 
0000000060 00000 n 
0000000119 00000 n 
0000000247 00000 n 
0000000343 00000 n 

trailer
<< /Size 6 /Root 1 0 R >>
startxref
453
%%EOF

Things, I needed to change:

  • Added font object 5 0 R for /F13
  • Added 100 250 Td to content stream. needed to set the current position
  • Corrected format of 4 0 R. Note the << /Length 46 >> and stream, endstream markers.
  • Corrections to xref. In particular first line 0000000000 65535 f is a dummy free object. First real object appears as the second entry.

Upvotes: 2

Related Questions