How to insert transparent PNG to PDF?

I can insert a jpg image into a PDF document with a DCTDecode filter. I think that all parameters should be the same for the PNG image, except for the filter, which should be FlateDecode . However, when I try to insert a PNG with the same parameters, the PNG image will not be visible in the PDF document.

UPDATE: I came to the conclusion that the PDF file should include

 1 0 obj << /Type /XObject /Subtype /Image /Width 512 /Height 512 /BitsPerComponent 8 /ColorSpace /DeviceRGB /SMask 9 0 R /Length 134753 /Filter /FlateDecode >> stream PNG_RAW DATA endstream endobj 9 0 obj << /Type /XObject /Subtype /Image /Width 512 /Height 512 /BitsPerComponent 8 /ColorSpace /DeviceGray /Length 12087 /Filter /FlateDecode >> stream ALPHA_PIXELS endstream endobj 

BUT, how can I separate the PNG and alpha pixels raw data through ImageMagick ? In other words, the ImageMagick command can create PDF_RAW_DATA and ALPHA_PIXELS to insert into a pdf file.

+8
image pdf imagemagick png adobe
source share
2 answers

@Bobrovsky

Here is an example: http://pd4ml.com/i/pd4ml18130.pdf

To be more precise: you cannot embed PNG absolutely without manipulating it. You will need to divide PNG into sections: IDAT (image data) goes into PDF as a stream of bytes without changes, PLTE (palette) into the definition of color space, iCCP does not necessarily go to the color profile object.

An object dictionary might look like this:

 << /Filter /FlateDecode /Type /XObject /Subtype /Image /BitsPerComponent 8 /Length 1277 /Height 250 /Width 250 /DecodeParms << /BitsPerComponent 8 /Predictor 15 /Columns 250 /Colors 1 >> /ColorSpace [/Indexed /DeviceRGB 1 <1989d1ffffff>] >> stream ... IDAT bytes ... 
+6
source share

Most likely you did not decode PNG images.

PNG is not directly supported in PDF. I mean, they are not supported in supported JPEG formats.

You must create raw uncompressed bitmap bytes from PNG before embedding them in a PDF. If you want, you can encode bitmap bytes using the Flate or LZW codec.

+4
source share

All Articles