Skip to content

Commit 3322c01

Browse files
author
KB Bot
committed
Added new kb article preserve-font-boldness-pdf-export-radspreadprocessing
1 parent f754083 commit 3322c01

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Preserving the Font in PDF Export from Excel
3+
description: Learn how to preserve the bold text when converting Excel documents to PDF using RadSpreadProcessing.
4+
type: how-to
5+
page_title: How to Keep Text Boldness in PDF Conversion with RadSpreadProcessing
6+
slug: preserve-font-boldness-pdf-export-radspreadprocessing
7+
tags: spreadprocessing, document, processing, pdf export, font, registration, bold, text
8+
res_type: kb
9+
ticketid: 1659898
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| .NET Framework| RadSpreadProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
When converting Excel documents in .NET Framework applications to PDF using RadSpreadProcessing, the bold text in the Excel file might not appear bold in the exported PDF. The font also may be changed in the exported PDF. This issue often arises due to the PDF export process using a different font than the one specified in the Excel document. For instance, the PDF export might default to using "Arial" font, while the original Excel document uses "Aptos Narrow".
21+
22+
This KB article also answers the following questions:
23+
- How to ensure text boldness is preserved in PDF exports?
24+
- How to register custom fonts for PDF export in RadSpreadProcessing?
25+
- How to handle font discrepancies between Excel documents and PDF exports?
26+
27+
## Solution
28+
29+
To preserve the font and the bold text when exporting an Excel document to PDF, it is necessary to register the font used in the Excel document if it is not part of the [standard fonts]({%slug radpdfprocessing-concepts-fonts%}) supported by the PDF export process. Follow these steps to register a custom font:
30+
31+
1. **Read the font** from the file system. Ensure you include both the regular and bold versions of the font if applicable.
32+
33+
2. **Create a `FontFamily`** instance for the custom font.
34+
35+
3. **Register the font** with the `FontsRepository`. Ensure to register both the regular and bold variations of the font to cover all text styles in the document.
36+
37+
```csharp
38+
// Read the font file
39+
byte[] fontDataAptos = File.ReadAllBytes(@"..\..\..\fonts\Aptos-Narrow.ttf");
40+
byte[] fontDataAptosBold = File.ReadAllBytes(@"..\..\..\fonts\Aptos-Narrow-Bold.ttf");
41+
42+
System.Windows.Media.FontFamily fontFamilyAptos = new System.Windows.Media.FontFamily("Aptos Narrow");
43+
44+
// Register the font
45+
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(fontFamilyAptos, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Normal, fontDataAptos);
46+
Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(fontFamilyAptos, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Bold, fontDataAptosBold);
47+
```
48+
49+
By following these steps, the exported PDF document will correctly display text in bold that was bold in the original Excel document, using the custom font. If other fonts are used in the Excel document, they also should be registered in a similar way.
50+
51+
## See Also
52+
53+
- [Fonts in RadPdfProcessing]({%slug radpdfprocessing-concepts-fonts%})
54+
- [Registering a Font](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/fonts#registering-a-font)

0 commit comments

Comments
 (0)