I have used mont font. It works okay on my local machine but it’s different in Dev servers and UAT Server. This is my code for loading it.
string fontFolder = Path.Combine(_rootEnviro.WebRootPath, “mont”);
string fontFile = Path.Combine(_rootEnviro.WebRootPath, “mont”, “Mont-ExtraLight.ttf”);
FontConfigs.SetFontFolder(fontFolder, true);
FolderFontSource fontSourceFolder = new FolderFontSource(fontFolder, false);
FileFontSource fontSourceFile = new FileFontSource(fontFile);
MemoryFontSource sourceMemory = new MemoryFontSource(File.ReadAllBytes(fontFile));
FontConfigs.SetFontSources(new FontSourceBase[] { fontSourceFolder, fontSourceFile, sourceMemory });
Then I define font like this
style.Font.Name = “Mont-ExtraLight”;
Please try to use FontRepository.findFont("Mont-ExtraLight") method while assigning the font to the text and let us know in case issue still persists by share the complete environment details where application is deployed. We will further proceed to assist you accordingly.
Mine is a ASPOSE.CELLS that I am converting to a pdf. Like this
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.OnePagePerSheet = true;
pdfOptions.DefaultFont = “Mont-ExtraLight”;
pdfOptions.AllColumnsInOnePagePerSheet = true;
pdfOptions.CreatedTime = DateTime.Today;
Please share us a standalone project with source code and source file to reproduce the issue.
Also, share us the output pdf files generated on your side(both your local machine and Dev servers, UAT Server) and the font file Mont-ExtraLight.ttf .
The font name should be Mont ExtraLight instead of Mont-ExtraLight.
For DejaVU font, the font name should be DejaVu Sans.
Also, for set font folder code, only the following one line is enough.
FontConfigs.SetFontFolder(fontFolder, true);
So the code will be:
string fontFolder = Path.Combine(_rootEnviro.WebRootPath, "mont");
//string fontFile = Path.Combine(_rootEnviro.WebRootPath, "mont", "Mont-ExtraLight.ttf");
FontConfigs.SetFontFolder(fontFolder, true);
//FolderFontSource fontSourceFolder = new FolderFontSource(fontFolder, false);
//FileFontSource fontSourceFile = new FileFontSource(fontFile);
//MemoryFontSource sourceMemory = new MemoryFontSource(File.ReadAllBytes(fontFile));
//FontConfigs.SetFontSources(new FontSourceBase[] { fontSourceFolder, fontSourceFile, sourceMemory });
...
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.OnePagePerSheet = true;
//the font name should be right.
pdfOptions.DefaultFont = "Mont ExtraLight";
pdfOptions.AllColumnsInOnePagePerSheet = true;
pdfOptions.CreatedTime = DateTime.Today;
//path = path + rprtDto.Name + ".xlsx";
//reportWb.Save(path);
MemoryStream ms = new();
reportWb.Save(ms, SaveFormat.Pdf);
...
If you still have issues, please save the workbook to xlsx file before saving to pdf, and share us the xlsx file and some screenshots to highlight the issues.
Also, what is the result as we early discussed to use font Mont ExtraLight ?
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.OnePagePerSheet = true;
//the font name should be right.
pdfOptions.DefaultFont = "Mont ExtraLight";
pdfOptions.AllColumnsInOnePagePerSheet = true;
pdfOptions.CreatedTime = DateTime.Today;
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.