I try to use some extra fonts in my code but as soon as I try to use theses fonts my output document is 0kb. I tried with a OpenType Font and a TrueType Font file but without success. The two fonts are attached to my post so you can make a test using them.
// Colors
Color rosa = new Color(241, 0, 135);
// Translations
Dictionary<string, string> translations = new Dictionary<string, string>();
translations.Add(“typeDeBillet”, “billet type service horaire”);
Pdf pdf = new Pdf();
pdf.IsFontNotFoundExceptionThrown = true;
Section headerSection = pdf.Sections.Add() ;
HeaderFooter header = new HeaderFooter(headerSection) ;
headerSection.OddHeader = headerSection.EvenHeader = header;
header.IsFirstPageOnly = true;
Text textBilletType = new Text(header);
header.Paragraphs.Add(textBilletType);
//Create a text segment
Aspose.Pdf.Generator.Segment s1 = new Aspose.Pdf.Generator.Segment(translations[“typeDeBillet”]);
textBilletType.Segments.Add(s1);
//Set the font name to the TextInfo.FontName property of segment, where ‘Almonto Snow’ is custom font name
// That one works
s1.TextInfo.FontName = “Symbol”;
// That one fails
//s1.TextInfo.FontName = “Gotham Light”;
s1.TextInfo.IsFontEmbedded = true ;
//Save the Pdf
pdf.Save(@“C:\Test.pdf”);
In order to use Gotham Light true type font, you need to specify the location where True type font is located on system using TextInfo.
TruetypeFontFileName property. I have tested the scenario using Aspose.Pdf for .NET 7.7.0 using following code snippet and I am unable to notice any issue.
Furthermore, please try using SetUnicode(..) method before saving the PDF file so that the subset of true-type font is included in PDF document.
C#
Pdf pdf = new Pdf();
pdf.IsFontNotFoundExceptionThrown = true;
Section headerSection = pdf.Sections.Add();
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(headerSection);
headerSection.OddHeader = headerSection.EvenHeader = header;
header.IsFirstPageOnly = true;
Text textBilletType = new Text(header);
header.Paragraphs.Add(textBilletType);
// Create a text segment
Aspose.Pdf.Generator.Segment s1 = new Aspose.Pdf.Generator.Segment("translations-typeDeBillet");
textBilletType.Segments.Add(s1);
// Set the font name to the TextInfo.FontName property of segment, where ‘Almonto Snow’ is custom font name
s1.TextInfo.FontName = "Gotham Light";
// specify the true type font file path
s1.TextInfo.TruetypeFontFileName = @"C:\Softwares\Aspose\Fonts\Gotham+Light\gothamlight.ttf";
s1.TextInfo.IsFontEmbedded = true;
// add the subset of True-Type font file in PDF document
pdf.SetUnicode();
// Save the Pdf
pdf.Save(@"C:\pdftest\Font_Test.pdf");
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.
Enables storage, such as cookies, related to analytics.
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.