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

Free Support Forum - aspose.com

insertImage(java.lang.String fileName) diff between .doc and .docx output (java)

When I create a document and insert an image from a url and write it as a .doc the document looks just fine.

Do I change the .doc to .docx format the image is inserted/shown as a String value…



Do I do something wrong or is this a bug?

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I can’t reproduce this issue in my side. I used the following code for testing.

//Open the document and create DocumentBuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//insert image

builder.insertImage("http://www.aspose.com/Images/aspose-logo.jpg");

//Save output doc

doc.save("C:\\Temp\\out.docx", SaveFormat.DOCX);

Could you please let me know how to reproduce the issue?

Best regards.

Apologies for the late reply. I was forced to work on something else but here it is.



I have the following piece of code:



public void js_insertImage(Object image) {

try {

if (image != null) {

if (image instanceof String && !Utilities.isNullOrEmpty(image)) {

builder.insertImage((String) image);

} else if (image instanceof byte[]) {

builder.insertImage((byte[]) image);

}

}

} catch (final Exception e) {

Log.error(e.getMessage());

}

}



The image inserted comes from a link “media:///logo_it2be.png”.



The .doc and .docx documents are attached.



One thing that could be of importance. I test with Word 2008 on the mac. I can not test for Windows…



Thanks,



Marcel

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Your DOCX document looks good. Image is displayed correctly. I suppose you see the following instead of image:

{ INCLUDEPICTURE \d "ooxWord://word/media/image1.png" \* MERGEFORMATINET }

If so you should just press Alt+F9 after opening DOCX document to hide Field codes in the document.

Hope this helps.

Best regards.

Wow, do I feel stupid :slight_smile:



That was it, thank you!