Having trouble loading a private font

I’m using GemBox.Pdf to create a new PDF document, using Visual Studio 2022/.Net 6. I’m trying to load the Google “Poppins-Regular” font as follows:
var _PoppinsFont = new PdfFontFamily(null, “Fonts”, “Poppins-Regular.ttf”);
I’ve tried setting the “Build Action” property to “Resource”, and “Embedded resource”, but I am not able to get this font to load. I don’t see any error message, but my document appears to fall back to a default Serif font. Is there something about this particular font that would be causing the issue?

Hi Jerry,

Please read this example:
Private Fonts - Example

Also, please check the “CSPROJ” and the “CS” file in this GitHub project:
Private Fonts - GitHub

In short, I believe you’ll need to use this:

var _PoppinsFont = new PdfFontFamily(null, "Fonts", "Poppins");

I hope this helps.

If the problem remains, please send us a small Visual Studio project that reproduces your issue so that we can investigate it.

Regards,
Mario

Mario,
I reviewed the Private Fonts example again, and tried to add in the Google Poppins font.
If I compile the example as .Net 4.8 using Visual Studio 2019, the Almonte Woodgrain font works, but the others do not.
If I compile the example as .Net 5.0 or .Net 6.0 using Visual Studio 2022, none of the fonts appear to work.
Note: all of these examples used GemBox.Pdf 17.0.1363. I tried to zip these examples so I could send them to you, but this page won’t let me upload a zip file. How should I send these to you?
FYI, the actual program that I am writing is a .Net 6.0 console app.

When you’re targeting “net48” or “net6.0-windows” then you should set those font files as <Resource>.

But when you’re targeting “net6.0” then you need to set them as <EmbeddedResource> for the build action.

Anyway, you can send us your project via email or via support ticket, please check our Contact page.

When I run locally, this works fine. But when the program is run from the server it does not load the font.
I have my fonts in a top-level “Fonts” folder and they are all set to .
I load the fonts with this statement: _PoppinsFont = new PdfFontFamily(“Fonts”, “Poppins”);
The “Fonts” folder exists on the server, but it clearly does not find/load the font. Any ideas?

Also, is there some way that the code can determine at run time whether the “new PdfFontFamily(“Fonts”, “Poppins”);” statement worked successfully or not?

I found that I can use a system font instead of trying to use a private font. Now the problem I have is, the generated PDF document seems to randomly drop individual characters. Any idea why this might be happening? We need to generate these letters in production next week.


Actual text says “Your health”, and “Read this letter carefully”

MissingChars2
Actual text says “using IRS Form 8962”

MissingChars1
The first word for each bullet should be: “Visit, Call, Find, Contact, Call”

FYI, this works fine when running local thru VisualStudio.

I believe the problem is with the relative path, can you try using the absolute path?
For example:

 _PoppinsFont = new PdfFontFamily(Server.MapPath("Fonts"), "Poppins");

Can you please send us the “Poppins” font files and also the text that reproduces your issue so that we can investigate this?

The easiest way would be to use PdfFonts.GetFontFamilies method.

I created a test project to reproduce the issue, then zipped all the files. However, the Contact page will not let me send the Zip file to you. I can Choose the file and that appears to work (I see a small icon and “47.4 MB”). But when I click on Submit, I get a message that says: “Uploaded file was not found. Please try again.” I tried several times, all with the same result.

First can you please check that you’re not zipping the “bin” and “obj” folders?
Second, can you please try again by sending that zip to our email that’s mentioned on the Contact page?