Setting font in a document using the DocumentBuilder

Hi,
I came across this property in the DocumentBuilder which is getFont().When I tried doing the following, the font didn’t get changed. Is there a way I can set the font?

Document doc = execute("SomeFileName");
DocumentBuilder builder = new DocumentBuilder(doc);
Font font = builder.getFont();
String fontName = font.getName(); //Here fontName gets a string named "Arial"
font.setName("Arial"); // Does this setting change the font?

I do this, but the resultant document has text with Calibri as the font. What do I do to change the font?
Regards,
Pavithra V.S

Hi

Thanks for your inquiry. If you would like to change font of the entire document, you should loop through all nodes and change font. You can use DocumentVisitor to achieve this. Here is code example:

String fontName = "Tahoma";
// Open document
Document doc = new Document("C:\\Temp\\template.doc");
// Create font changer
FontChanger changer = new FontChanger(fontName);
// Change font of the entire document
doc.accept(changer);
// Also we can loop through all styles in the docuemnt
// And change font of styles
for (Style style: doc.getStyles())
{
    if (style.getFont() != null)
        style.getFont().setName(fontName);
}
// Save output document
doc.save("C:\\Temp\\out.doc");

FontChanger class is attached.
Hope this helps.
Best regards.