Convert html to word doc question

Hi,

I am evaluating Aspose see whether it can replace our existing code and improve the performance when creating word doc.

I need to take HTML content combined with images, and encode this in
some way that it can be presented for reporting or download purposes in a
format that can be loaded as single file in Word or
by Internet Explorer.

Currently our application use CDO.MessageClass and IBodyPart to create MHT string, and html image src string is replaced with cid:imagexxx and images are embedded to the MHT content. However, this is quite slow when dealing with lots of data with large amount of images.

I tried to rewrite this using Aspose today and come up with several questions, hopefully someone can guide me through this:

  1. I used DocumentBuild InsertHtml to directly insert the html, without change the src to cid reference. Given that the image location is set to public accessible, the word document can show the images.

Are these images embedded to the word doc? I think so as I make the image locations not public accessible and reopen the word doc, the images still visible to me. Could you confirm this please?

  1. The image src is actually point to a image ashx handler with querystring to specify width, e.g. ImageHandler.ashx?width=120. However, after using InsertHtml and download the document, the image present as its original size. How to make sure it’s displayed as the required size (120 width in this example).

  2. Our html contains styles, such as mso-level-number-format:bullet; also xml to default the zoom level using <w:Zoom>90</w:Zoom> etc.

When we using CDO and build the MHT string, when open the downloaded file, the style is correct and zoom level as well. However, if using Aspose to insertHtml then I use wordDoc.Save(Response, “Aspose.Words.Demos.doc”, ContentDisposition.Inline, null); to output the file, after open the downloaded file, the style is missing and the default zoom level is not affected as well.

Hope someone can provide some help here.

Thanks

Hi

Thank you for your interest in Aspose.Words.

  1. Yes, images are embedded into the document.
  2. You can specify size of the image in your HTML, like shown below:
<img width="120" height="120" src="http://www.aspose.com/Images/aspose-logo.jpg" />
  1. These styles and settings are not native HTML features. This is kind of MS Word magic, which used to roundtrip HTML documents.

Best regards,

Thank you very much for the information.

For 3, I will rewrite the code for the style, but for default zoom level <w:Zoom>90</w:Zoom>, what is the alternative for this?

Thanks

Hi

Thanks for your request. You can specify zooming programmatically. Please follow the link for more information:
https://reference.aspose.com/words/net/aspose.words.settings/viewoptions/zoompercent/
Hope this helps.
Best regards.

Really helpful indeed, thank you very much!

Hi,

I have two more questions hope you can help.

I noticed that in our html, there are lots of <li> items without <ul> tag. Originally when using CDO this is output as circle bullet points. But in Aspose it won’t show as bullet point unless I surround li items with ul tag and specify the list-style-type:circle. However, this is difficult as content can just input by users without ul tag.

I tried to add list-style-type:circle; to the <li> tag, but seems not parsed by Aspose. Is there a walkaround for this?

All h2 html elements are rendered in word doc using heading 2 style whic is Italic by default, is it possible to change the default heading 2 style to not Italic?

Thanks

Hi

Thanks for your request.

  1. I managed to reproduce the problem with LI tags without OL/UL. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
  2. I think it would be enough just change Heading 2 style, as shown below:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml("<h2>This is heading2 text</h2>");
doc.Styles[StyleIdentifier.Heading2].Font.Italic = false;
doc.Save(@"Test001\out.doc");

Hope this helps.
Best regards,

Thank you very much, look forward to the patch for issue 1.

Cheers

Hi, My company has purchase Aspose total recently, regarding the issue mentioned on this post https://forum.aspose.com/t/62879, do you know roughly when the fix will be available? We are very keen on using Aspose on our application. Cheers

This message was posted using Email2Forum by alexey.noskov.

Hi

Thanks for your inquiry. Unfortunately, it is difficult to provide you any reliable estimate regarding this issue at the moment. We will let you know once there is some progress with this issue.
Best regards.