Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Pdf.Model

Classes, interfaces and records

classePdfError

inherits from Exception

(no public members)

classtPdfDocument

(no public members)

classtPdfObject

fixed-width patchable slots (/ByteRange)

tPdfObject

One PDF value. All values live in the arena of their tPdfDocument (the document frees every object it created), so values can be shared and mutated freely without ownership bookkeeping. Loaded top-level indirect objects carry their object number/generation in ObjNumber/ObjGeneration (-1 for direct values), which is what the incremental writer needs to re-emit an updated object under its original number.

constructor Create(aDocument: tPdfDocument; aKind: tPdfObjectKind); property Kind: tPdfObjectKind read fKind; property BoolValue: Boolean read fBoolValue write fBoolValue; property IntValue: Int64 read fIntValue write fIntValue; property RealValue: Double read fRealValue write fRealValue; property StrValue: OctetString read fStrValue write fStrValue;
StrValue holds the raw bytes of a pokString or pokRaw, or the decoded (unescaped) name of a pokName.
property HexString: Boolean read fHexString write fHexString; property RefNumber: Integer read fRefNumber write fRefNumber; property RefGeneration: Integer read fRefGeneration write fRefGeneration; property ObjNumber: Integer read fObjNumber write fObjNumber; property ObjGeneration: Integer read fObjGeneration write fObjGeneration; property Document: tPdfDocument read fDocument;

classtPdfArray

inherits from tPdfObject

tPdfArray - pokArray; items are arena objects.

constructor Create(aDocument: tPdfDocument); destructor Destroy; override; procedure Add(aValue: tPdfObject); property Count: Integer read get_Count; property Items[aIndex: Integer]: tPdfObject read get_Items; default;

classtPdfDictionary

inherits from tPdfObject

tPdfDictionary - pokDictionary. Keys are decoded name strings.

constructor Create(aDocument: tPdfDocument); destructor Destroy; override; function GetValue(const aKey: string): tPdfObject;
GetValue returns the raw value (which may be a pokReference), or nil.
function Get(const aKey: string): tPdfObject;
Get returns the value with references resolved through the document.
function GetInt(const aKey: string; aDefault: Int64): Int64; function GetName(const aKey: string): string; function GetDictionary(const aKey: string): tPdfDictionary; function GetArray(const aKey: string): tPdfArray; procedure SetValue(const aKey: string; aValue: tPdfObject); procedure SetInteger(const aKey: string; aValue: Int64); procedure SetName(const aKey, aName: string); procedure SetString(const aKey: string; const aValue: OctetString; aHex: Boolean = False); procedure SetReference(const aKey: string; aNumber, aGeneration: Integer); procedure RemoveKey(const aKey: string); function HasKey(const aKey: string): Boolean;
Returns True if fKeys.IndexOf(aKey) is greater than or equal to 0; otherwise False.
property Count: Integer read get_Count; property KeyName[aIndex: Integer]: string read get_KeyName; property ValueByIndex[aIndex: Integer]: tPdfObject read get_ValueByIndex;

classtPdfStream

inherits from tPdfDictionary

tPdfStream - pokStream: a dictionary plus raw (still encoded) data. DecodedData applies FlateDecode (+ PNG predictors) on demand.

constructor Create(aDocument: tPdfDocument); property Data: OctetString read fData write fData;
Data is the raw stream content exactly as stored in the file.
function DecodedData: OctetString;
DecodedData applies the /Filter chain. Supported: no filter and FlateDecode with optional /DecodeParms predictors - the encodings used by cross-reference and object streams. Anything else raises.

recordtPdfXrefEntry

tPdfXrefEntry - one cross-reference entry, all three ISO 32000 types.

fEntryType: Byte;
0 = free, 1 = offset in file, 2 = in object stream
fOffset: Int64;
type 1: byte offset; type 2: object stream NUMBER
fGeneration: Integer;
type 1: generation; type 2: index within stream
fPresent: Boolean;

classtPdfDocument

tPdfDocument

Loads a PDF from a stream or octet string, exposes the trailer, the cross-reference map and on-demand object loading (including objects inside object streams), plus factories for building new values in the document arena. The full file stays in Buffer - the signer needs the original bytes for ByteRange digesting anyway.

constructor Create; destructor Destroy; override; procedure LoadFromStream(aStream: TStream); procedure LoadFromOS(const aData: OctetString); function GetObject(aNumber: Integer): tPdfObject;
GetObject loads (and caches) the indirect object aNumber. Returns nil for free/absent entries.
function Resolve(aValue: tPdfObject): tPdfObject;
Resolve dereferences aValue while it is a pokReference (nil-safe).
function ResolveDictionary(aValue: tPdfObject): tPdfDictionary; function Root: tPdfDictionary;
Root returns the document catalog; FirstPage the first /Type/Page leaf of the page tree (both resolved, with ObjNumber set when indirect).
function FirstPage: tPdfDictionary; function IsEncrypted: Boolean;
Delegates to Assigned, passing 1 argument(s), and returns its result.
function MaxObjectNumber: Integer; function ObjectLocation(aNumber: Integer; out aType: Byte; out aOffset: Int64; out aGeneration: Integer): Boolean;
ObjectLocation reports WHERE the cross-reference map places object aNumber, without loading it: aType is the xref entry type (1 = at a byte offset, 2 = inside an object stream), aOffset the file offset (type 1) or the container object number (type 2), aGeneration the generation (type 1) or the in... Full description »
function NewNull: tPdfObject;
Arena factories:
function NewBoolean(aValue: Boolean): tPdfObject; function NewInteger(aValue: Int64): tPdfObject; function NewReal(aValue: Double): tPdfObject; function NewString(const aValue: OctetString; aHex: Boolean = False): tPdfObject; function NewName(const aName: string): tPdfObject; function NewRaw(const aBytes: OctetString): tPdfObject; function NewReference(aNumber, aGeneration: Integer): tPdfObject; function NewArray: tPdfArray;
Delegates to tPdfArray.Create, forwarding Self, and returns its result.
function NewDictionary: tPdfDictionary;
Delegates to tPdfDictionary.Create, forwarding Self, and returns its result.
function NewStreamObject: tPdfStream;
Delegates to tPdfStream.Create, forwarding Self, and returns its result.
property Buffer: OctetString read fBuffer; property Trailer: tPdfDictionary read fTrailer; property StartXref: Int64 read fStartXref; property XrefIsStream: Boolean read fXrefIsStream; property Version: string read fVersion;

recordtPdfEmittedObject

tPdfEmittedObject - where one object body landed inside the emitted increment (offsets relative to the increment start).

fNumber: Integer; fGeneration: Integer; fOffset: Int64; fLength: Int64;

classtPdfIncrementalUpdate

tPdfIncrementalUpdate

Collects new objects (AddObject assigns the next free number) and updated existing objects (ReplaceObject re-emits under the original number), then Emit produces the complete byte suffix to append to the original file: object bodies, the cross-reference section (classic or stream, matching the original file's form), trailer with /Prev = the previous startxref, startxref and %%EOF. Emitted object positions are reported so a caller can patch fixed-width placeholders (the signature workflow).

constructor Create(aDocument: tPdfDocument); function AddObject(aObj: tPdfObject): Integer;
AddObject registers aObj as a NEW indirect object and returns its number (generation 0).
procedure ReplaceObject(aObj: tPdfObject);
ReplaceObject re-emits an EXISTING object (typically mutated in place) under its original number/generation in this update.
function Emit(aBaseLength: Int64): OctetString;
Emit serializes the update. aBaseLength is the byte length of the original file the update will be appended to (used for offsets).
function EmittedCount: Integer;
Delegates to Length, forwarding fEmitted, and returns its result.
function EmittedObject(aIndex: Integer): tPdfEmittedObject;

Types (enumerations, sets, aliases)

enumtPdfObjectKind

  tPdfObjectKind = (pokNull,
                    pokBoolean,
                    pokInteger,
                    pokReal,
                    pokString,
                    pokName,
                    pokArray,
                    pokDictionary,
                    pokStream,
                    pokReference,
                    pokRaw); // verbatim bytes, used by the writer for

Routines