facebooktwittermenuarrow-up

GemBox Support Forum

Custom font of whole document before saving

Gembox.document: How to set the custom font of the whole document before saving.
I have to process find & replace and it works fine. But before saving I want to change & set the custom font of the whole document irrespective of area/section/block etc.

I tired using: document.DefaultCharacterFormat.FontName = “Verdana”
but this does not work

Note: The custom font is installed in Windows & registered.

Hi Maninder,

Changing the default font will only work for elements that specify the font neither directly nor on its style.
If you’re interested in learning about how formatting is inherited in document elements, then check this Style Resolution example.

Anyway, try using this:

var document = DocumentModel.Load("input.docx");

foreach (Run run in document.GetChildElements(true, ElementType.Run))
    run.CharacterFormat.FontName = "Verdana";

document.Save("output.docx");

Does it solve your issue?

Regards,
Mario

okay i got it.

but please tell how to set font name for replace text (loadtext)
If content IsNot Nothing Then
content.LoadText(“newword”)
//set font name here
End If

Try this:

content.LoadText("newword", New CharacterFormat() With {.FontName = "Arial"})

Regards,
Mario