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

Free Support Forum - aspose.com

Aspose.Pdf.Generator.TextInfo Not working with custom Font/True Type Font

I am using custom font for Barcode. How to use ttf file with Aspose.pdf.Generator.
I found following one way, but it does not accept virtual path It needs always physical path or map.path which is not possible in our application case.
Aspose.Pdf.Generator.TextInfo styleBarcode = new Aspose.Pdf.Generator.TextInfo();
styleBarcode.FontName = “PrecisionID C128 08”;
styleBarcode.FontAfmFile = “~/Font/PrecisionID_C128_08.afm”;
styleBarcode.FontOutlineFile = "~/Font/PrecisionID_C128_08.pfb;
styleBarcode.IsFontEmbedded = true;
styleBarcode.FontSize = 4;
styleBarcode.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

Adding to it, I installed font" PrecisionID_C128_08" on my local machine, but when I am using this font with Aspose.Pdf.Generator this font is not working,
eg: Aspose.Pdf.Generator.TextInfo styleBarcode = new Aspose.Pdf.Generator.TextInfo();
styleBarcode.FontName = “PrecisionID C128 08”;
This one also not working. This font suppose to show text in barcode format. But same font working in regular Aspx pages

Please help.


Thanks for contacting support.

In order to load/use fonts while creating PDF, please use following Aspose.Pdf DOM (Document Object Model) approach. Please note that Aspose.Pdf.Generator approach has been obsoleted in the latest version of the API and it is strongly recommended to use DOM model.

Load Font From File

string fontFile =  "~/Font/HPSimplified.TTF";
using (FileStream fontStream = System.IO.File.OpenRead(fontFile))
 TextFragment textFragment = new TextFragment("Hello world");
 // Set the font name for text string
 textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF);

Use Installed Font

textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Verdana");

Please use shared ways to use specific font while PDF generation with latest version of the API, which is Aspose.Pdf for .NET 17.8. In case if you face any issue while using above shared approach, please share your font file with us, so that we can test the scenario in our environment and address it accordingly.