Interpreter
in package
Pdf extract content interpreter class
Tags
Table of Contents
Constants
- MAX_DO_DEPTH = 32
- Maximum Do-operator (Form XObject) recursion depth
Properties
- $actualTextPos : mixed
- Position captured for a pending ActualText replacement run
- $charSpace : float
- Character spacing
- $cm : array<string|int, mixed>
- Current transformation matrix
- $doc : Document
- Document being interpreted against
- $fontName : string|null
- Active font resource name
- $fontResolved : mixed
- Active font's resolved dictionary
- $fontResolvedKey : string|null
- Active font's precomputed cache key, computed once per Tf
- $fontSize : float
- Active font size
- $horizScale : float
- Horizontal scaling percentage
- $lastX : float|null
- Last emitted run's x position, used to compute the next run's separator
- $lastY : float|null
- Last emitted run's y position, used to compute the next run's separator
- $leading : float
- Text leading
- $markedStack : array<string|int, mixed>
- Marked-content stack, pushed/popped by BDC/BMC/EMC
- $qStack : array<string|int, mixed>
- Graphics state stack, pushed/popped by q/Q
- $runs : array<string|int, mixed>
- Text runs emitted so far
- $td : array<string|int, mixed>
- Text line matrix translation
- $tm : array<string|int, mixed>
- Text matrix
- $wordSpace : float
- Word spacing
Methods
- run() : array<string|int, mixed>
- Interpret a page's content stream against a document/resources, returning the extracted text runs
- decodePdfTextString() : string
- Decode a PDF text string, converting a UTF-16BE (BOM-prefixed) value to UTF-8
- dispatch() : void
- Dispatch one operator with its operands, updating interpreter state and/or emitting runs
- emitRun() : void
- Emit a text run, computing its separator relative to the previous run
- handleDo() : void
- Handle the Do operator, recursively interpreting a Form XObject's content stream
- interpret() : void
- Tokenize and dispatch a content stream's operators
- isReversedActive() : bool
- Determine if the marked-content stack currently has /ReversedChars active
- isSuppressingForActualText() : bool
- Determine if the marked-content stack is currently suppressing output for an ActualText replacement
- resetState() : void
- Reset all interpreter state to its initial values
- showText() : void
- Show text (Tj/TJ/'/"), either emitting a run or capturing an ActualText substitution's position
- skipInlineImage() : void
- Skip over an inline image (BI...ID...EI) without interpreting it
Constants
MAX_DO_DEPTH
Maximum Do-operator (Form XObject) recursion depth
protected
mixed
MAX_DO_DEPTH
= 32
Properties
$actualTextPos
Position captured for a pending ActualText replacement run
protected
mixed
$actualTextPos
= null
$charSpace
Character spacing
protected
float
$charSpace
= 0.0
$cm
Current transformation matrix
protected
array<string|int, mixed>
$cm
= ['a' => 1.0, 'b' => 0.0, 'i' => 0.0, 'j' => 1.0, 'x' => 0.0, 'y' => 0.0]
$doc
Document being interpreted against
protected
Document
$doc
$fontName
Active font resource name
protected
string|null
$fontName
= null
$fontResolved
Active font's resolved dictionary
protected
mixed
$fontResolved
= null
$fontResolvedKey
Active font's precomputed cache key, computed once per Tf
protected
string|null
$fontResolvedKey
= null
$fontSize
Active font size
protected
float
$fontSize
= 0.0
$horizScale
Horizontal scaling percentage
protected
float
$horizScale
= 100.0
$lastX
Last emitted run's x position, used to compute the next run's separator
protected
float|null
$lastX
= null
$lastY
Last emitted run's y position, used to compute the next run's separator
protected
float|null
$lastY
= null
$leading
Text leading
protected
float
$leading
= 0.0
$markedStack
Marked-content stack, pushed/popped by BDC/BMC/EMC
protected
array<string|int, mixed>
$markedStack
= []
$qStack
Graphics state stack, pushed/popped by q/Q
protected
array<string|int, mixed>
$qStack
= []
$runs
Text runs emitted so far
protected
array<string|int, mixed>
$runs
= []
$td
Text line matrix translation
protected
array<string|int, mixed>
$td
= ['x' => 0.0, 'y' => 0.0]
$tm
Text matrix
protected
array<string|int, mixed>
$tm
= ['a' => 1.0, 'b' => 0.0, 'i' => 0.0, 'j' => 1.0, 'x' => 0.0, 'y' => 0.0]
$wordSpace
Word spacing
protected
float
$wordSpace
= 0.0
Methods
run()
Interpret a page's content stream against a document/resources, returning the extracted text runs
public
run(Document $doc, string $content, array<string|int, mixed> $resources) : array<string|int, mixed>
Parameters
- $doc : Document
- $content : string
- $resources : array<string|int, mixed>
Return values
array<string|int, mixed>decodePdfTextString()
Decode a PDF text string, converting a UTF-16BE (BOM-prefixed) value to UTF-8
protected
decodePdfTextString(string $value) : string
Parameters
- $value : string
Return values
stringdispatch()
Dispatch one operator with its operands, updating interpreter state and/or emitting runs
protected
dispatch(string $op, array<string|int, mixed> $operands, array<string|int, mixed> $resources, array<string|int, mixed> $doStack, int $depth) : void
Parameters
- $op : string
- $operands : array<string|int, mixed>
- $resources : array<string|int, mixed>
- $doStack : array<string|int, mixed>
- $depth : int
emitRun()
Emit a text run, computing its separator relative to the previous run
protected
emitRun(string|null $rawBytes, string|null $decodedText, float $x, float $y) : void
Parameters
- $rawBytes : string|null
- $decodedText : string|null
- $x : float
- $y : float
handleDo()
Handle the Do operator, recursively interpreting a Form XObject's content stream
protected
handleDo(string $name, array<string|int, mixed> $resources, array<string|int, mixed> $doStack, int $depth) : void
Parameters
- $name : string
- $resources : array<string|int, mixed>
- $doStack : array<string|int, mixed>
- $depth : int
interpret()
Tokenize and dispatch a content stream's operators
protected
interpret(string $content, array<string|int, mixed> $resources, array<string|int, mixed> $doStack, int $depth) : void
Parameters
- $content : string
- $resources : array<string|int, mixed>
- $doStack : array<string|int, mixed>
- $depth : int
isReversedActive()
Determine if the marked-content stack currently has /ReversedChars active
protected
isReversedActive() : bool
Return values
boolisSuppressingForActualText()
Determine if the marked-content stack is currently suppressing output for an ActualText replacement
protected
isSuppressingForActualText() : bool
Return values
boolresetState()
Reset all interpreter state to its initial values
protected
resetState() : void
showText()
Show text (Tj/TJ/'/"), either emitting a run or capturing an ActualText substitution's position
protected
showText(string $bytes) : void
Parameters
- $bytes : string
skipInlineImage()
Skip over an inline image (BI...ID...EI) without interpreting it
protected
skipInlineImage(Tokenizer $tokenizer) : void
Parameters
- $tokenizer : Tokenizer