iTextSharp Image Extraction with Transparency

匆匆过客 提交于 2019-11-29 16:10:18

Please read the PDF specification (ISO-32000-1). You are making the assumption that, for instance a transparent PNG, can be stored inside a PDF as a transparent PNG. That assumption is wrong.

The image type PNG isn't supported in PDF. When a transparent PNG is added to a PDF document, it is converted into two compressed bitmaps. One bitmap is the image you're referring to: the image that allegedly lost its transparency. The other bitmap, an image you didn't tell us anything about, but that is there, is a mask for this image. When you examine the Image XObject, you'll notice that it has a reference to this mask. This is explained in my book in section 10.3.2, entitled "Masking images".

Your allegation that you have a transparent image stored in your PDF documents is wrong. Instead, you have two opaque images of which one image is the mask of the other, in order to achieve transparency. You can't extract these images as a single transparent image. You need to extract both opaque images and merge them into a single transparent image. This is outside the scope of iText(Sharp).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!