Free Support Forum - aspose.cloud

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?


#21

@Anatoliy,

Thanks for additional information. I am looking into the requirement and will share the details shortly.


#22

@Anatoliy

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.


#23

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.
For example:

fragment 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">&#xa0; </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">&#xa0;</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

{
“id”: 1468,
“paragraph_id”: 1273,
“add_space_between_far_east_and_alpha”: true,
“add_space_between_far_east_and_digit”: true,
“alignment”: “Justify”,
“bidi”: false,
“drop_cap_position”: “None”,
“first_line_indent”: 0,
“keep_together”: false,
“keep_with_next”: false,
“left_indent”: 36,
“line_spacing”: 12,
“line_spacing_rule”: “AtLeast”,
“lines_to_drop”: 0,
“no_space_between_paragraphs_of_same_style”: false,
“outline_level”: “BodyText”,
“page_break_before”: false,
“right_indent”: 36,
“space_after”: 12,
“space_after_auto”: false,
“space_before”: 0,
“space_before_auto”: false,
“style_identifier”: “User”,
“style_name”: “Resolution”,
“suppress_auto_hyphens”: false,
“suppress_line_numbers”: false,
“Widow_control”: true,
“created_at”: “2019-08-23T06:45:19.556Z”,
“updated_at”: “2019-08-23T06:45:19.556Z”
}```

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;


#24

@Anatoliy

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.


#25

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.

BR,
Anatoliy


#26

@Anatoliy

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.


#27

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.

BR,
Anatoliy


#28

@Anatoliy,

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.