Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue May 21, 2019 8:05 pm

Hi support,
we have a problem with unicode TrueType font loaded from file. This is how we create the font:

Code: Select all
            PrivateFontCollection collection = new PrivateFontCollection();
            collection.AddFontFile(@"./font/DINPro-CondLight.otf");
            FontFamily fontFamily = new FontFamily("DIN Pro Cond Light", collection);
            Font font = new Font(fontFamily, 10f);
            PdfTrueTypeFont truetypeFont = new PdfTrueTypeFont(font, true);
            page.Canvas.DrawString("Hello ℮ symbol", truetypeFont, brush, new PointF(10, 10), format, true);


The PdfTrueTypeFont object revert to Times font instead of the one loaded from file.

How can we solve our issue?

Best,
Carlo Brunengo

carlo.brunengo
 
Posts: 2
Joined: Tue May 21, 2019 7:51 pm

Wed May 22, 2019 7:18 am

Dear Carlo,

Thank you for contacting us.
Kindly note that the Font class doesn't support .otf font, that's the reason why it didn't present the loaded font file. Our PdfTrueTypeFont supports directly loading .otf font by specifying font path, please refer to the following code.
Code: Select all
PdfTrueTypeFont truetypeFont = new PdfTrueTypeFont(@"./font/DINPro-CondLight.otf", 10f);

After using above code, you will find that the generated Pdf doesn't render the specific character "℮", that's because the font "DINPro-CondLight.otf" doesn't support the specific character. Please use another font such as "Courier New" which supports it to draw the string. Please refer to the code below.
Code: Select all
PdfTrueTypeFont truetypeFont = new PdfTrueTypeFont(new Font("Courier New", 10f),true);

If there is any question, please feel free to write back.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1320
Joined: Tue Sep 27, 2016 1:06 am

Wed May 22, 2019 2:17 pm

Dear Nina,
thank you very much for your support.
I need to load the font from a file and I tried a lot of fonts, otf and ttf. Just a few ttf fonts works with PdfTrueTypeFont and enabling unicode characters. What is the reason? I'm looking for a condensed font. Can you give me an advice, please?

Best,
Carlo

carlo.brunengo
 
Posts: 2
Joined: Tue May 21, 2019 7:51 pm

Thu May 23, 2019 2:51 am

Dear Carlo,

Thanks for your feedback.
The specific characters need the fonts that support rendering them. As I said before, the "DINPro-CondLight.otf" font itself doesn't support rendering the specific characters, but the "Courier New" supports. That's the reason for your issue.
I'm afraid I can't give you a good advice regarding the condense fonts that support the specific characters since I don't have much knowledge about it. If you have other question, just feel free to contact us.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1320
Joined: Tue Sep 27, 2016 1:06 am

Tue Apr 13, 2021 4:35 pm

Nina.Tang wrote:Dear Carlo,

Thank you for contacting us.
Kindly note that the Font class doesn't support .otf font, that's the reason why it didn't present the loaded font file. Our PdfTrueTypeFont supports directly loading .otf font by specifying font path, please refer to the following code.
Code: Select all
PdfTrueTypeFont truetypeFont = new PdfTrueTypeFont(@"./font/DINPro-CondLight.otf", 10f);


Sincerely,
Nina
E-iceblue support team


Is this still the case? Whenever I try to link to an .OTF font in the above manner, I get the following error message:
Error
Failed to load PDF document.

Using version 7.3.3.0

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Wed Apr 14, 2021 2:02 am

Hello,

Thanks for your inquiry!

I linked to the HelveticaNeueLTStd-Cn.otf font and drew some string to a PDF with the following code, but did not reproduce your issue, I also attached my result file for reference.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();

            //Draw text - brush
            String text = "Test String";
            PdfPen pen = PdfPens.DeepSkyBlue;
            PdfSolidBrush brush = new PdfSolidBrush(Color.White);
            PdfStringFormat format = new PdfStringFormat();
            PdfTrueTypeFont truetypeFont = new PdfTrueTypeFont(@"E:\testdoc\HelveticaNeueLTStd-Cn\HelveticaNeueLTStd-Cn.otf", 10f, PdfFontStyle.Bold);
            SizeF size = truetypeFont.MeasureString(text, format);
            RectangleF rctg = new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180, size.Width / 3 * 2, size.Height * 2);
            page.Canvas.DrawString(text, truetypeFont, pen, brush, rctg, format);

            pdf.SaveToFile("UseOtf.pdf", FileFormat.PDF);


First, please make sure that the font file can be read by your program. If so, and the issue still exists, to help us reproduce and investigate your issue quickly and efficiently, please provide us with the following information. Thanks in advance.

1. Your font file
2. Your testing code
3. Your target framework
4. Your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese)

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Sun Apr 25, 2021 9:47 am

Hello,

Hope you are doing well!

How is the issue now? If it still exists, could you please provide the above information to us for further investigation?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF