class HexaPDF::Content::Parser


This class knows how to correctly parse a content stream.


A content stream is mostly just a stream of PDF objects. However, there is one exception: inline images.

Since inline images don’t follow the normal PDF object parsing rules, they need to be handled specially and this is the reason for this class. Therefore only the BI operator is ever called for inline images because the ID and EI operators are handled by the parser.

To parse some contents the parse method needs to be called with the contents to be parsed and a Processor object which is used for processing the parsed operators.

Public Class Methods

parse(contents, processor = nil, &block)

Creates a new Parser object and calls parse.

Public Instance Methods

parse(contents, processor = nil) { |object, params| ... }

Parses the contents and calls the processor object or the given block for each parsed operator.

If a full-blown Processor is not needed (e.g. because the graphics state doesn’t need to be maintained), one can use the block form to handle the parsed objects and their parameters.

Note: The parameters array is reused for each processed operator, so duplicate it if necessary.