Using ElementReader to read content from random Form XObjects

Q:

When traversing through PDF page elements with an ElementReader everything works fine.

But if I try to use ElementReader to read content from some other form XObjects (e.g. Type3 fonts or some forms referenced from a page, or “Root”.“Pages”.“Kids”[0].“Kids”[0].“Contents”)

as is:

Dim elm_reader As New ElementReader

elm_reader.Begin(objX)

ProcessElements(elm_reader, objNode, MaxLev)

elm_reader.End()

ALMOST everything works fine.

BUT when the elm = reader.Next() gets to what should give an e_image element (e.g. fourth e_group_begin, and first e_group_begin inside that on above example), I get an Exception, if I try elm = reader.Next() again it continues just fine with the next element.

The exception I get is

pdftron.Common.PDFNetException: Exception:

Message: Missing resource

at pdftron.PDF.ElementReader.Next()

Is this a bug, or am I doing something wrong?

A:

The most likely problem is that ElementReader can’t find the required XObject in the resource dictionary of the given stream (e.g. as is the case with page content streams etc.). In this case you need to explicitly provide the resource dictionary that ElementReader can consult when reading elements. There are two options:

a) Use ElementReader.Begin(xobject, resource_dict)

b) Use ElementReader.AppendResource(resource_dict) before traversing elements with ElementReader.Next()