Skip to content

Commit f440014

Browse files
github-actions[bot]KB Botdessyordanova
authored
Added new kb article fixedcontenteditor-drawtext-extended-latin-characters-pdf (#645)
* Added new kb article fixedcontenteditor-drawtext-extended-latin-characters-pdf * polishing the KB --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Desislava Yordanova <[email protected]>
1 parent 96228c2 commit f440014

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Using FixedContentEditor's DrawText method to Write Extended Latin Characters in PDF Document
3+
description: Learn how to resolve the issue when the FixedContentEditor's DrawText methodin the PdfProcessing library does not display extended Latin characters like Polish letters correctly.
4+
type: how-to
5+
page_title: Displaying Extended Latin Characters with the FixedContentEditor's DrawText in PDF
6+
meta_title: Displaying Extended Latin Characters with FixedContentEditor's DrawText in PDF
7+
slug: fixedcontenteditor-drawtext-extended-latin-characters-pdf
8+
tags: pdf,processing,fixedcontenteditor,draw,text,unicode,extended,latin,font, polish
9+
res_type: kb
10+
ticketid: 1699876
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+
When using the [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%}) **DrawText** method in the Telerik PdfProcessing library to generate PDF documents, extended Latin characters (e.g., Polish letters like "ż", "ł", "ć", "ę", "ś", "ą") may not display correctly. Instead, characters are replaced or omitted, leading to incomplete text in the PDF. This happens because standard PDF fonts like TimesRoman do not support extended Latin characters. This knowledge base article shows how to handle this situation.
22+
23+
## Solution
24+
25+
To correctly display extended Latin characters, use a Unicode-compliant TrueType font and [register]({%slug radpdfprocessing-concepts-fonts%}#registering-a-font) it with the Telerik Document Processing library. Follow these steps:
26+
27+
1. Add the desired TrueType font file (e.g., Segoe UI) to your project.
28+
2. Write the following code to load, register, and use the font for drawing text:
29+
30+
```csharp
31+
RadFixedDocument document = new RadFixedDocument();
32+
RadFixedPage page = document.Pages.AddPage();
33+
page.Size = new Size(595, 842); // A4
34+
35+
FixedContentEditor editor = new FixedContentEditor(page);
36+
37+
// Load the TTF font that supports Polish characters (e.g., Segoe UI)
38+
byte[] fontData = File.ReadAllBytes(@"..\..\..\fonts\segoeui.ttf");
39+
40+
// Register the font with the FontsRepository
41+
var fontFamily = new Telerik.Documents.Core.Fonts.FontFamily("Segoe UI");
42+
var fontStyle = Telerik.Documents.Core.Fonts.FontStyles.Normal;
43+
var fontWeight = Telerik.Documents.Core.Fonts.FontWeights.Normal;
44+
FontsRepository.RegisterFont(fontFamily, fontStyle, fontWeight, fontData);
45+
46+
// Create the font
47+
FontBase font;
48+
bool success = FontsRepository.TryCreateFont(fontFamily, fontStyle, fontWeight, out font);
49+
50+
// Set font properties
51+
editor.TextProperties.FontSize = 12;
52+
editor.TextProperties.Font = font;
53+
54+
// Define the text and position
55+
editor.Position.Translate(10, 10);
56+
string text = "Zażółć gęślą jaźń";
57+
58+
// Draw the text
59+
editor.DrawText(text);
60+
61+
// Export the document
62+
string outputFilePath = "Output.pdf";
63+
File.Delete(outputFilePath);
64+
65+
PdfFormatProvider provider = new PdfFormatProvider();
66+
provider.ExportSettings.FontEmbeddingType = FontEmbeddingType.Full;
67+
using (Stream output = File.OpenWrite(outputFilePath))
68+
{
69+
provider.Export(document, output, TimeSpan.FromSeconds(10));
70+
}
71+
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
72+
```
73+
74+
### Notes:
75+
- In ASP.NET Core, system fonts are not directly accessible. Include the font file in your project.
76+
- Ensure the font file is part of the deployment package for your application.
77+
78+
## See Also
79+
80+
- [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%})
81+
- [Fonts in PdfProcessing]({%slug radpdfprocessing-concepts-fonts%})
82+
- [Cross-Platform Support]({%slug radpdfprocessing-cross-platform-fonts%})

0 commit comments

Comments
 (0)