We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem using extra Embedded Font

Hello,

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”);

Any help would be appreciated

Hi Faessler,


Thanks for using our products.

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();<o:p></o:p>

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");