new 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).
For a full sample, please refer to ElementReader and ElementReaderAdvTest sample projects.
Extends
Methods
-
<static> create()
-
Constructor for an ElementReader object that can be used to parse and process content streams.
Returns:
A promise that resolves to Returns an ElementReader object- Type
- Promise.<Core.PDFNet.ElementReader>
-
appendResource(res)
-
Parameters:
Name Type Description res
Core.PDFNet.Obj resource dictionary for finding images, fonts, etc. Returns:
- Type
- Promise.<void>
-
begin(content_stream [, resource_dict] [, ctx])
-
begin processing given content stream. The content stream may be a Form XObject, Type3 glyph stream, pattern stream or any other content stream.
Parameters:
Name Type Argument Description content_stream
Core.PDFNet.Obj A stream object representing the content stream (usually a Form XObject). resource_dict
Core.PDFNet.Obj <optional>
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. ctx
Core.PDFNet.OCGContext <optional>
An optional parameter used to specify the Optional Content (OC) Context that should be used when processing the page. When the OCG::Context is specified, Element::IsOCVisible() will return 'true' or 'false' depending on the visibility of the current Optional Content Group (OCG) and the states of flags in the given context. Note: When page processing is completed, make sure to call ElementReader.End(). Returns:
- Type
- Promise.<void>
-
beginOnPage(page [, ctx])
-
begin processing a page.
Parameters:
Name Type Argument Description page
Core.PDFNet.Page A page to start processing. ctx
Core.PDFNet.OCGContext <optional>
An optional parameter used to specify the Optional Content (OC) Context that should be used when processing the page. When the OCG::Context is specified, Element::IsOCVisible() will return 'true' or 'false' depending on the visibility of the current Optional Content Group (OCG) and the states of flags in the given context. Note: When page processing is completed, make sure to call ElementReader.End(). Returns:
- Type
- Promise.<void>
-
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().
Returns:
- Type
- Promise.<void>
-
current()
-
Returns:
A promise that resolves to the current Element or a 'NULL' Element. The current element is the one returned in the last call to Next(). Note: Every call to ElementReader::Next() destroys the current Element. Therefore, an Element becomes invalid after subsequent ElementReader::Next() operation.- Type
- Promise.<Core.PDFNet.Element>
-
destroy()
-
Destructor
- Inherited From:
Returns:
- Type
- Promise.<void>
-
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.
Returns:
A promise that resolves to true if the closed display list is a sub-list or false if it is a root display list.- Type
- Promise.<boolean>
-
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.
Returns:
- Type
- Promise.<void>
-
getChangesIterator()
-
Returns:
A promise that resolves to 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.- Type
- Promise.<Core.PDFNet.Iterator.<number>>
-
getColorSpace(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Note: see ElementReader::GetFont Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
getExtGState(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Note: see ElementReader::GetFont Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
getFont(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Returns:
A promise that resolves to sDF/Cos object matching the specified name in the current resource dictionary. For 'Page' the name is looked up in the page's /Resources/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. - Type
- Promise.<Core.PDFNet.Obj>
-
getPattern(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Note: see ElementReader::GetFont Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
getShading(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Note: see ElementReader::GetFont Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
getXObject(name)
-
Parameters:
Name Type Description name
string string of the name of the SDF/Cos object to get Note: see ElementReader::GetFont Returns:
A promise that resolves to an object of type: "PDFNet.Obj"- Type
- Promise.<Core.PDFNet.Obj>
-
isChanged(attrib)
-
Parameters:
Name Type Description attrib
number PDFNet.GState.Attribute = { e_transform : 0 e_rendering_intent : 1 e_stroke_cs : 2 e_stroke_color : 3 e_fill_cs : 4 e_fill_color : 5 e_line_width : 6 e_line_cap : 7 e_line_join : 8 e_flatness : 9 e_miter_limit : 10 e_dash_pattern : 11 e_char_spacing : 12 e_word_spacing : 13 e_horizontal_scale : 14 e_leading : 15 e_font : 16 e_font_size : 17 e_text_render_mode : 18 e_text_rise : 19 e_text_knockout : 20 e_text_pos_offset : 21 e_blend_mode : 22 e_opacity_fill : 23 e_opacity_stroke : 24 e_alpha_is_shape : 25 e_soft_mask : 26 e_smoothnes : 27 e_auto_stoke_adjust : 28 e_stroke_overprint : 29 e_fill_overprint : 30 e_overprint_mode : 31 e_transfer_funct : 32 e_BG_funct : 33 e_UCR_funct : 34 e_halftone : 35 e_null : 36 }
the GState attribute to test if it has been changed ClearChangeList().Returns:
A promise that resolves to true if given GState attribute was changed since the last call to- Type
- Promise.<boolean>
-
next()
-
Returns:
A promise that resolves to 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. Note: Every call to ElementReader::Next() destroys the current Element. Therefore, an Element becomes invalid after subsequent ElementReader::Next() operation.- Type
- Promise.<Core.PDFNet.Element>
-
patternBegin(fill_pattern [, reset_ctm_tfm])
-
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.
Parameters:
Name Type Argument Description fill_pattern
boolean 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. reset_ctm_tfm
boolean <optional>
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(pattern) 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. Returns:
- Type
- Promise.<void>
-
takeOwnership()
-
Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
- Inherited From:
Returns:
- Type
- void
-
type3FontBegin(char_data [, resource_dict])
-
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.
Parameters:
Name Type Argument Description char_data
Core.PDFNet.CharData The information about the glyph to process. You can get this information by dereferencing a CharIterator. resource_dict
Core.PDFNet.Obj <optional>
An optional '/Resource' dictionary parameter. If any glyph descriptions refer to named resources but Font Resource dictionary is absent, the names are looked up in the supplied resource dictionary. To open a Type3 font sub-display list use Type3FontBegin() method. The Next() returned Element will be the first Element in the glyph's display list. Subsequent calls to Next() will traverse glyph's display list until NULL is returned. At any point you can close the glyph sub-list using ElementReader::End() method. After the glyph display list is closed, the processing will return to the parent display list at the point where glyph display list was spawned. Returns:
- Type
- Promise.<void>