Hi, I’m trying to use Words to mail merge info into different document templates. Is there any way to:
-
Change the font of the entire document contents - the text in the document will have various formatting and sizes, but I want the font to be the same for the entire document and selectable by the user.
-
Scale the font proportionately, so for example, increase all text by 30%?
Thanks for your help
Hi
Thanks for your inquiry. Yes of course you can change font of the whole document. You can use the following code to achieve this.
// Open document
Document doc = new Document(@"Test173\in.doc");
////Loop through all styles in the document
////And change formating
foreach (Style style in doc.Styles)
{
if (style.Font != null)
{
style.Font.ClearFormatting();
style.Font.Size = 20;
style.Font.Name = "Arial";
}
}
// Get collection of runs and set the same formating
NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);
foreach (Run run in runs)
{
run.Font.ClearFormatting();
run.Font.Size = 20;
run.Font.Name = "Arial";
}
doc.Save(@"Test173\out.doc");
You can use the same technique to change font size.
Best regards.