Free Support Forum - aspose.com

PNG image replaced with redcross image when saving document to PDF format

Hi,

We use Aspose 16.7 Words Java library to create WORD and PDF documents.
While saving a document to PDF format, the PNG image inside the document is replaced by a redcross image. This issue doesn’t happen when document is saved to WORD format. The image comes up perfectly fine in the WORD output.

We use the following snippet to save the document in both PDF and WORD format :

public class SavePNGImage
{

public static void main(String[] args) throws Exception
{
TestAsposeUtils.setupLicense(TestAsposeUtils.LICENSE_FILE_PATH);
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
docBuilder.insertImage(“dw.png”);

String baseFolder = System.getProperty(“java.io.tmpdir”);
String unique = UUID.randomUUID().toString().replaceAll(" ", “");
String docpath = baseFolder + "test
” + unique + “_” + BuildVersionInfo.getVersion();

doc.save(docpath + “.doc”);
doc.save(docpath + “.docx”);

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);
pdfSaveOptions.setUpdateFields(true);
pdfSaveOptions.getOutlineOptions().setHeadingsOutlineLevels(6);
pdfSaveOptions.getOutlineOptions().setExpandedOutlineLevels(0);
doc.save(new NullOutputStream(),DocSaveOptions.createSaveOptions(SaveFormat.DOC));
doc.save(docpath + “.pdf”,pdfSaveOptions);

System.out.println(docpath + “.doc”);
System.out.println(docpath + “.docx”);
System.out.println(docpath + “.pdf”);
}

private static class NullOutputStream extends OutputStream
{
@Override
public void write(int b) throws IOException
{
}
}
}

Please find the attached PNG Image and Word and PDF documents created from the above snippet.

Is there anything wrong with the PNG Image? If so, why is the issue not seen in WORD document? The image opens normally in other platforms like Web Browsers, Paint etc
Another interesting fact I observed is : If I save the word document generated from the above snippet to PDF, the saved PDF shows the PNG image without any issue. What is the reason behind this?

Kindly revert with answers for all the queries made.


Thanks,
Akash

Hi Akash,


Thanks for your inquiry. We have tested the scenario with your shared document using Aspose.Words for Java 17.4 and we are unable to replicate the reported issue, sample output is attached here for your reference. It seems JAI is not installed or configured at your end. Please check following system requirement documentation page to install JAI. It will help you to resolve the issue.


Best Regards,

Hi Tilal,

I tested the issue with the new Aspose Java 17.4 library. And it works fine in this case. But again this doesn’t work with Aspose Java 16.7(even with JAI libraries). Could you please share some details around why this issue happens in 16.7 and what changed in 17.4 that makes it work?


Thanks,
Akash Srivastava

Hi Akash,


Thanks for your feedback. It is good to know that you have managed to resolve the issue with Aspose.Words for Java 17.4.0.

Furthermore in reference to your issue cause, please note we maintain a single code base of Aspose.Words. All the fixes and improvements are made in latest version. It seems your issue has been fixed in result of some other fix or improvement in a later version. It is quite difficult to tell you issue reason because we have released 8 versions after 16.7 with number of fixes and improvements.

We are sorry for the inconvenience.

Best Regards,