Registering Custom Font Variants (Regular, Bold, Italic) for Conversion in Telerik Document Processing
Environment
| Version | Product | Author |
|---|---|---|
| 2025.4.1104 | RadPdfProcessing/RadWordsProcessing | Desislava Yordanova |
Description
When converting DOCX files to PDF with PdfProcessing, missing or incorrectly registered font variants may cause fallback fonts to appear in the output PDF. This article shows how to register custom font variants (Regular, Bold, Italic) for the Barlow font family (or any other) and perform the conversion with consistent output.
Solution
To ensure proper rendering of the custom (for example, Barlow) font family in converted PDFs, register each font variant and style individually before conversion. Follow these steps:
-
Register the Regular variant of the Barlow font:
csharpbyte[] barlowRegular = File.ReadAllBytes(@"..\..\Barlow\Barlow-Regular.ttf"); var barlowFamily = new FontFamily("Barlow"); FontsRepository.RegisterFont(barlowFamily, FontStyles.Normal, FontWeights.Normal, barlowRegular); -
Register the Regular variant of the Barlow Condensed font:
csharpbyte[] barlowCondensed = File.ReadAllBytes(@"..\..\Barlow\BarlowCondensed-Regular.ttf"); var barlowCondensedFamily = new FontFamily("Barlow Condensed"); FontsRepository.RegisterFont(barlowCondensedFamily, FontStyles.Normal, FontWeights.Normal, barlowCondensed); -
Register the Bold variant of the Barlow Condensed font:
csharpbyte[] barlowCondensedBold = File.ReadAllBytes(@"..\..\Barlow\BarlowCondensed-Bold.ttf"); var barlowCondensedFamilyBold = new FontFamily("Barlow Condensed"); FontsRepository.RegisterFont(barlowCondensedFamilyBold, FontStyles.Normal, FontWeights.Bold, barlowCondensedBold); -
Register the Regular variant of the Barlow Semi Condensed font:
csharpbyte[] barlowSemiCondensed = File.ReadAllBytes(@"..\..\Barlow\BarlowSemiCondensed-Regular.ttf"); var barlowSemiCondensedFamily = new FontFamily("Barlow Semi Condensed"); FontsRepository.RegisterFont(barlowSemiCondensedFamily, FontStyles.Normal, FontWeights.Normal, barlowSemiCondensed); -
Register the Bold variant of the Barlow Semi Condensed font:
csharpbyte[] barlowSemiCondensedBold = File.ReadAllBytes(@"..\..\Barlow\BarlowSemiCondensed-Bold.ttf"); var barlowSemiCondensedFamilyBold = new FontFamily("Barlow Semi Condensed SemiBold"); FontsRepository.RegisterFont(barlowSemiCondensedFamilyBold, FontStyles.Normal, FontWeights.Bold, barlowSemiCondensedBold); -
Convert the DOCX file to PDF using the registered fonts:
csharpstring inputFilePath = @"path-to-docx-file.docx"; string outputFilePath = @"output-path.pdf"; DocxFormatProvider docxProvider = new DocxFormatProvider(); PdfFormatProvider pdfProvider = new PdfFormatProvider(); RadFlowDocument document; using (FileStream inputStream = new FileStream(inputFilePath, FileMode.Open)) { document = docxProvider.Import(inputStream, TimeSpan.FromSeconds(10)); } using (FileStream outputStream = new FileStream(outputFilePath, FileMode.Create)) { pdfProvider.Export(document, outputStream, TimeSpan.FromSeconds(10)); }
Verify that the font name matches exactly in the DOCX and in the system font list. If the DOCX uses "Barlow Semi Condensed SemiBold", but the registered font is "Barlow Semi Condensed Bold", fallback occurs.