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

Free Support Forum - aspose.com

Aspose.words - DocumentBuilder.insertHTML does not paint the image

Hi,

I have this issue with DocumentBuilder.insertHTML() api.
When i try to insert a HTML containing the image. it does not paint the Image instead gives a cross sign.

Here’s a image on this server -
https://plm.sungard.com/ImageRenderer?ImageID=3003121

If you hit this on the web url, you will get the image. However, when you try inserting this through Aspose.words, it wont give the image. I tried writing this code. It does not work.

File w_file = new File(“C:/Documents and Settings/akhan/Desktop/Print.doc”);
DocumentBuilder w_bldr = new DocumentBuilder();
Document w_doc = w_bldr.getDocument();
String w_txt = “

<img src=“https://plm.sungard.com/ImageRenderer?ImageID=3003121” alt=”" width=“178” height=“129” />

";

w_bldr.insertHtml(w_txt);
w_doc.save(“C:/Documents and Settings/akhan/Desktop/Print.doc”);

Please help me out with this. I am also attaching the word that I get

Regards,
Aslam




Hi Aslam,


Thanks for your inquiry.

While using your code and the latest version of Aspose.Words i.e. 10.5.0, I was unable to reproduce this issue on my side. However, I would like to suggest you the following link for downloading and using the latest version of Aspose.Words:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

Moreover, to insert a picture inside Word document via HTML, please see the following code snippet that worked for me:

Document doc = new
Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// approach 1
string html = @"

"
;
builder.InsertHtml(html);

// approach 2
builder.InsertImage(https://plm.sungard.com/ImageRenderer?ImageID=3003121,
178, 129);

doc.Save(@“c:\test\imageInDoc.doc”);

I hope, this will help.

Best Regards,

Hi Awais,

I tried the insertImage thing it gave the following error.

Exception in thread “main” java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:607)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:278)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1296)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at java.net.URL.openStream(URL.java:1035)
at asposewobfuscated.of.aI(PalSystem.java:88)
at com.aspose.words.DocumentBuilder.insertImage(DocumentBuilder.java:1186)
at com.aspose.words.DocumentBuilder.insertImage(DocumentBuilder.java:1092)
at com.tufan.digite.utils.Test.main(Test.java:20)

Regards,
Aslam

Hi Aslam,

Thank you for additional information. As I can see from stack trace the issue is not related to Aspose.Words. There is something with connection to the site where the image is. Maybe your firewall blocks the request. But anyways there is no problem in Aspose.Words here.

Best regards,

Hi,

Thanks for your post. I am facing same issue. In localhost aspose is able to write image on docx file. But when i deploy the application on IIS. it is making cross sign in place of image.Kindly advise some possible solutions. Thanks

Hi,


Thanks for your inquiry. Apparently, it seems that when the website is deployed to IIS, the path to the image is not resolving correctly. Please try using HttpRequest.MapPath Method to convert virtual paths to absolute ones.

Moreover, if the issue is still occurring, could you please share the code you are getting problems with here for testing. I will investigate the issue on my side and provide you more information.

Best Regards,