Cannot display image using inserthtml

Hi,
Few days ago I downloaded an evaluation version of Aspose.Word for evaluation if this product matches to our requirement, and currently I have the following problem:

  1. I have an HTML string:
"..some other HTML tags....<img src='http://servername/images/test1.bmp' border='0' alt='test1.bmp' width='481' height='280' />follows by other HTML tags......"

then I used Inserthtml(the above string) the result is that the HTML displayed correctly except the image is a box and a letter X inside. why I cannot display the image ?

  1. I have problem with left indent using Inserthtml, it didn’t work. I tried <blockquote>…not working as well. can you help ?

Hi

Thanks for your inquiry.

  1. This occurs because Aspose.Words can’t find image. For example try using the following code.
//Create document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//Create HTML string
string someHtml = "<img src='http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg' border='0' />";
//Insert HTML
builder.InsertHtml(someHtml);
//Save document
doc.Save(@"Test009\out.doc");
  1. Please provide me code example. I will investigate this problem and provide you more information.

Best regards.

Alexey,
Thanks for your quick response, I still cannot display the image from the code you gave me, I can see the image if I put the address to the address bar directly (a car) but not with Inserthtml.

Hi
I can’t reproduce this problem on my side. Which version of Aspose.Words do you use? I use the latest version for testing and all works fine.
Best regards.

Alexey,
I am using Aspose.Word version 4.4.3.0 under .Net 2.0.
Thanks,
Ismail.

Hi

I also can’t reproduce this using
Aspose.Words v4.4.3.0. Please try this code for testing.

string URL = "http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg";
//Create web request
WebRequest myWebRequest = WebRequest.Create(URL);
//Get response
WebResponse myWebResponse = myWebRequest.GetResponse();
//Get response stream
Stream receiveStream = myWebResponse.GetResponseStream();
//Create Image from stream and save it on local drive
Image img = Image.FromStream(receiveStream);
string localImgPath = Path.Combine(@"C:\Temp", Path.GetFileName(URL));
img.Save(localImgPath);
//Create document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//Create HTML string
string someHtml = "<img src='file:///"+ localImgPath +"' border='0' />";
//Insert HTML
builder.InsertHtml(someHtml);
//Save document
doc.Save(@"Test009\out.doc");

Hope this helps.

Best regards.

Alexey,
The problem is the <img src=.....> all over the place in the HTML string…

sString="........some HTML .......<img........some HTML again......<img.....some HTML again.......<img.......<img.......";

can be more than 1 images…
so it is not only displaying an image in the Html string, the images can be embedded inside the Html string…
My code is in VB.NET.
Thanks.

Hi

I still can’t reproduce this problem. I tried using the following html

string someHtml = "<p>Some text</p>";
someHtml += "<p><img src='http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg' border='0' /></p>";
someHtml += "<p>Some text</p>";
someHtml += "<p><img src='http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg' border='0' /></p>";

Maybe you
can provide snippet of your html code for testing.

Best
regards.

Alexey,
Try this code:

sHTML="<p>Header.</p><p><br />mytext<br />mytext &gt; mytext &gt; mytext&gt; mytext.</p><p><img src='<A href="http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg">http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg</A>' border='0' /></p><p>mytext.</p><ul><li>mytext&nbsp; ie&nbsp;&nbsp; A3, D ,R </li><li>mytext</li><li>mytext&amp; mytext </li><li>mytext&amp; mytext.&nbsp;&nbsp;<br />(ie. mytext)</li></ul><p><br />mytext.</p><p><img src='<A href="http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg">http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg</A>' border='0' /></p>"
builder.insertHTML(sHTML)

if src='\\myIISserver\d$\inetpub\wwwroot\webpagefolder\images\imagename.bmp' it works but not

with http prefix: src='http://myIISserver/webpagefolder/images/imagename.bmp' is it because evaluation version I can’t get full functionality ?

I found that one of the discussion in the forum about proxy authentication ?

Is the current version accomodate this feature ?

Hi

Thanks for additional information.

  1. Evaluation version of Aspose.Words (without a license specified) provides full product functionality, but it injects an evaluation watermark at the top of the document on open and save and limits the maximum document size to several hundred paragraphs.

  2. No, this feature is not implemented yet. Have you tried to use the following code to get image?

string URL = "http://images.amazon.com/images/G/03/videogames/features/TestDrive_PC_big_2.jpg";
//Create web request
WebRequest myWebRequest = WebRequest.Create(URL);
//Get response
WebResponse myWebResponse = myWebRequest.GetResponse();
//Get response stream
Stream receiveStream = myWebResponse.GetResponseStream();
//Create Image from stream and save it on local drive
Image img = Image.FromStream(receiveStream);
string localImgPath = Path.Combine(@"C:\Temp", Path.GetFileName(URL));
img.Save(localImgPath);

Really, maybe this problem occurs because proxy authentication is required.

Best
regards.

Alexey,
The problem is I don’t know the image address, they are embedded in the html string and they can be different images in each html string (user can insert any images from any webserver in our local network).
If it is a fixed image then your code might work.
so it is hard to extract each image and save it to local.
For temporary solution I replace all occurances of src="http:/webserver/images...." to src="\\webserver\drive\images..." I have to tell users make sure all images stored in the correct image directory, otherwise it won’t display correctly.
The second problem is why leftindent didn’t work ?

builder.ParagraphFormat.ClearFormatting()
builder.Font.Size = 11
builder.Font.Name = "Arial"
builder.ParagraphFormat.LeftIndent = 2.3
builder.ParagraphFormat.KeepTogether = True
builder.InsertHtml(TaskDescription.Text)
builder.InsertParagraph()

i.e: (result in Word)
1.2 Header text
description…
I want to be displayed as:
1.2 header text description…
I have tried leftindent value from 1.X…to 20.X …nothing change in Word.

Hi

Thanks for your inquiry. This occurs because use InsertHtml method. Formatting of Paragraph is imported from HTML. For example if you use the following code then you will get properly formatted result.

builder.Writeln("Header text");
builder.ParagraphFormat.ClearFormatting();
builder.Font.Size = 11;
builder.Font.Name = "Arial";
builder.ParagraphFormat.LeftIndent = 23;
builder.ParagraphFormat.FirstLineIndent = 23;
builder.ParagraphFormat.KeepTogether = true;
builder.Write("Description...........");
builder.InsertParagraph();

Also you can try using HTML formatting. For example

builder.InsertHtml("<p 'margin-left:100px;'>test</p>");

I hope this could help you.

Best regards.

Alexey,
With InsertHtml using ("<p style='margin-left:100px;") not always 100% working.

Hi
What do you mean? Please provide sample document and your code for testing. Also note that inline style of HTML paragraph is supported, but limited to paragraph attributes exported by Aspose.Word.
Best regards.

Original htmlstring=
"<p>The modification will only impact .....</p><p>only support Batch strings up to a length of 10 characters.</p><p>will display expiry date format of DD/MM/CCYY....</p><p>Operator will be able to enter..... </p>"

then I added string from you:

"<p style='margin-left:100px;'>"   +  the above string + "</p>"

finally I used InsertHtml("<p style='margin-left:100px;'>" + the above string + "</p>")

and the indent didn’t work.
Thanks.

Hi

I mean that
you should specify margin-left for each paragraph. For example see the
following code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string htmlstring = "<p>The modification will only impact .....</p><p>only support Batch strings up to a length of 10 characters.</p><p>will display expiry date format of DD/MM/CCYY....</p><p>Operator will be able to enter.....</p>";

//Insert Left Indent
htmlstring = htmlstring.Replace("<p>", "<p style='margin-left:100px;'>");
builder.InsertHtml(htmlstring);
//Save document
doc.Save(@"Test009\out.doc");

Hope this helps.

Best
regards.

Alexey,
It worked…Thanks again for your help.