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

Free Support Forum - aspose.com

Custom styles

Hi,

I was reading the documentation http://www.aspose.com/docs/display/wordsjava/Font and specifically, the following example:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, “MyStyle1”);
style.getFont().setSize(24);
style.getFont().setName(“Verdana”);
style.getParagraphFormat().setSpaceAfter(12);

// Create a list and make sure the paragraphs that use this style will use this list.
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);

// Apply the paragraph style to the current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln(“Hello World: MyStyle1, bulleted.”);

// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get(“Normal”));
builder.writeln(“Hello World: Normal.”);

builder.getDocument().save(getMyDir() + “Lists.ParagraphStyleBulleted Out.doc”);

Can you please tell me how do you define the MyStyle1 custom style. I can see how you use it by adding it in the Styles of the paragraph, but how you define what MyStyle1 is?

Ok, maybe I’m blind!! The answer is apparent on the example you provided, but I cannot delete the current post.

Hi Giorgos,


Thanks for your inquiry. The StyleCollection.add method creates a new user defined style and adds it the collection. You can create character, paragraph or a list style.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.