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

Free Support Forum - aspose.com

Set Direct Font Formatting (Font Family Size) on Text in Whole Word DOCX Document using Document Builder Java

We are unable to set font family of whole document including html, paragraphs, headings, tables, barcodes using DocumentBuilder of Aspose.Words in Java.

Tried acheiving it by following code but this does not seem to work:

// Set Font Family
com.aspose.words.Style style = doc.getStyles().add(com.aspose.words.StyleType.PARAGRAPH, “MyStyle”);
style.getFont().setName(“Arial”);
builder.getParagraphFormat().setStyle(style);

builder.getFont().setName(“Arial”);

Please suggest solution to the problem.

Thanks.

@mussab,

Just before saving the document, you can use the following simple Java code to apply direct Font formatting on text in Word document:

Document doc = new Document("C:\\Temp\\input.docx");

for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)) {
    run.getFont().setName("Arial");
    run.getFont().setBold(true);
}

doc.save("C:\\Temp\\awjava-20.9.docx");

@awais.hafeez

Thanks, it worked.