Free Support Forum - aspose.com

Header Styles

I am having an issue with the Heading styles. Right now I am setting a portion of my text to use Heading Style 1 (code below), which seems to be working but Heading 1 is not defined as anything for the document. Is there a way to set the styles for Heading1 so it knows what it should look like.

-- sectionHeader is just plain text
-- GetTextStyleIdentifier just returns StyleIdentifier.Heading1

...
string textStyle = "HEADING1";
paragraph.ParagraphFormat.StyleIdentifier = ASPOSEHelpers.GetTextStyleIdentifier(textStyle);
docBuilder.Write(sectionHeader);
...

when i click on the heading in the document it says it is set to Heading1 but it remains as Arial 10pt and just Bold's it. Thanks in advance. If you need anything else, let me know.

Doug

If you set paragraph style to Heading 1, then the text in the paragraph will look according to formatting defined in the Heading 1 style. Unless of course you have explicit formatting assigned to runs in the paragraph.

So, you can access the style itself via the Document.Styles collection.

Style style = Document.Styles[StyleIdentifier.Heading1];

or you can access the style directly from the paragraph object I believe

Style style = paragraph.ParagraphFormat.Style;

It will give you the same style object that you can examine or modify.

Note, for the text in the paragraph to look like the assigned style, it should not have explicit formatting that overrides the style formatting.

If you have a run in a paragraph formatted as Arial 10 pt (I mean Run.Font.Size = 10), then setting paragraph style will not change the font size of the run. You have to clear formatting from the run first using Run.Font.ClearFormatting.

Thanks, I'll give that a try. I do believe I set the font to arial and 10pt on my document object in the beginnning so that is probably causing the issue. The ClearFormatting should do the trick and then I can reset it.

Doug