Hi,
I'm working on a small and simple pdf generator (just for simple drawing purpose), and I'm trying to manage semi-transparent image (like png).
I've successfully managed non semi transparent image (so with no alpha layer) like jpeg, bmp,... or non semi-transparent png (or removing alpha layer from png to display them).
When generating a simple PDF (one page, with one picture drawn on it with a non transparent), I've obtain something like this:
%PDF-1.7
1 0 obj <</Type /Catalog /Pages 2 0 R>>
endobj
2 0 obj <</Type /Pages /Kids [4 0 R] /Count 1>>
endobj
3 0 obj
<<
/Title (Test)
/Author (Me)
/CreationDate(D:20130710104410+02'00')
/ModDate(D:20130710104410+02'00')
>>
endobj
4 0 obj <</Type /Page /Parent 2 0 R /MediaBox [0 0 595 841] /Resources 5 0 R /Contents 6 0 R>>
endobj
5 0 obj <<
/XObject <</Im1 7 0 R >>
>>
endobj
6 0 obj
<</Length 33>>
stream
q
149 0 0 66 50 725 cm
/Im1 Do
Q
endstream
endobj
7 0 obj <<
/Type /XObject
/Subtype /Image
/Width 149
/Height 66
/ColorSpace /DeviceRGB
/BitsPerComponent 8
/Filter /FlateDecode
/Length 338
>>stream
BINARY DATA STREAM
endstream
endobj
xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000056 00000 n
0000000111 00000 n
0000000413 00000 n
0000000515 00000 n
0000000563 00000 n
0000000643 00000 n
trailer <</Size 8 /Root 1 0 R /Info 3 0 R>>
startxref
1147
%%EOF
According to the pdf specification, I'v tried to manage the alpha layer of image by using SMask like this:
Add a /SMask X o R (where X will be 8 in my example) to my XObject Image (7 0 obj in my previous example); and then generating the new 8 0 obj with only the alpha layer as data.
My SMask object has the same width/height of my Image (it's the alpha layer), and each pixel varying from 0 to 255 (alpha opacity value), extracted and encoded as the same way of my RGB image.
So, if I update my example, I have:
%PDF-1.7
1 0 obj <</Type /Catalog /Pages 2 0 R>>
endobj
2 0 obj <</Type /Pages /Kids [4 0 R] /Count 1>>
endobj
3 0 obj
<<
/Title (Test)
/Author (Me)
/CreationDate(D:20130710104410+02'00')
/ModDate(D:20130710104410+02'00')
>>
endobj
4 0 obj <</Type /Page /Parent 2 0 R /MediaBox [0 0 595 841] /Resources 5 0 R /Contents 6 0 R>>
endobj
5 0 obj <<
/XObject <</Im1 7 0 R >>
>>
endobj
6 0 obj
<</Length 33>>
stream
q
149 0 0 66 50 725 cm
/Im1 Do
Q
endstream
endobj
7 0 obj <<
/Type /XObject
/Subtype /Image
/Width 149
/Height 66
/ColorSpace /DeviceRGB
/BitsPerComponent 8
/SMask 8 0 R
/Filter /FlateDecode
/Length 338
>>stream
BINARY DATA STREAM
endstream
endobj
8 0 obj <<
/Type /XObject
/Subtype /Image
/Width 149
/Height 66
/ColorSpace /DeviceGRAY
/BitsPerComponent 8
/Filter /FlateDecode
/Length 1092
>>stream
BINARY DATA STREAM
endstream
endobj
xref
0 9
0000000000 65535 f
0000000009 00000 n
0000000056 00000 n
0000000111 00000 n
0000000413 00000 n
0000000515 00000 n
0000000563 00000 n
0000000643 00000 n
0000001160 00000 n
trailer <</Size 9 /Root 1 0 R /Info 3 0 R>>
startxref
2420
%%EOF
Using SMask is the right way to manager an alpha layer, or not?
I've tried to generate a similar pdf from word with a pdf printer driver, but it seems not generating a SMask tag and object.
Must the SMask object (my 8 0 obj) must be reference to the pdf resources (5 0 obj)?
In fact, my pdf is not displayed in Adobe Pdf Reader (last version, an error is popup saying that there is an error into my pdf) but it displayed correctly with another pdf reader (PDF Architect).
Regards,
Alex