|
| 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 | + |
0 commit comments