Free Support Forum - aspose.com

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....

test1.bmp

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 ?

2. I have problem with left indent using Inserthtml, it didn't work. I tried

...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 = "";

//Insert HTML

builder.InsertHtml(someHtml);

//Save document

doc.Save(@"Test009\out.doc");

2. 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 = "";

//Insert HTML

builder.InsertHtml(someHtml);

//Save document

doc.Save(@"Test009\out.doc");

Hope this helps.

Best regards.

Alexey,

The problem is the 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 and all works fine on my side.

string someHtml = "

Some text

";

someHtml += "

";

someHtml += "

Some text

";

someHtml += "

";

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

Best regards.

Alexey,

Try this code:

sHTML="

Header.


mytext
mytext > mytext > mytext> mytext.

mytext.

  • mytext  ie   A3, D ,R
  • mytext
  • mytext& mytext
  • mytext& mytext.  
    (ie. mytext)


mytext.

"

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 ?

http://www.aspose.com/Community/Forums/thread/60796.aspx

Is the current version accomodate this feature ?

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

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 style='margin-left:100px;'>test

");

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.

Alexey,

Original htmlstring=

"

The modification will only impact .....

only support Batch strings up to a length of 10 characters.

will display expiry date format of DD/MM/CCYY....

Operator will be able to enter.....

"

then I added string from you:

"

" + the above string + "

"

finally I used InsertHtml(

"

" + the above string + "

")

and the indent didn't work.

<?xml:namespace prefix = o />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 = "

The modification will only impact .....

only support Batch strings up to a length of 10 characters.

will display expiry date format of DD/MM/CCYY....

Operator will be able to enter.....

";

//Insert Left Indent

htmlstring = htmlstring.Replace("

"

, "

"

);

builder.InsertHtml(htmlstring);

//Save document

doc.Save(@"Test009\out.doc");

Hope this helps.

Best regards.

Alexey,

It worked......Thanks again for your help.