Christian
Christian

Reputation: 646

PDF inline Image does not work

I defined an image within a pdf stream. It works correctly an shows me a red 4 pixel palette:

%PDF-1.7
1 0 obj
<<
  /Type     /Catalog
  /Pages    2 0 R
  /PageMode /UseNone
>>
endobj
2 0 obj
<<
  /Type  /Pages
  /Count 1
  /Kids  [3 0 R]
>>
endobj
3 0 obj
<<
  /Type      /Page
  /Parent    2 0 R
  /MediaBox  [0 0 50 20]
  /Contents  4 0 R
  /Resources
  <<
    /XObject << /Im1 5 0 R >>
  >>
>>
endobj
4 0 obj
<<
  /Length 38
>>
stream
  40 0 0 10 5 5 cm
  /Im1          Do
endstream
endobj
5 0 obj
<<
  /Type             /XObject
  /Subtype          /Image
  /Width            4
  /Height           1
  /ColorSpace       /DeviceRGB
  /BitsPerComponent 2
  /Filter           /ASCIIHexDecode
  /Length 10
>>
stream
 01 08 30
endstream
endobj
xref
0 6
0000000000 65535 f 
0000000009 00000 n 
0000000090 00000 n 
0000000155 00000 n 
0000000311 00000 n 
0000000400 00000 n 
trailer
<<
  /Size 6
  /Root 1 0 R
>>
startxref
720
%%EOF

But when I try to show the same image as an inline image, there is only a blank page:

...
...same as above...
...
3 0 obj
<<
  /Type      /Page
  /Parent    2 0 R
  /MediaBox  [0 0 50 20]
  /Contents  4 0 R
>>
endobj
4 0 obj
<<
  /Length 92
>>
stream
 40 0 0 10 5 5 cm
 BI
  /W   4
  /H   1
  /CS  /RGB
  /BPC 2
  /F   /AHx
 ID
  01 08 30
 EI
endstream
endobj
...

When I use no abbreviations for the image properties, there is already a blank page.

Does anyone has an idea what could be the problem?

Thank you for any hint and help!

Upvotes: 2

Views: 1749

Answers (1)

Christian
Christian

Reputation: 646

Okay, the last two days I read the specification again and again. But it was worthwhile.

There were two mistakes. Only the correction of both of them gave me my wanted result...

First of all I did not end the ASCIIHexDecodeFilter portion between ID and ED. The specification says: "A right angle bracket character (>) indicates EOD." If there is a full stream filtered with ASCIIHexDecodeFilter, the Adobe Reader knows about the end of the stream by reading the /Length attribute. But as part of the stream itself it needs the > character.

The second thing is that my page object (3 0 obj) requires a /Resources attribute mandatory. It may be empty (/Resources << >>) but it may not be missing.

Thanks for everyone who tried to answer or help!!

Here the correct working inline image PDF file stream:

%PDF-1.7
1 0 obj
<<
  /Type     /Catalog
  /Pages    2 0 R
  /PageMode /UseNone
>>
endobj
2 0 obj
<<
  /Type  /Pages
  /Count 1
  /Kids  [3 0 R]
>>
endobj
3 0 obj
<<
  /Type      /Page
  /Parent    2 0 R
  /MediaBox  [0 0 50 20]
  /Contents  4 0 R
  /Resources << >>
>>
endobj
4 0 obj
<<
  /Length 90
>>
stream
q
 40 0 0 10 5 5 cm
 BI
  /W 4
  /H 1
  /CS/RGB
  /BPC 2
  /F /AHx
 ID
  01 08 30 >
 EI
Q
endstream
endobj
xref
0 5
0000000000 65535 f 
0000000009 00000 n 
0000000090 00000 n 
0000000155 00000 n 
0000000277 00000 n 
trailer
<<
  /Size 5
  /Root 1 0 R
>>
startxref
418
%%EOF

Upvotes: 4

Related Questions