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

Free Support Forum - aspose.com

How to write html image to word document using aspose.words

iam getting html text and image in string builder in below code…By using oDocBuilder.InsertHtml iam writing html text to word document…now how to write Html image to word document using Aspose.words?

StringBuilder oSB="<p>Test Global....!! update again<input style=\"width: 81px; height: 66px\" type=\"image\" alt=\"\" src=\"http://ust/SelectImage.aspx?ImageID=29\" /></p>"
var oCurrentDoc=new document;
oDocBuilder = new DocumentBuilder(oCurrentDoc);  
oDocBuilder.InsertHtml(oSB.ToString());

how to write html image and content to word document using aspose.words?

Hi

Thanks for your inquiry. Please make sure that the image exists on the following path. Maybe you should use full path instead of relative.

I use the following code for testing:

// Create document and DocumentBuidler object
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert HTML.
string html = @"<table><tr><td><img src='C:\Temp\TestImg.jpg' /></td></tr></table>";
builder.InsertHtml(html);

doc.Save("C:\\Temp\\out.doc");

Best regards,

Actually my question is by using builder.InsertHtml(html) is it possible to write html image to word document?..IS Inserthtml works ONLY to write html text to word document?..Actually my html string looks like below line…here we are getting imge tag in this type <input type="image" ...> …is it possible to write this way to word document…i mean iam notgetting as <img src='C:\Temp\TestImg.jpg' /> in this model…see my below code can u pls work on this type of html string…here iam getting image from url…try in this model as same as my code and pls let me know…

string html ="<p>Test Global....!! update again<input style=\"width: 81px; height: 66px\" type=\"image\" alt=\"\" src=\"http://ust/SelectImage.aspx?ImageID=29\" /></p>"

But by using Insert html just it is writing html text to wrod document not html image by using above html string …can u pls try with tht string which i gave above …

Hi

Thanks for your request. Sure, it is possible to insert images using InsertHtml method. But you should note that path to the image should be valid and accessible.

Best regards,

Dear Alexey Noskov,
We are currently evaluating aspose words s/w, actually we are trying generate a pdf from html script from using java, we are using below code but the pdf or word doc is not really showing the image.
but if I create a html from the html code, and open in browser it shows image, that proves that there is no image availability issue, please suggest

Document doc = new Document(getPathToTemplateDoc());
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<table> <tr><td><img src='C:\\back.JPG' /></td></tr></table>");

could you please check if aspose words doesnt support this feature?

Many Thanks
Ganesh

Hi

Thanks for your request. Sure, this feature is supported by Aspose.Words. I used the following code for testing on my side and the image is properly inserted into the document:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<table><tr><td><img src='C:\\Temp\\logo.png' /></td></tr></table>");
doc.save("C:\\Temp\\out.doc");

There must be a problem with permissions on your side.

Best regards,

Hi Ganesh,
Thanks for inquiry. Aspose.Words does support adding images in documents using html script. Following code works for me:

//Path to template file
String path = "D:\\Aspose\\input\\";
//Load template file in document object 
Document doc = new Document("D:\\Aspose\\input\\"+"InputFile.docx"); 
DocumentBuilder builder = new DocumentBuilder(doc); 
builder.insertHtml("<table> <tr><td><img src='D:\\Aspose\\input\\Logo.jpg' /></td></tr></table>");
// Save document as pdf
doc.save(path + "out.pdf");

Regards,
Nabeel Ahmad

Hi Alexey& Nabeel,
Thanks a lot for your quick response, I missed a very small point ‘double back slash’ :-(, now my pdf is showing images absolutely fine. Many thanks for your support.

-Ganesh