Show / Hide Table of Contents

Class ElementReader

ElementReader can be used to parse and process content streams. ElementReader provides a convenient interface used to traverse the Element display list of a page. The display list representing graphical elements (such as text-runs, paths, images, shadings, forms, etc) is accessed using the intrinsic iterator. ElementReader automatically concatenates page contents spanning multiple streams and provides a mechanism to parse contents of sub-display lists (e.g. forms XObjects and Type3 fonts).

Inheritance
System.Object
ElementReader
Implements
System.IDisposable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: pdftron.PDF
Assembly: PDFNet.dll
Syntax
public class ElementReader : IDisposable
Examples

For a full sample, please refer to ElementReader and ElementReaderAdv sample projects. A sample use case for ElementReader is given below:

  
...
ElementReader reader=new ElementReader();
reader.Begin(page);
for (Element element=reader.next(); element!=null;element=reader.next()) {
Rect bbox;
if((bbox=element.getBBox())!=null) System.out.println("Bounding Box: " + bbox.getRectangle());
switch (element.getType())	{
case Element.e_path: { // Process path data...
double[] data = element.getPathPoints();
}
break; 
case Element.e_text: 
// ...
break;
}
}
reader.End();	    

Constructors

ElementReader()

Instantiates a new element reader.

Declaration
public ElementReader()
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Methods

Begin(Page)

Begin processing a page.

Declaration
public void Begin(Page page)
Parameters
Type Name Description
Page page

A page to start processing.

Remarks

When page processing is completed, make sure to call ElementReader.End().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Begin(Page, Context)

Begin processing a page.

Declaration
public void Begin(Page page, Context ctx)
Parameters
Type Name Description
Page page

A page to start processing.

Context ctx

the ctx

Remarks

When page processing is completed, make sure to call ElementReader.End().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Begin(Obj)

Begin processing given content stream. The content stream may be a Form XObject, Type3 glyph stream, pattern stream or any other content stream.

Declaration
public void Begin(Obj content_stream)
Parameters
Type Name Description
Obj content_stream
  • A stream object representing the content stream (usually a Form XObject).
Remarks

When page processing is completed, make sure to call ElementReader.End().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Begin(Obj, Obj)

Begin processing given content stream. The content stream may be a Form XObject, Type3 glyph stream, pattern stream or any other content stream.

Declaration
public void Begin(Obj content_stream, Obj resource_dict)
Parameters
Type Name Description
Obj content_stream
  • A stream object representing the content stream (usually a Form XObject).
Obj resource_dict
  • An optional '/Resource' dictionary parameter. If content stream refers to named resources that are not present in the local Resource dictionary, the names are looked up in the supplied resource dictionary.
Remarks

When page processing is completed, make sure to call ElementReader.End().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Begin(Obj, Obj, Context)

Begin processing given content stream. The content stream may be a Form XObject, Type3 glyph stream, pattern stream or any other content stream.

Declaration
public void Begin(Obj content_stream, Obj resource_dict, Context ctx)
Parameters
Type Name Description
Obj content_stream
  • A stream object representing the content stream (usually a Form XObject).
Obj resource_dict
  • An optional '/Resource' dictionary parameter. If content stream refers to named resources that are not present in the local Resource dictionary, the names are looked up in the supplied resource dictionary.
Context ctx

the ctx

Remarks

When page processing is completed, make sure to call ElementReader.End().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

ClearChangeList()

Clear the list containing identifiers of modified graphics state attributes. The list of modified attributes is then accumulated during a subsequent call(s) to ElementReader.Next().

Declaration
public void ClearChangeList()
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Current()

Current.

Declaration
public Element Current()
Returns
Type Description
Element

the current Element or a 'NULL' Element. The current element is the one returned in the last call to Next().

Remarks

Every call to ElementReader::Next() destroys the current Element. Therefore, an Element becomes invalid after subsequent ElementReader::Next() operation.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Dispose()

Releases all resources used by the ElementReader

Declaration
public override sealed void Dispose()

Dispose(Boolean)

Declaration
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0)
Parameters
Type Name Description
System.Boolean A_0

End()

Close the current display list.

If the current display list is a sub-list created using FormBegin(), PatternBegin(), or Type3FontBegin() methods, the function will end the sub-list and will return processing to the parent display list at the point where it left off before entering the sub-list.

Declaration
public bool End()
Returns
Type Description
System.Boolean

true if the closed display list is a sub-list or false if it is a root display list.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Finalize()

Declaration
protected void Finalize()

FormBegin()

When the current element is a form XObject you have the option to skip form processing (by not calling FormBegin()) or to open the form stream and continue Element traversal into the form.

To open a form XObject display list use FormBegin() method. The Next() returned Element will be the first Element in the form XObject display list. Subsequent calls to Next() will traverse form's display list until NULL is returned. At any point you can close the form sub-list using ElementReader::End() method. After the form display list is closed (using End()) the processing will return to the parent display list at the point where it left off before entering the form XObject.

Declaration
public void FormBegin()
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

GetChangesIterator()

Gets the changes iterator.

Declaration
public GSChangesIterator GetChangesIterator()
Returns
Type Description
GSChangesIterator

an iterator to the beginning of the list containing identifiers of modified graphics state attributes since the last call to ClearChangeList(). The list can be consulted to determine which graphics states were modified between two Elements. Attributes are ordered in the same way as they are set in the content stream. Duplicate attributes are eliminated.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

GetColorSpace(String)

Gets the color space.

Declaration
public Obj GetColorSpace(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

the color space

Remarks

see ElementReader::GetFont

GetExtGState(String)

Gets the ext g state.

Declaration
public Obj GetExtGState(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

the ext g state

Remarks

see ElementReader::GetFont

GetFont(String)

Gets the font.

Declaration
public Obj GetFont(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

SDF/Cos object matching the specified name in the current resource dictionary. For 'Page' the name is looked up in the page's /Resources/<Class> dictionary. For Form XObjects, Patterns, and Type3 fonts that have a content stream within page content stream the specified resource is first looked-up in the resource dictionary of the inner stream. If the resource is not found, the name is looked up in the outer content stream's resource dictionary. The function returns NULL if the resource was not found.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

GetPattern(String)

Gets the pattern.

Declaration
public Obj GetPattern(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

the pattern

Remarks

see ElementReader::GetFont

GetShading(String)

Gets the shading.

Declaration
public Obj GetShading(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

the shading

Remarks

see ElementReader::GetFont

GetXObject(String)

Gets the x object.

Declaration
public Obj GetXObject(string name)
Parameters
Type Name Description
System.String name

the name

Returns
Type Description
Obj

the x object

Remarks

see ElementReader::GetFont

IsChanged(GState.GStateAttribute)

Checks if is changed.

Declaration
public bool IsChanged(GState.GStateAttribute attrib)
Parameters
Type Name Description
GState.GStateAttribute attrib

the gstate_attrib

Returns
Type Description
System.Boolean

true if given GState attribute was changed since the last call to ClearChangeList().

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Next()

Next.

Declaration
public Element Next()
Returns
Type Description
Element

a page Element or a 'NULL' element if the end of current-display list was reached. You may use GetType() to determine the type of the returned Element.

Remarks

Every call to ElementReader::Next() destroys the current Element. Therefore, an Element becomes invalid after subsequent ElementReader::Next() operation.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

PatternBegin(Boolean)

Pattern begin.

Declaration
public void PatternBegin(bool fill_pattern)
Parameters
Type Name Description
System.Boolean fill_pattern

the fill_pattern

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

PatternBegin(Boolean, Boolean)

A method used to spawn the sub-display list representing the tiling pattern of the current element in the ElementReader. You can call this method at any point as long as the current element is valid.

Declaration
public void PatternBegin(bool fill_pattern, bool reset_ctm_tfm)
Parameters
Type Name Description
System.Boolean fill_pattern

If true, the filling pattern of the current element will be spawned; otherwise, the stroking pattern of the current element will be spawned. Note that the graphics state will be inherited from the parent content stream (the content stream in which the pattern is defined as a resource) automatically.

System.Boolean reset_ctm_tfm

An optional parameter used to indicate whether the pattern's display list should set its initial CTM and transformation matrices to identity matrix. In general, we should leave it to be false.

To open a tiling pattern sub-display list use PatternBegin() method. The Next() returned Element will be the first Element in the pattern display list. Subsequent calls to Next() will traverse pattern's display list until NULL is encountered. At any point you can close the pattern sub-list using ElementReader::End() method. After the pattern display list is closed, the processing will return to the parent display list at the point where pattern display list was spawned.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Type3FontBegin(CharData)

A method used to spawn a sub-display list representing a Type3 Font glyph. You can call this method at any point as long as the current element in the ElementReader is a text element whose font type is type 3.

Declaration
public void Type3FontBegin(CharData char_data)
Parameters
Type Name Description
CharData char_data

The information about the glyph to process. You can get this information by dereferencing a CharIterator.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Implements

System.IDisposable
Back to top Generated by DocFX