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

Free Support Forum - aspose.com

How to set paragraph styles for default Headings?

Team,

I am using Aspose latest version for document conversion. I am trying to set document default paragraph ( Noraml, Heading1, Heading2, Heading3, … ) styles like below

Document doc = new Document();
ParagraphFormat paraFmt = doc.getStyles().get(1).getParagraphFormat();
// trying to get and set styles for Heading 1
Font font = doc.getStyles().get(1).getFont();
font.setSize(11);
paraFmt.setAlignment(1);
doc.save(MyDir + "out.docx");

paraFmt is returning Null. Am i doing anything wrong ? How to set default styles for Normal, Heading1 to 6 ?

Thanks

Hi Anbu,

Thanks for your inquiry.

In your case, I suggest you please use the StyleCollection.getByStyleIdentifier method to get the built-in styles. Please note that empty document does not contain the styles e.g Heading 1, Heading 2 etc. When you try to get built-in style by using StyleCollection.getByStyleIdentifier method and the style does not exist in the document, Aspose.Word copies this style into StyleCollection. Please see the following code snippet for your kind reference.

Document doc = new Document();
ParagraphFormat paraFmt = doc.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1).getParagraphFormat();
Font font = doc.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1).getFont();

Hope this answers your query. Please let us know if you have any more queries.