Back to Devexpress

How to: Embed Fonts Used in a Document

wpf-404372-controls-and-libraries-rich-text-editor-examples-formatting-how-to-embed-fonts-used-in-a-document.md

latest2.0 KB
Original Source

How to: Embed Fonts Used in a Document

  • Feb 24, 2025

The Rich Text Editor for WPF allows you to specify whether to embed fonts used in a document. You can embed TrueType and OpenType fonts that have the specified embedding permissions.

Use the Document.EmbedFonts property to embed fonts.

The code sample below loads a document to the RichEditControl instance, formats the document header and applies the Chiller font, enables font embedding, and saves the result.

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

richEditControl.LoadDocument(@"C:\Docs\Word (RTF) Document API for NET.docx");
Paragraph titleParagraph = richEditControl.Document.Paragraphs[0];
CharacterProperties characterProperties =
    richEditControl.Document.BeginUpdateCharacters(titleParagraph.Range);
characterProperties.FontName = "Chiller";
characterProperties.FontSize = 16;
richEditControl.Document.EndUpdateCharacters(characterProperties);
richEditControl.Document.EmbedFonts = true;
string fileName = /*the path to the OneDrive folder*/ 
richEditControl.SaveDocument(fileName, DocumentFormat.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

richEditControl.LoadDocument("C:\Docs\Word (RTF) Document API for NET.docx")
Dim titleParagraph As Paragraph = richEditControl.Document.Paragraphs(0)
Dim characterProperties As CharacterProperties =
    richEditControl.Document.BeginUpdateCharacters(titleParagraph.Range)
characterProperties.FontName = "Chiller"
characterProperties.FontSize = 16
richEditControl.Document.EndUpdateCharacters(characterProperties)
richEditControl.Document.EmbedFonts = True
Dim fileName As String = richEditControl.SaveDocument(fileName, DocumentFormat.Docx)