Set Default Font Family, Size & Default Paragraph Format for Entire Word Document using Java

Hi,

I am using Aspose word for java. I have created a new Document, for which i have to set a default font family. I have set some default paragraph formats to the document as

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.removeAllChildren();
builder.getParagraphFormat().setSpaceAfter(12);
builder.getParagraphFormat().setSpaceBefore(12);

Like this i have to set the default font-family as calibri and font-size as 11pt.Please guide in doing this.

Hello,
Thanks for your request. If you need to change font of the whole document, you can try using the technique as described here:

But in your case it would be enough just change font of the normal style in your document.

// Open document.
Document doc = new Document("in.doc");
// Change font fon the normal style.
Style normal = doc.Styles[StyleIdentifier.Normal];
normal.Font.Name = "Arial";
normal.Font.Size = 10;

Hope this helps.

Hi,
Thanks for your reply. But I couldn’t find the method Styles for document object(doc) in my Aspose word for java API(using 4.2.0 jar). Will you provide me some sample java code for my task.

Oh, sorry, forgot to clarify. That it concerns a new version of our product 10.0. We recommend you upgrade to it. This is totally outoporting .net version. You can download it from here.

I have upgraded. But still couldn’t find the method doc.Styles. Is this API belongs to aspose words for java 10.0.

here is my code,

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.removeAllChildren();
Style normal = doc.Style[StyleIdentifier.NORMAL];

Correct me if am wrong anywhere.

Here it is:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.removeAllChildren();
Style normal = doc.getStyles().get(StyleIdentifier.NORMAL);