Document doc = new Document("C:\\Temp\\in.txt");
FontChanger fontChanger = new FontChanger(2.0f);
doc.accept(fontChanger);
doc.save("C:\\Temp\\out.pdf");
private static class FontChanger extends DocumentVisitor
{
public FontChanger(float fontScaleFactor)
{
mFontScaleFactor = fontScaleFactor;
}
/**
* Called when a FieldEnd node is encountered in the document.
*/
public int visitFieldEnd(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(FieldSeparator fieldSeparator)
{
ResetFont(fieldSeparator.getFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a FieldStart node is encountered in the document.
*/
public int visitFieldStart(FieldStart fieldStart)
{
ResetFont(fieldStart.getFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a Footnote end is encountered in the document.
*/
public int visitFootnoteEnd(Footnote footnote)
{
ResetFont(footnote.getFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a FormField node is encountered in the document.
*/
public int visitFormField(FormField formField)
{
ResetFont(formField.getFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a Paragraph end is encountered in the document.
*/
public int visitParagraphEnd(Paragraph paragraph)
{
ResetFont(paragraph.getParagraphBreakFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a Run node is encountered in the document.
*/
public int visitRun(Run run)
{
ResetFont(run.getFont());
return VisitorAction.CONTINUE;
}
/**
* Called when a SpecialChar is encountered in the document.
*/
public int visitSpecialChar(SpecialChar specialChar)
{
ResetFont(specialChar.getFont());
return VisitorAction.CONTINUE;
}
private void ResetFont(com.aspose.words.Font font)
{
font.setSize(font.getSize() * mFontScaleFactor);
}
private float mFontScaleFactor = 1.0f;
}