We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting PNG -> PDF on Windows Server

Hi.
We’re using Aspose Total for Java to convert PNG images to PDF’s.
When we run this operation on Windows 7 (64 bit), everything is OK.
When we run the same program on Windows 2012 server, PDF is broken.

PNG and broken PDF in attachments.

We use the code from this example:

http://www.aspose.com/docs/display/pdfnet/How+to+Convert+a+text+file+to+PDF

I hope, You can help me.

Hi Krzysztof,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 9.0.0 over Windows Server 2012 where I have used JDK 1.7.0_10 and I am unable to notice any problem. The image file is properly being converted to PDF format. For your reference, I have also attached the resultant PDF file generated over my end. Can you please try using the following code snippet and in case the problem still persists, please share the JDK version and other information. We are sorry for your inconvenience.

[Java]
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
doc.getPages().add();
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
image.setFile(“c:/pdftest/png.png”);
doc.getPages().get_Item(1).getParagraphs().add(image);
doc.save(“c:/pdftest/ConversionIssue_png.pdf”);




Hi.
Thanks for answer.
I’ve checked Your code and it seems to be OK.
But why my code wasn’t good?

Could You check if it works in Your enviroment:

[Java]
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(filePath);
//Save the Pdf
pdf1.save(newFile);

Hi,


The code which you have been using is based on legacy Aspose.Pdf for Java (aspose.pdf package). However the one which I have shared is based on new Document Object Model of Aspose.Pdf for Java (com.aspose.pdf package). So we recommend you to please try using the latest DOM approach and in the event of any further query, please feel free to contact.