Font name not recognized

Hello,


I have a problem with creating a PDF document with custom fonts. I attached both fonts and here is a short code snippet which demonstrates the problem:

System.Drawing.Font winFont = new System.Drawing.Font(“Humnst777 BT”, 10);
System.Diagnostics.Debug.WriteLine(winFont.FontFamily.Name);

Aspose.Pdf.Text.Font font = FontRepository.OpenFont(@“C:\Windows\Fonts\HUM777N.TTF”);
System.Diagnostics.Debug.WriteLine(font.FontName);


The first WriteLine prints the following value on the console: Humnst777 BT. The second WriteLine produces a different output: Humanist 777 BT. A similar issue happens with the OCR font.

Obviously Aspose detects these fonts under a different name than Windows does. This must be the reason that the PDF export fails (see the attached sample code). No error is reported, but an empty file is produced (zero bytes).

I am using PDF library version 2015.01.12, which is quite new.

Of course I can do the name mappings on my own for these two fonts, but I am afraid that our customers will be facing the same problem sometime in the future. Is there a way to completely solve this issue?

Thank you in advance for your help,

Boris

Hi Boris,


Thanks for your inquiry. Please use new DOM for creating PDF document. Both methods OpenFont() and FindFont() recognize same font name and moreover. If you want to pass font name then need to remove spaces between font name. Please check sample code for your reference. Hopefully it will help you to accomplish the task.

//open document<o:p></o:p>

Document pdfDocument = new Document();

Aspose.Pdf.Page section = pdfDocument.Pages.Add();

TextFragment t = new TextFragment("Sample Text in Humnst777 BT font");

// to find font in system font folder

Aspose.Pdf.Text.Font font1 = FontRepository.OpenFont(@"C:\Users\Home\Downloads\fonts\HUM777N.ttf");

Console.WriteLine(font1.FontName);

Aspose.Pdf.Text.Font font = FontRepository.FindFont("Humanist777BT");

Console.WriteLine(font.FontName);

t.TextState.Font = font;

// to open a font with complete path

TextFragment t1 = new TextFragment("Sample Text in OCR B 10 BT font");

// to find font in system font folder

t1.TextState.Font = FontRepository.FindFont("OCR-B10PitchBT");

section.Paragraphs.Add(t);

section.Paragraphs.Add(t1);

pdfDocument.Save(myDir + "Custom_Fonts_out.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Hello,


thank you for the explanation and sorry for my late reply. I am afraid that I still have a problem with font names.

Let’s focus on the OCR-B-10 BT font. When I install it on my windows 7 system, it is named “OCR-B-10 BT”, see the attached picture. The .Net framework and all windows applications (e.g. MS Word) find the font under that name, except Aspose.

In our application we have some kind of report editor, where the user can select a desired font for specific text elements. We provide a list of fonts by enumerating them with the .Net functionality, e.g.:

List fonts = new List();
foreach (FontFamily font in System.Drawing.FontFamily.Families)
{
fonts.Add(font.Name);
}

Now suppose that user selects the “OCR-B-10 BT” font. This name won’t get recognized by the FontRepository class:

// works OK, the font is found
var windowsFont = new System.Drawing.Font(“OCR-B-10 BT”, 10);
System.Diagnostics.Debug.WriteLine(windowsFont.Name);

// does not work, throws an exception
var asposeFont = FontRepository.FindFont(“OCR-B-10 BT”);
System.Diagnostics.Debug.WriteLine(asposeFont.FontName);

So my question is: does the Aspose PDF export mechanism provide a way to specify the font by its “real” name (the one that windows recognizes as the valid one)?

Let me know if you need the ttf file for the OCR font (probably you can take it from my previous post). By the way: I tried to remove the spaces as you suggest (e.g. OCR-B-10BT), but it still does not work.

Thank you in advance for your support,

Boris

Hi Boris,


Thanks for your feedback. We have logged a ticket PDFNEWNET-38962 for further investigation and resolution. We will keep you updated about our findings within this forum thread.

We are sorry for the inconvenience caused.

Best Regards,