Free Support Forum - aspose.com

Problems with Fonts

Hi,

when converting to word, I am having trouble with font.
In teh template i am having Arial font, and the merge fields coming from database are having Times New roman font, how to set the font of the whole document to be the same?.

Hi

Thanks for your inquiry. You can try using the following code to solve this problem.

public void TestMailMerge_106189()

{

Document doc = new Document(@"417_106189_raviteja\in.doc");

string[] names = { "test" };

string[] values = { "value" };

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_106189);

doc.MailMerge.Execute(names, values);

doc.Save(@"417_106189_raviteja\out.doc");

}

void MailMerge_MergeField_106189(object sender, MergeFieldEventArgs e)

{

e.Field.Start.ParentParagraph.ParagraphFormat.Style.Font.Name = "Arial";

}

Also you can use the following code.

NodeCollection paragpaphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach(Paragraph par in paragpaphs)

{

par.ParagraphFormat.Style.Font.Name = "Arial";

}

I hope that this will help you.

Best regards.