Skip to content

Commit 3087a82

Browse files
github-actions[bot]KB Botdessyordanova
authored
Added new kb article consistent-pdf-font-formatting (#664)
* Added new kb article consistent-pdf-font-formatting * polished --------- Co-authored-by: KB Bot <kb-bot@telerik.com> Co-authored-by: Desislava Yordanova <dyordano@progress.com>
1 parent dcbc3c0 commit 3087a82

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Resolving Font Differences Between Client and Server-Side PDF generation in Telerik Document Processing
3+
description: Resolve font formatting discrepancies between client-side and server-side PDF generation using Telerik Document Processing.
4+
type: how-to
5+
page_title: Resolving PDF Formatting Differences Between Client and Server in Telerik Document Processing
6+
meta_title: Resolving PDF Formatting Differences Between Client and Server in Telerik Document Processing
7+
slug: consistent-pdf-font-formatting
8+
tags: pdf, font,telerik, document, processing,formatting,server-side,client-side,export
9+
res_type: kb
10+
ticketid: 1700632
11+
---
12+
13+
## Environment
14+
15+
| Version | Product | Author |
16+
| ---- | ---- | ---- |
17+
| 2025.3.806| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
18+
19+
## Description
20+
21+
This knowledge base article shows how to resolve font differences between server-side and client-side PDF generation.
22+
23+
## Solution
24+
25+
Usually, the main difference between the server and client-side generated PDF documents is the font. To achieve consistent font formatting between the client-side and server-side PDFs, follow these steps:
26+
27+
1. Install the [Telerik.Documents.Fixed]({%slug available-nuget-packages%}) NuGet package.
28+
2. Specify the font explicitly for text elements in the server-side PDF generation code.
29+
3. Load the required font file and register it with the `FontsRepository`.
30+
31+
Use one of the following options to set the font for text blocks:
32+
33+
### Option 1: Explicitly Set Font for Blocks
34+
Register and apply the font as shown in the example below:
35+
36+
```csharp
37+
byte[] fontData = File.ReadAllBytes(@"C:\Windows\Fonts\calibri.ttf");
38+
FontFamily fontFamily = new FontFamily("Calibri");
39+
FontsRepository.RegisterFont(fontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
40+
41+
FontBase calibriFont;
42+
bool success = FontsRepository.TryCreateFont(fontFamily, FontStyles.Normal, FontWeights.Normal, out calibriFont);
43+
44+
var c0 = row.Cells.AddTableCell();
45+
c0.PreferredWidth = preferredWidths[0];
46+
Block block1 = c0.Blocks.AddBlock();
47+
block1.TextProperties.Font = calibriFont;
48+
block1.InsertText(reportItem.JobNumber ?? string.Empty);
49+
```
50+
51+
### Option 2: Use FontFamily for Text Insertion
52+
Alternatively, utilize the `FontFamily` directly during text insertion:
53+
54+
```csharp
55+
byte[] fontData = File.ReadAllBytes(@"C:\Windows\Fonts\calibri.ttf");
56+
FontFamily fontFamily = new FontFamily("Calibri");
57+
FontsRepository.RegisterFont(fontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
58+
59+
var c10 = row.Cells.AddTableCell();
60+
c10.PreferredWidth = preferredWidths[10];
61+
c10.Blocks.AddBlock().InsertText(fontFamily, reportItem.StatusDate?.ToString("dd/MM/yyyy") ?? string.Empty);
62+
```
63+
64+
Ensure consistent usage of fonts between client-side and server-side export processes. Use the same font family and size as implemented in the client-side export.
65+
66+
## See Also
67+
68+
- [Cross-Platform Fonts]({%slug radpdfprocessing-cross-platform-fonts%})
69+
- [Registering a Font]({%slug radpdfprocessing-concepts-fonts%}#registering-a-font)
70+

libraries/radpdfprocessing/cross-platform/fonts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ You can find a detailed **FixedExtensibilityManager** and **FontsProvider** desc
3939
* [Resolving Missing Content in Exported PDF Files]({%slug missing-content-word-to-pdf-radwordsprocessing%})
4040
* [Validating Fonts when Using Telerik Document Processing]({%slug validating-fonts-pdf-document-processing%})
4141
* [Preserving Original Bold, Italic and Regular Fonts When Exporting PDF Documents Using PdfProcessing in .NET Standard]({%slug pdfprocessing-prevent-font-conversion-embedding-fonts%})
42+
* [Resolving Font Differences Between Client and Server-Side PDF generation in Telerik Document Processing]({%slug consistent-pdf-font-formatting%})
4243

4344

0 commit comments

Comments
 (0)