How to get the name of an embedded (TrueType) font?

Product: PDFNet.dll (.NET)
Product Version: 9.3.0-88327614b9

You save the embedded font with the function SetFont to the PDF Document.

TextWidget textWidget = TextWidget.Create(pdfDoc, xxx, yyy);
string fontFilepath = @"C:\WINDOWS\Fonts\comic.ttf";
textWidget.SetFont(pdftron.PDF.Font.CreateTrueTypeFont(pdfDoc, fontFilepath, true, true));

If you load the PDF Document and try to get the font(s) like this:

            for (PageIterator itr = pdfDoc.GetPageIterator(); itr.HasNext(); itr.Next())
            {
                Page page = itr.Current();
                int num_annots = page.GetNumAnnots();
                for (int i = 0; i < num_annots; ++i)
                {
                    Annot annot = page.GetAnnot(i);
                    TextWidget textWidget = new TextWidget(annot);
                    pdftron.PDF.Font font = textWidget.GetFont();
                    string embeddedFontName = font.GetEmbeddedFontName(); // ""
                    object embeddedFont = font.GetEmbeddedFont(); // null
                    bool isEmbedded = font.IsEmbedded(); // false
                    string nameame = font.GetName(); // Helvetica (??)

… you do not get the expected font (comic sans)

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:Forums:

Did you save the PDF file between your two sections of code?
The Font would be saved at the time of saving.

Also, if there was no text in the TextWidget, then there would not be any text to subset, so the SDK may optimize and not embed anything at all.

Hi Ryan,
thanks for your response. Yes I saved the PDF file.
The TextWidget has no text at this moment.

But I would like to set a text at runtime like this:

textWidget.SetText("It is a test.");
textWidget.RefreshAppearance();

The text appears with the standard font.

If there is a way to get the assigned font, you can do this

System.Drawing.Font font = new System.Drawing.Font("???ASSIGNED_FONT_NAME???", (float)SP.ConvertMetrics.TwipsToPoint((int)textWidget.GetFontSize()));
pdftron.PDF.Font tmpFont = pdftron.PDF.Font.CreateTrueTypeFont(pdfDoc, font, true, true);
textWidget.SetFont(tmpFont);

It is better to just use Font.Create for instance the following worked as expected for me.

using (PDFDoc doc = new PDFDoc())
{
	Page blank_page = doc.PageCreate();
	doc.PagePushBack(blank_page);

	string text = "Basic Text Field";
	TextWidget text1 = TextWidget.Create(doc, new Rect(110, 700, 380, 730));
	text1.SetFont(Font.Create(doc, "ComicSans", text));
	text1.SetText(text);
	text1.RefreshAppearance();
	blank_page.AnnotPushBack(text1);

	doc.Save(output_path + "forms_test1.pdf", 0);

	Console.WriteLine("Done.");
}