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

Free Support Forum - aspose.com

HTML to WORD margin control with .net Aspose.words

Hello <?xml:namespace prefix = o />

My name Bill Pecor from iCompass technologies, and was hoping you could help me out or forward this email to someone who can.

I have two issues I have been fighting with:

1. Setting margins for a word document where I am converting from html to word

2. Keeping the image size set in the html

Please see attached documents and Note

Both have been created using the same HTML input as seen below

Bill


This message was posted using Email2Forum by ShL77. (attachment)

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

Thanks for your request. Unfortunately, it is very difficult to produce Word document that looks the same as HTML. Some HTML features are not supported yet. Please see the following document to learn more about restrictions

http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry108980.aspx

Regarding your document, I create three issues in our defect database.

Issue #7232 - Support color names like ‘lightgrey’ during HTML import.

As a workaround, you can use color code like ‘#ff00ff’.

Issue #7233 - Support ‘style’ attribute of ‘img’

As a workaround, you can use width and height attributes to specify image size. Here is an example:

<img height="10" width="10" src="test.jpg" />

Issue #7234 - Support inheriting styles from parent objects.

I will notify you as soon as these issues are fixed.

Best regards.

Hello,<?xml:namespace prefix = o />

Thanks you for your response. I have figured out my margin issue and I have also from your email been able to create a work around for height and width of images and for other i have added my solution below for your forum.

I was also wondering if you could add for future release support for


tag

or style text-decoration:underline

or style border-bottom: ...

and any information on how to get a line to show would be great thanks.

Bill

Here is my solution .NET C#:

//aspose word work around as images sizes are not taken from style tags

private string HTMLtoWordImageSizing(string strHtml)

{

// check style tags for images and change them to height and width

Regex regImageTag = new Regex(@"]*>(.*?)", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Regex regImgTag = new Regex(@"<img ", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Regex regStyleHeight = new Regex(@"height: \b[^;]*", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Regex regStyleWidth = new Regex(@"width: \b[^;]*", RegexOptions.IgnoreCase | RegexOptions.Compiled);

MatchCollection mcImageStr;

Match mHeight;

Match mWidth;

// Get matches of pattern in text

mcImageStr = regImageTag.Matches(strHtml);

string strImage, height, width;

// Iterate matches

for (int ctr = 1; ctr <= mcImageStr.Count; ctr++)

{

strImage = mcImageStr[ctr - 1].Value;

mHeight = regStyleHeight.Match(strImage);

mWidth = regStyleWidth.Match(strImage);

height = mHeight.Value.ToLower().Replace("height: ", "").Replace("px", "").Replace("pt", "");

width = mWidth.Value.ToLower().Replace("width: ", "").Replace("px", "").Replace("pt", "");

strHtml = regImgTag.Replace(strHtml, "<img height='"</SPAN> + height + <SPAN style="COLOR: rgb(163,21,21)">"' " + "width='" + width + "' ");

}

return strHtml;

}


This message was posted using Email2Forum by ShL77.

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

Thank you for your request.

Everything you mention is supported. Please try importing this short HTML document:

Underlined text

Horizontal rule:


Border at bottom:

According to #7234 some style attributes are not applied if placed on different nodes. In particular, text-decoration is a font attribute and in the current implementation Aspose.Words takes it only from span, not from p. Border attributes should be placed at p. (MS Word also supports fonts with borders but they cannot be specified only on one side.)

If you are not sure why something is not imported you can try creating an MS Word document with the same feature and export it to HTML using Aspose.Words. Usually we import the same way as we export. This is the roundtrip principle and it works for almost all features. (Every rule has exceptions. In particular, we export but don’t import image list bullets.)

You can also refer to this spreadsheet to know what is supported on HTML import/export:

http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry108980.aspx

P. S. Would you please post your replicas directly to the forum? This way is more convenient.

Best regards,

Hi! That’s me again.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Regarding #7232 there is some progress. Currently we parse the following color values:

1. Long RGB codes starting with # like this: #RRGGBB

2. Long RGB codes starting with rgb like this: rgb(100, 100, 100)

3. Color names recognized by System.Drawing.Color.FromName. They all are the static members of System.Drawing.Color.

If you change from “lightgrey” to “lightgray” it is recognized. In the future we plan to support more color code types, in particular short color codes like #a8f on import.

Regards,

The issues you have found earlier (filed as 7232) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by alexey.noskov.

The issues you have found earlier (filed as WORDSNET-2020) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)

The issues you have found earlier (filed as WORDSNET-2021) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(32)