I’m converting html to pdf using itextPDF, everything works as expected but for one of the GIF image after conversion to pdf only the skeleton of the image appears. This is a static GIF image not animated just an image with transparent background and image in center. when I run the code through other GIF images with transparent background works as expected. I’m using the below code to convert HTML to PDF. I have attached a sample image of the issue.sample image
PdfWriter writer = new PdfWriter(inMemoryStream);
PdfDocument pdf = new PdfDocument(writer);
PdfMerger merger = new PdfMerger(pdf);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument temp = new PdfDocument(new PdfWriter(baos));
HtmlConverter.convertToPdf(test, temp, converterProperties);
temp = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())));
merger.merge(temp, 1, temp.getNumberOfPages());
temp.close();
pdf.close();
inMemoryStream.close();
2
Answers
This should not be a problem if you understand how PDF handles transparency.
It does not matter if an Image is TIFF PNG or GIF with transparency they are all stored in a similar fashion as 2 images. One is the opaque DeviceRGB the other is the Alpha channel as a black "SoftMask" we can see one image in left column, and 2 images mentioned in right column, and the 2 images (RGB overlaid with SoftMask) in the central PDF view.
The issue here is bad image generation as the SoftMask has not been drawn well
it should look like this