How can I enumerate all Fonts in a PDF document and determine if a given font is embedded?

Q:

Could you please tell me how I can determine which fonts have been
embedded in a PDF document.

I have found the sample code to embed a font and to get/set the font
for elements on a page, but I didn't see anything for determining
which fonts have been embedded into the document.
---

A:
You can determine if the font is embedded in PDF using
font.IsEmbedded() method in pdftron.PDF.Font class.

Using PDFNet SDK there are several ways you can enumerate all fonts in
the document. For example,

1) you could use the same approach used to enumerate images in
ImageExtract or JBIG2 sample projects. Something along the following
lines:

// In C#
Doc cos_doc = doc.GetSDFDoc();
int num_objs = cos_doc.XRefSize();
for (int i=1; i<num_objs; ++i) {
  Obj obj = cos_doc.GetObj(i);
  if (obj!=null && !obj.IsFree()&& obj.IsStream()) {
    // Process only fonts
    DictIterator itr = obj.Find("Type");
    if (itr == obj.DictEnd() || itr.Value().GetName() != "Font")
continue;

    itr = obj.Find("BaseFont");
    if (itr == obj.DictEnd()) continue;

    pdftron.PDF.Font font = new pdftron.PDF.Font(obj);
    bool is_embedded = font.IsEmbedded();
  }
}

2) You could enumerate all font resources used on a given page. For
example:

// C# pseudocode
pdftron.SDF.Obj res = page.GetResources();
if (res != null) {
  SDF.Obj fonts = res.FindObj("Font")
  if (fonts != null) {
    SDF.DictInterator itr = fonts.DictBegin();
    SDF.DictInterator end = fonts.DictEnd();
    for (; itr!=end; itr.Next()) {
      Obj fnt_dict = itr.Value() // (in C++ use itr->second)
      pdftron.PDF.Font font = new pdftron.PDF.Font(fnt_dict);
      bool is_embedded = font.IsEmbedded();
  }
}

3) Finally if you are using ElementReader (see
http://www.pdftron.com/net/samplecode.html#ElementReaderAdv sample
project) to enumerate page contents you can simply obtain the
pdftron.PDF.Font object from any e_text Element object.