Hello,
I am using the Aspose words 21.2(Licensed),
I have set the default font as Garamond and the font size as 12 in the generated doc file. The issue is when I try to add a list inside it, its default font is getting changed in Microsoft Word. The solution I want is consistent font in the whole document.
Also note that this behavior is specific to Microsoft Word editor only, not to other editors. and the font is not changed when I add paragraphs.
@wivo Could you please attach your input and output documents along with code that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.
import com.aspose.words.*;
public class FontChanger extends DocumentVisitor {
public FontChanger(String fontName) {
mFontName = fontName;
mFontSize = 0;
}
public FontChanger(String fontName, double fontSize)
{
mFontName = fontName;
mFontSize = fontSize;
}
/// <summary>
/// Called when a FieldEnd node is encountered in the document.
/// </summary>
@Override
public int visitFieldEnd(FieldEnd fieldEnd)
{
//Simply change font name
resetFont(fieldEnd.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a FieldSeparator node is encountered in the document.
/// </summary>
@Override
public int visitFieldSeparator(FieldSeparator fieldSeparator)
{
resetFont(fieldSeparator.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a FieldStart node is encountered in the document.
/// </summary>
@Override
public int visitFieldStart(FieldStart fieldStart)
{
resetFont(fieldStart.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Footnote end is encountered in the document.
/// </summary>
@Override
public int visitFootnoteEnd(Footnote footnote)
{
resetFont(footnote.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a FormField node is encountered in the document.
/// </summary>
@Override
public int visitFormField(FormField formField)
{
resetFont(formField.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Paragraph end is encountered in the document.
/// </summary>
@Override
public int visitParagraphEnd(Paragraph paragraph)
{
resetFont(paragraph.getParagraphBreakFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a Run node is encountered in the document.
/// </summary>
@Override
public int visitRun(Run run)
{
resetFont(run.getFont());
return VisitorAction.CONTINUE;
}
/// <summary>
/// Called when a SpecialChar is encountered in the document.
/// </summary>
@Override
public int visitSpecialChar(SpecialChar specialChar)
{
resetFont(specialChar.getFont());
return VisitorAction.CONTINUE;
}
private void resetFont(Font font)
{
font.setName(mFontName);
if(mFontSize > 0)
font.setSize(mFontSize);
}
private String mFontName = "Arial";
private double mFontSize = 0;
}
Thanks, @alexey.noskov for your reply. This works with numbered lists, bulleted lists, and multilevel lists. However, the issue persists when I add a list with a heading.