This is a migrated thread and some comments may be shown as answers.

The builtin PDF fonts don't have a Euro sign

10 Answers 548 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
Roland asked on 03 Nov 2020, 02:28 AM

€100 is printed as 100.

What do I do to get my € back?

10 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Nov 2020, 12:31 PM

Hi Roland,

I have tested this with the following code and it works on my side: 

var document = new RadFixedDocument();
var page = document.Pages.AddPage();
var editor = new FixedContentEditor(page);

Block block = new Block();
block.TextProperties.Font = FontsRepository.TimesRoman;
block.InsertText("100€");


editor.Position.Translate(100, 100);
editor.DrawBlock(block);

var provider = new PdfFormatProvider();
File.WriteAllBytes(@"..\..\result.pdf", provider.Export(document));

Please note that if this is a .NET Framework application you can use the fonts available on the operating system. For example: 

Block block = new Block();
block.InsertText(new FontFamily("Segoe UI"), "100€");

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 21 Nov 2020, 02:17 PM
I created a Console app with the exact code above, and I get a PDF with just "100". No Euro sign.
0
Dimitar
Telerik team
answered on 23 Nov 2020, 09:41 AM

Hello Roland,

Is this a .NET Framework or .NET Core/Standart application? What is the default culture on your operating system? Which version of the PdfPorcessing library are you using? 

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 23 Nov 2020, 05:34 PM

used to be .NET Core 3.1, now .NET 5

The server OS culture is nl-NL, my PC OS culture is en-US, my browser language is English, but the application forces the current culture and [""Accept-Language"] request header to nl-NL.Currency is written with a € (and all the right delimiters and separators) as expected, but that never shows up in the PDF.

0
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 23 Nov 2020, 05:37 PM
and I am using Nuget packages Telerik.Documents.Fixed (2020.3.1019) and Telerik.UI.for.Blazor (2.19.0)
0
Dimitar
Telerik team
answered on 24 Nov 2020, 09:45 AM

Hi Roland,

When using the version for NET Standart, the fonts must be manually registered or you can use one of the predefined fonts in the repository.  By default, the Helvetica font is used and it does not contain the euro symbol. Detailed information about this is available in the following articles: 

Here is how you can register the font and use the example from the previous post (you can copy the font from the C:|Windows\Fonts folder):

var fontData = File.ReadAllBytes(@"..\..\..\SEGOEUI.TTF");
FontsRepository.RegisterFont(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, fontData);

var document = new RadFixedDocument();
var page = document.Pages.AddPage();
var editor = new FixedContentEditor(page);

Block block = new Block();
block.InsertText(new FontFamily("Segoe UI"), "100€");

editor.Position.Translate(100, 100);
editor.DrawBlock(block);

var provider = new PdfFormatProvider();
File.WriteAllBytes(@"..\..\..\result.pdf", provider.Export(document));

Let me know if you have any other questions.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 24 Nov 2020, 11:24 AM

>By default, the Helvetica font is used and it does not contain the euro symbol.

Nor do the others...

Registering a font from my PC seems to work, but how do I set the font once for an entire document instead of having to change every block.InsertText()?

0
Dimitar
Telerik team
answered on 25 Nov 2020, 06:37 AM

Hi Roland,

You can set the TextProperties.Font and this way all text added after that will use this font. Here is an example of this: 

FontBase font;
FontsRepository.TryCreateFont(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, out font);
editor.TextProperties.Font = font; 

Block block = new Block();
block.InsertText("100€");
editor.Position.Translate(100, 100);
editor.DrawBlock(block);

editor.Position.Translate(100, 150);
editor.DrawText("Test 100€");

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
answered on 25 Nov 2020, 08:32 PM

the combination

editor.TextProperties.Font = font;

block.InsertText("100€");

seems to be highly unreliable.

If I load font arial.ttf with fontfamily name "arial", I cannot print a €.

Exact same font with name "Arial" suddenly works as expected.

I will stick to block.TextProperties.Font = font; for now

0
Dimitar
Telerik team
answered on 26 Nov 2020, 10:10 AM

Hi Roland,

The font names are case sensitive and you need to use the correct name when creating a font (this is indeed a bit tricky at first). You can check the font names in MS Word in case you are wondering about a particular case.  

In addition, you can fallback to a particular font in case you decide to get the fonts from the operating system: 

FontBase font;
if (!FontsRepository.TryCreateFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal, out font))
{
    font = FontsRepository.TimesRoman;
} 

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PdfProcessing
Asked by
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Roland
Top achievements
Rank 3
Iron
Iron
Veteran
Share this question
or