How to set the font size of the entire document using Java

Document document = new Document(mFilePath);
Paragraph paragraph = new Paragraph(document);
paragraph.getParagraphFormat().getStyle().getFont().setSize(50);

I use this method to adjust the font size, I don’t know if it is correct。
This method is only valid for some documents. Some documents are invalid。
test2.zip (406.3 KB)

@lingengliang

Please use the following code example to change the font name and size of whole document. Hope this helps you.

Document doc = new Document(MyDir + "test2.doc");
FontChanger changer = new FontChanger();
doc.accept(changer);

doc.save(MyDir + "output.docx");

public class FontChanger extends DocumentVisitor
{
///
/// Called when a FieldEnd node is encountered in the document.
///
public int VisitFieldEnd(final FieldEnd fieldEnd)
        {
        //Simply change font name
        ResetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a FieldSeparator node is encountered in the document.
///
public int VisitFieldSeparator(final FieldSeparator fieldSeparator)
        {
        ResetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a FieldStart node is encountered in the document.
///
public int VisitFieldStart(final FieldStart fieldStart)
        {
        ResetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a Footnote end is encountered in the document.
///
public int VisitFootnoteEnd(final Footnote footnote)
        {
        ResetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a FormField node is encountered in the document.
///
public int VisitFormField(final FormField formField)
        {
        ResetFont(formField.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a Paragraph end is encountered in the document.
///
public int VisitParagraphEnd(final Paragraph paragraph)
        {
        ResetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a Run node is encountered in the document.
///
public int visitRun(final Run run)
        {
        ResetFont(run.getFont());
        return VisitorAction.CONTINUE;
        }

///
/// Called when a SpecialChar is encountered in the document.
///
public int VisitSpecialChar(final SpecialChar specialChar)
        {
        ResetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
        }

private void ResetFont(Font font)
        {
            font.setName(mNewFontName);
            font.setSize(mNewFontSize);

        }

    private String mNewFontName = "Arial";
    private double mNewFontSize = 19.0;
}