PDF-Signer

Document
in package

FinalYes

An existing PDF, read far enough to revise it with an incremental update.

It follows the chain of cross-reference sections from the end of the file, tables and streams alike, reads objects on demand, including those packed into object streams, and walks the page tree. Where an offset is wrong it falls back to finding objects by scanning the file, as PDF viewers do.

Table of Contents

Properties

$bytes  : string
$objects  : array<int, mixed>
$objectStreams  : array<int, array{0: string, 1: array}>
$pages  : array<int, Page>|null
$scanned  : array<int, int>|null
$startxref  : int
$trailer  : Dictionary
$xref  : array<int, array{0: int, 1: int, 2: int}>
Where each object is: `[1, offset, generation]`, `[2, object stream, index]`, or `[0, 0, 0]` when it is free.
$xrefIsStream  : bool

Methods

bytes()  : string
The document's bytes, exactly as read.
fromString()  : self
Reads a PDF from its bytes.
hasDigitalSignatures()  : bool
Whether the document carries a digital signature, which rewriting it would invalidate.
isEncrypted()  : bool
Whether the document is encrypted.
object()  : mixed
An indirect object's value, or null when it does not exist, as PDF defines a missing object.
open()  : self
Reads a PDF file.
pages()  : array<int, Page>
The pages, in order.
resolve()  : mixed
A value with any indirect references followed.
size()  : int
One more than the highest object number in use: where new objects start.
startxref()  : int
The offset of the newest cross-reference section, which an update's `/Prev` points to.
trailer()  : Dictionary
The newest trailer, with entries only older ones set filled in from them.
xrefIsStream()  : bool
Whether the newest cross-reference section is a stream, which an update should then use too.
__construct()  : mixed
box()  : array{float, float, float, float}|null
A rectangle, normalised to lower-left and upper-right, or null when it is not one.
collectPages()  : void
Adds the pages under a page tree node, applying the attributes pages inherit.
parser()  : Parser
A parser over the whole file that can resolve an indirect stream length.
readAt()  : mixed
Reads the object at an offset, falling back to scanning when it is not the object expected there.
readCompressed()  : mixed
Reads an object packed into an object stream.
readCrossReferences()  : void
Follows the cross-reference sections from the last `startxref` back through `/Prev`.
readScanned()  : mixed
Reads an object from where scanning the file found it, or null when it is nowhere.
readSection()  : Dictionary, 1: bool}
Reads one cross-reference section, table or stream.
readStreamEntries()  : void
Reads a cross-reference stream's entries.
readTable()  : Dictionary
Reads a cross-reference table's entries, and the trailer after them.
rebuildFromScan()  : void
Rebuilds the document's structure by scanning, for a file whose cross-references are missing or broken.
resolveLength()  : mixed
Resolves a stream's indirect `/Length`.
scan()  : void
Finds every `n g obj` in the file; the last one for a number wins, as in an update.

Properties

$objects

private array<int, mixed> $objects = []

$objectStreams

private array<int, array{0: string, 1: array}> $objectStreams = []

Decoded object streams: their data, and each object's offset in it.

$scanned

private array<int, int>|null $scanned = null

Offsets found by scanning, when the cross-reference sections cannot be trusted.

$xref

Where each object is: `[1, offset, generation]`, `[2, object stream, index]`, or `[0, 0, 0]` when it is free.

private array<int, array{0: int, 1: int, 2: int}> $xref = []

$xrefIsStream

private bool $xrefIsStream = false

Methods

bytes()

The document's bytes, exactly as read.

public bytes() : string
Return values
string

fromString()

Reads a PDF from its bytes.

public static fromString(string $bytes) : self
Parameters
$bytes : string

The PDF.

Tags
throws
PdfException

The bytes are not a PDF.

Return values
self

hasDigitalSignatures()

Whether the document carries a digital signature, which rewriting it would invalidate.

public hasDigitalSignatures() : bool
Return values
bool

isEncrypted()

Whether the document is encrypted.

public isEncrypted() : bool
Return values
bool

object()

An indirect object's value, or null when it does not exist, as PDF defines a missing object.

public object(int $number) : mixed
Parameters
$number : int

The object number.

open()

Reads a PDF file.

public static open(string $path) : self
Parameters
$path : string

The file.

Tags
throws
PdfException

The file could not be read, or is not a PDF.

Return values
self

pages()

The pages, in order.

public pages() : array<int, Page>
Tags
throws
PdfException

The document has no page tree.

Return values
array<int, Page>

resolve()

A value with any indirect references followed.

public resolve(mixed $value) : mixed
Parameters
$value : mixed

A value that may be a Reference.

size()

One more than the highest object number in use: where new objects start.

public size() : int
Return values
int

startxref()

The offset of the newest cross-reference section, which an update's `/Prev` points to.

public startxref() : int
Return values
int

xrefIsStream()

Whether the newest cross-reference section is a stream, which an update should then use too.

public xrefIsStream() : bool
Return values
bool

__construct()

private __construct(string $bytes) : mixed
Parameters
$bytes : string

box()

A rectangle, normalised to lower-left and upper-right, or null when it is not one.

private box(mixed $value) : array{float, float, float, float}|null
Parameters
$value : mixed

The rectangle as stored.

Return values
array{float, float, float, float}|null

collectPages()

Adds the pages under a page tree node, applying the attributes pages inherit.

private collectPages(mixed $node, array<string, mixed> $inherited, array<int, true> &$visited) : void
Parameters
$node : mixed

The node, usually a reference.

$inherited : array<string, mixed>

Resources, MediaBox, CropBox and Rotate set by its ancestors.

$visited : array<int, true>

Nodes already walked, so a loop in the tree cannot recurse forever.

parser()

A parser over the whole file that can resolve an indirect stream length.

private parser() : Parser
Return values
Parser

readAt()

Reads the object at an offset, falling back to scanning when it is not the object expected there.

private readAt(int $offset, int $number) : mixed
Parameters
$offset : int

Where the cross-reference section says it is.

$number : int

The object number expected.

readCompressed()

Reads an object packed into an object stream.

private readCompressed(int $streamNumber, int $index, int $number) : mixed
Parameters
$streamNumber : int

The object stream.

$index : int

The object's position in it.

$number : int

The object number.

readCrossReferences()

Follows the cross-reference sections from the last `startxref` back through `/Prev`.

private readCrossReferences() : void

readScanned()

Reads an object from where scanning the file found it, or null when it is nowhere.

private readScanned(int $number) : mixed
Parameters
$number : int

The object number.

readSection()

Reads one cross-reference section, table or stream.

private readSection(int $offset) : Dictionary, 1: bool}
Parameters
$offset : int

Where it starts.

Return values
Dictionary, 1: bool} —

Its trailer dictionary, and whether it was a stream.

readStreamEntries()

Reads a cross-reference stream's entries.

private readStreamEntries(Stream $stream) : void
Parameters
$stream : Stream

The stream, whose dictionary is also a trailer.

readTable()

Reads a cross-reference table's entries, and the trailer after them.

private readTable(int $offset) : Dictionary
Parameters
$offset : int

Just after the xref keyword.

Return values
Dictionary

rebuildFromScan()

Rebuilds the document's structure by scanning, for a file whose cross-references are missing or broken.

private rebuildFromScan() : void
Tags
throws
PdfException

No document catalog could be found.

resolveLength()

Resolves a stream's indirect `/Length`.

private resolveLength(Reference $reference) : mixed
Parameters
$reference : Reference

The length object.

scan()

Finds every `n g obj` in the file; the last one for a number wins, as in an update.

private scan() : void
On this page

Search results