Skip to content

Commit befbc82

Browse files
Merge pull request #456 from telerik/new-kb-preserve-font-boldness-pdf-export-radspreadprocessing-3cc18315c9e8453f8759307f9ca180e2
Added new kb article preserve-font-boldness-pdf-export-radspreadprocessing
2 parents 349177c + aea9023 commit befbc82

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 Preserve 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, pdf, export
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 format using [RadSpreadProcessing]({%slug radspreadprocessing-overview%}), 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](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/fonts#registering-a-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)
55+
- [Using PdfFormatProvider]({%slug radspreadprocessing-formats-and-conversion-pdf-pdfformatprovider%})

libraries/radpdfprocessing/concepts/fonts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,5 @@ You can create fonts that are not explicitly registered. Creating a font that is
153153
* [Cross-Platform Support for Fonts]({%slug radpdfprocessing-cross-platform-fonts%})
154154
* [FontsRepository](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.html)
155155
* [TextFragment]({%slug radpdfprocessing-model-textfragment%})
156+
* [Preserving the Font in PDF Export from Excel]({%slug preserve-font-boldness-pdf-export-radspreadprocessing%})
156157

libraries/radspreadprocessing/formats-and-conversion/pdf/pdfformatprovider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ The result from the export method is a document that can be opened in any applic
7272
- [How to Eliminate Formatting Issues when Exporting XLSX to PDF Format]({%slug exporting-xlsx-to-pdf-formatting-issues%})
7373
- [Import/Load and Export/Save RadSpreadProcessing Workbook]({%slug import-export-save-load-workbook%})
7474
- [Export Worksheet to image]({%slug spreadprocessing-export-worksheet-to-image-netstandard%})
75+
- [Preserving the Font in PDF Export from Excel]({%slug preserve-font-boldness-pdf-export-radspreadprocessing%})
7576

0 commit comments

Comments
 (0)