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

Free Support Forum - aspose.com

Insert html image in word document using docbuilder not working

see my below code iam not able to write html image into word document and also in pdf?
when i kept image tag src as c:\winter.jpg it is working …if i kept image tag src as url i mean http://wkt002:20649/SelectImage.aspx?ImageID=8 it is not wokring in this case…pls help me out…

var oImgChkDocument = new Document();
DocumentBuilder builder = new DocumentBuilder(oImgChkDocument);
string stylesheetPath = @"C:\Footnote.css";
StringBuilder sbHfnContent = new StringBuilder();
string value = "<img class='' height='101' width='144' src='http://wkt002:20649/SelectImage.aspx?ImageID=8' />";
sbHfnContent.Append(value);
sbHfnContent.Insert(0, "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></meta></head>" +
"<link href=\"" + stylesheetPath + "\" type=\"text/css\" rel=\"Stylesheet\" />" + "<body>");
sbHfnContent.Append("</body></html>");
sbHfnContent.Replace("border=\"1\"", "border=\"0\"");
builder.InsertHtml(sbHfnContent.ToString());
oImgChkDocument.Save(@"C:\htmlimage.docx");
oImgChkDocument.Save(@"C:\out.pdf");

i tried by downloading latest aspose.words dll in the given below site even though it is not working…
https://forum.aspose.com/t/56150

Hi,

Thanks for your inquiry. Unfortunately, I was unable to reproduce this issue on my side. Could you please create and attach here a simple little console application that enables me to reproduce this issue on my side? I will investigate the issue further and provide you more information.

Best Regards,

Please see my below code iam unable to write image in pdf…pls see my attached pdf

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string html = @"<img src='http://wht002:20649/SelectImage.aspx?ImageID=8' alt='test image' width='178' height='129' />";
builder.InsertImage(html);
doc.Save(@"C:\work.pdf"); 

Hi,
Thanks for the additional information. I have made a few corrections to your code. Please try using the following code snippet and let us know how it goes on your side?

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string html = @"<p><img src='http://cdn.aspose.com/homepage/images/logo.png' alt='Aspose logo'width='230' height='70' /></p>";
builder.InsertHtml(html);
doc.Save(@"c:\temp\out.pdf");

I hope, this will help.
Best Regards,

i tried in the way wht u said it is not working…see atatched pdf…pls help me out…when i pasted tht image src path in browser separately it was working fine…when i kept here in code it was not working fine…

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string html = @"<img src='http://www.orkutbuddy.com/albums/glitters/cartoon/cartoons_20_63_.gif alt='test image' width='178' height='129' />";
builder.InsertHtml(html);
doc.Save(@"C:\work.pdf"); 

even i tried with ur url http://cdn.aspose.com/homepage/images/logo.png it is not working…see sample pdf attached …if i open ur url in browser i mean in separate window it was working fine…pls help me out…wht was the problem iam not getting…

Hi,
Thanks for your inquiry.
While using Aspose.Words v11.4.0 and the following code, I was unable to reproduce this issue on my side. I have attached the PDF file (out.pdf) i.e. generated on my side here for your reference.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string html = <span style="color:#A31515">@"<img src='http://cdn.aspose.com/homepage/images/logo.png' alt='Aspose logo'width='230' height='70' />";            
builder.InsertHtml(html);
doc.Save(<span style="color:#A31515">@"c:\temp\out.pdf");

Moreover, Could you please double check if you are using the latest version (11.4.0)? You can dynamically check if you’re referencing the correct DLL by using the following code snippet:

System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (System.Reflection.Assembly assembly in assemblies)
{
    System.Reflection.AssemblyName assemblyName = assembly.GetName();
    if (assemblyName.Name.Contains("Aspose.Words"))
        Console.WriteLine("Aspose.Words Version Number: " + assemblyName.Version.ToString());
}

Also, you can download the latest version from the following link:https://downloads.aspose.com/words/net

If we can help you with anything else, please feel free to ask.
Best Regards,

see my attached sample solution u will get an idea …pls have a look…

Hi,


Thanks for your patience. I have attached the PDF file (sample.pdf), i.e. generated on my side, here for your reference.

Best Regards,

thanks a lot…

Hi,


Thanks for your request. I have removed my post now.

Best Regards,