Add a transparent PNG image to a PDF file in Java using Aspose.PDF for Java

Hello.

I am using Aspose.Pdf for Java and encountered a problem when I added a PNG image with a transparent background to pdf. The background turned into black color. I searched the forum and found someone had the same problem with Aspose.Pdf for .NET in Aug 2008 and Aspose support team gave him a solution. But for Aspose.Pdf for Java. Do you have a solution for this scenario?

By the way, here is your solution for .NET.
Add a transparent PNG image to a PDF file in C# using Aspose.PDF for .NET - #4 by Hans.firefox - Free Support Forum - aspose.com

Thanks.

zq

Hello Qiang,

Thanks for using our products.

This problem is already logged in our issue tracking system as PDFJAVA-20964. Our development team is looking into the details of this problem and will keep you updated on the status of a correctio. Please be patient and spare us little time.

We apologize for your inconvenience.

The issues you have found earlier (filed as 23219) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I’m using Aspose PDF 3.0.1 and still see this issue.

Code:
Section section = pdf.getSections().add();

                    Image image = new aspose.pdf.Image(section);
                    image.getImageInfo().setImageStream(new FileInputStream("/some dir /davebrown/Downloads/out.png"));
                    // Add image object into the Paragraphs collection of the section
                    section.getParagraphs().add(image);

pdf.save(pdfFile.getAbsolutePath());

Hello Dave,


Thanks for using our products.

I have tested the scenario while using Aspose.Pdf for Java 3.0.1 where I have tried converting the attached Penguin.PNG into PDF format and as per my observations, the image still has white background. Please take a look over the attached resultant PDF document.

Can you please share the source PNG image so that we can try converting it in our environment. We are really sorry for this inconvenience.

Sure! Attached is the input image and resultant pdf.



Note - this is Java.

Hi Dave,

Thank you for sharing the files.

I tested your issue using your shared files and I am unable to notice the problem. I have attached the resultant PDF file. Please share your environment details with us. This will help us isolate the issue.

Sorry for the inconvenience,

My test environment is OSX Lion in a headless environment.

Hi Dave,

Thank you for sharing the environment information with us. I have created an issue in our issue tracking system with issue id: PDFJAVA-33127.
Our development team will further look into your issue as per your environment. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience,

Would it be possible to get this looked at ASAP?

Thanks!

Hi -



We also tried Win7 with the same result.



Would it be possible to send me a ful code example I could try?

Hi Dave,

Following is the code I used to generate the attached PDF file:

//Instantiate a Pdf object by calling its empty constructor`
Pdf pdf1 = new Pdf();

//Create a section in the Pdf object`
Section sec1 = pdf1.getSections().add();

//Create an image object in the section`
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);

//Add image object into the Paragraphs collection of the section`
sec1.getParagraphs().add(img1);

//Set the path of image file`
img1.getImageInfo().setFile("E:/AP Data/Feb2012/Archive/out.png");

//Set the title of image file`
img1.getImageInfo().setTitle("PDF image");

//Save the Pdf`
pdf1.save("E:/AP Data/Feb2012/Archive/PNG_image_toPDF.pdf");

I am using Java 1.6 version, Aspose.Pdf for Java 3.0.1 on a Windows 7 32 bit machine. Please share your complete code and environment details with us to help us reproduce the issue.

Sorry for the inconvenience,

Hello Dave,

Adding more to Nausherwan's comments, I have also tried executing the same code snippet on Windows 7 Professional X64 machine running jdk1.6.0_20 and as per my observations, the source Image is properly being converted into PDF format. Please take a look over the attached resultant PDF document that I have generated. For your reference, I have also attached Aspose.Pdf for Java 3.0.1 which I am using in my environment.

Hi Dave,

Please download and try the latest version of Aspose.Pdf for Java v3.1.0 as your reported issue has been fixed in this version (tested on both OSX Lion and Win 7 x64). Please download and try the latest version and share your feedback with us.

Sorry for the inconvenience.

The issues you have found earlier (filed as PDFJAVA-33127) have been fixed in Aspose.Pdf for Java 3.2.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan