Thanks for additional information. I am looking into the requirement and will share the details shortly.
Will supports API call in 'Aspose.Words for Cloud API Reference' for get Document Styles for Microsoft Docx as it do as in java library?
I am afraid there is no simple rule. Aspose.Words calculates "margin-xxx" values of each element. Then removes styles that duplicate values applied from other sources (the default stylesheet or the stylesheet generated by Aspose.Words itself). Then tries to combine individual "margin-xxx" declarations to shorthand "margin" declarations. And then writes the result to the document.
In most cases "margin-left" and "margin-right" are exported from ParagraphFormat.LeftIndentLeftIndent and ParagraphFormat.RightIndentRightIndent. But they may be adjusted if HtmlSaveOptions.AllowNegativeIndent=false (which is the default) in order to prevent paragraph text from overflowing the browser window and being clipped.
Also, we adjust these values for list item paragraphs that are being exported to native HTML list items (<li> elements). This is required because HTML list items have their own default margins and paddings that affect positioning of list item text.
Please check some margin examples below, how Aspose.Words calculates the margins and write in HTML.
margin:72pt: all four margins are same because page margin is 1 inch for each side and exported because of the "ExportPageMargins=true" option.
margin:0pt 36pt 12pt: marign top=0, left=right=36 and bottom=12, margins of of the corresponding paragraph.
margin-top:0pt; margin-bottom:12pt: ParagraphFormat.LeftIndentLeftIndent and ParagraphFormat.RightIndent values are zero. Aspose.Words didn’t write “margin-left:0” and “margin-right:0” because it had calculated that these are applied to this <p> element by default. We try to avoid writing CSS that would duplicate styles from other sources (for example, from the default CSS stylesheet used by browsers)
margin:0pt: <ol> is needed to zero vertical margins of this element. By default, <ol> elements have 1em top and bottom margins. "margin-top:0; margin-bottom:0" would do here, too. But we write "margin:0pt" for historical reasons.
However, can you please tell us why you need the margin calculation? So we can guide you exactly.
Thank you for your answer.
I try selected different styles for different paragraphs (these data I get from aspose - format by each paragraph) and match them with styles that I get from aspose in html, but I receive fail in most cases because the margins that I take from the paragraph formats do not match the margins that come in html.
<p style="margin:0pt 36pt 12pt; text-align:justify; line-height:12pt"><span style="font-family:'Times New Roman'; font-size:12pt; font-weight:bold; text-decoration:underline">RESOLVED</span><span style="font-family:'Times New Roman'; font-size:12pt; font-weight:bold">:</span><span style="font-family:'Times New Roman'; font-size:12pt; -aw-import:spaces">  </span><span style="font-family:'Times New Roman'; font-size:12pt">That a copy of the Certificate of Incorporation of the Company as filed with the Delaware Secretary of State and bearing the file stamp and certification of the Delaware Secretary of State, and attached hereto as </span><span style="font-family:'Times New Roman'; font-size:12pt; text-decoration:underline">Exhibit</span><span style="font-family:'Times New Roman'; font-size:12pt; text-decoration:underline"> </span><span style="font-family:'Times New Roman'; font-size:12pt; text-decoration:underline">A</span><span style="font-family:'Times New Roman'; font-size:12pt">, is hereby accepted and ratified.</span></p>``` fragment json describing paragraph format
I usually build such mapping:
right_indent -> margin-right,
left_indent -> margin-left,
space_before -> margin-top,
space_after -> margin-bottom
In result I get margin-right: 36pt;margin-left: 36pt;margin-top: 0pt; margin-bottom: 0pt; and it not equal margin:0pt 36pt 12pt;
Can you please confirm how you are getting margin-bottom. As I see it is 12 pt in HTML, Word document and paragraph format as well.
Sorry, I made typo, here I don’t have question, but my question why one margin (and not 4 margins: margin-right: 36pt;margin-left: 36pt;margin-top: 0pt; margin-bottom: 12pt; ), I get fail because different strings.
Thanks for the additional details. You know margin is a shorthand property of margin-top, margin-right, margin-bottom and margin-left. So where possible, we are using it to shorten the code. For example margin:72t and margin:0pt 36pt 12pt.
I understood, but you have algorithm that set margin short or margins with specify side. I’d like to use like algorithm for my tasks.
As already stated above, Aspose.Words calculates all “margin-xxx” values, but writes only those that don’t duplicate values inherited from other sources. If some of the written values are same and can be represented with the shorthand property “margin”, Aspose.Words uses the shorthand. Otherwise, it writes individual properties.
Since individual calculated margin values depend on the structure of the document, there is no simple rule like “always write shorthand for lists” or “don’t write horizontal margins for paragraphs”.
Furthermore, in general you cannot match the CSS and Paragraph formatting. Because there is no 1-to-1 mapping between paragraph formatting and CSS styles. We have to adjust the CSS in certain cases in order to preserve the look of the document and compensate for differences between HTML and MS Word rendering rules.