Parser
in package
Reads PDF objects from bytes, following the object syntax of ISO 32000-1, section 7.3.
Table of Contents
Constants
- DELIMITERS : mixed = '()<>[]{}/%'
- WHITESPACE : mixed = "\x00\t\n\f\r "
Properties
Methods
- __construct() : mixed
- indirectObject() : array{0: int, 1: int, 2: mixed}
- Reads an indirect object, `12 0 obj … endobj`, and the stream that follows its dictionary if it has one.
- position() : int
- The offset the next read starts at.
- seek() : void
- Moves to an offset.
- skipWhitespace() : void
- Skips whitespace and comments.
- startsWith() : bool
- Whether the next token, after any whitespace, starts with a keyword such as `xref` or `stream`.
- token() : string
- Reads the next run of regular characters: a number, a keyword, or an operator.
- value() : mixed
- Reads the next value.
- array() : array<int, mixed>
- Reads a `[…]` array.
- dictionary() : Dictionary
- Reads a `<<…>>` dictionary.
- endstreamAt() : bool
- Whether `endstream` follows an offset, after at most a line ending and some spaces.
- escape() : string
- Reads what follows a backslash in a literal string.
- hexString() : PdfString
- Reads a `<…>` string of hex digits; an odd final digit is followed by an implied 0.
- integerOrReference() : int|Reference
- An integer, or the reference it starts: `12 0 R`.
- literalString() : PdfString
- Reads a `(…)` string: balanced parentheses, backslash escapes, and line endings read as a line feed.
- name() : Name
- Reads a name, decoding `#xx` escapes.
- stream() : Stream
- Reads the data of a stream whose dictionary has just been read and whose `stream` keyword is next.
Constants
DELIMITERS
private
mixed
DELIMITERS
= '()<>[]{}/%'
WHITESPACE
private
mixed
WHITESPACE
= "\x00\t\n\f\r "
Properties
$bytes read-only
private
string
$bytes
$length read-only
private
int
$length
$position
private
int
$position
= 0
$resolve read-only
private
Closure|null
$resolve
= null
Methods
__construct()
public
__construct(string $bytes[, int $position = 0 ][, callable(Reference): mixed|null $resolve = null ]) : mixed
Parameters
- $bytes : string
-
The bytes to read.
- $position : int = 0
-
Where to start reading.
- $resolve : callable(Reference): mixed|null = null
-
Resolves an indirect object, for a stream whose
/Lengthis one.
indirectObject()
Reads an indirect object, `12 0 obj … endobj`, and the stream that follows its dictionary if it has one.
public
indirectObject(int $offset) : array{0: int, 1: int, 2: mixed}
Parameters
- $offset : int
-
Where the object starts.
Tags
Return values
array{0: int, 1: int, 2: mixed} —The object number, generation and value.
position()
The offset the next read starts at.
public
position() : int
Return values
intseek()
Moves to an offset.
public
seek(int $position) : void
Parameters
- $position : int
-
The offset to read from next.
skipWhitespace()
Skips whitespace and comments.
public
skipWhitespace() : void
startsWith()
Whether the next token, after any whitespace, starts with a keyword such as `xref` or `stream`.
public
startsWith(string $keyword) : bool
Parameters
- $keyword : string
-
The keyword.
Return values
booltoken()
Reads the next run of regular characters: a number, a keyword, or an operator.
public
token() : string
Return values
stringvalue()
Reads the next value.
public
value() : mixed
Tags
Return values
mixed —A Name, PdfString, Dictionary, Reference, list, int, float, bool or null.
array()
Reads a `[…]` array.
private
array() : array<int, mixed>
Return values
array<int, mixed>dictionary()
Reads a `<<…>>` dictionary.
private
dictionary() : Dictionary
Return values
DictionaryendstreamAt()
Whether `endstream` follows an offset, after at most a line ending and some spaces.
private
endstreamAt(int $offset) : bool
Parameters
- $offset : int
-
Where the stream's data would end.
Return values
boolescape()
Reads what follows a backslash in a literal string.
private
escape() : string
Return values
stringhexString()
Reads a `<…>` string of hex digits; an odd final digit is followed by an implied 0.
private
hexString() : PdfString
Return values
PdfStringintegerOrReference()
An integer, or the reference it starts: `12 0 R`.
private
integerOrReference(int $integer) : int|Reference
Parameters
- $integer : int
-
The integer just read.
Return values
int|ReferenceliteralString()
Reads a `(…)` string: balanced parentheses, backslash escapes, and line endings read as a line feed.
private
literalString() : PdfString
Return values
PdfStringname()
Reads a name, decoding `#xx` escapes.
private
name() : Name
Return values
Namestream()
Reads the data of a stream whose dictionary has just been read and whose `stream` keyword is next.
private
stream(Dictionary $dictionary) : Stream
Parameters
- $dictionary : Dictionary
-
The stream's dictionary.