THotPDF.LoadFromRandomAccessSource
Loads a PDF through a caller-defined seekable byte source without requiring a TStream implementation
Declarations
THPDFRandomAccessSource = class
public
function GetSize: Int64; virtual; abstract;
function IsRangeAvailable(Offset, Count: Int64): Boolean; virtual;
function ReadAt(Offset: Int64; var Buffer;
Count: Longint): Longint; virtual; abstract;
function ReadAtCancellable(Offset: Int64; var Buffer;
Count: Longint; CancellationToken: THPDFCancellationToken): Longint; virtual;
end;
function LoadFromRandomAccessSource(
Source: THPDFRandomAccessSource;
OwnsSource: Boolean = False): Integer; overload;
function LoadFromRandomAccessSource(
Source: THPDFRandomAccessSource;
const Password: AnsiString;
OwnsSource: Boolean = False): Integer; overload;
Contract
GetSizereturns the stable byte length and must not return a negative valueReadAtreads at the supplied zero-based offset and returns a count from zero through the requested count- HotPDF automatically wraps ordinary sources in a 256 KiB range coalescer with a 2 MiB bounded cache and cancellation-aware asynchronous prefetch
- Passing an existing
THPDFCoalescingRandomAccessSourcepreserves caller-selected block, cache, ownership, and prefetch settings - Override
ReadAtCancellablewhen the backing transport can abort an in-flight request; its default implementation remains compatible with existingReadAt-only subclasses - The source must remain valid while the loaded document is in use unless
OwnsSourceisTrue - With ownership enabled, HotPDF frees the source when another source is loaded, when loading fails, or when the component is destroyed
- The password overload first reads bounded trailer and cross-reference ranges, then fetches the referenced encryption dictionary by its authoritative object offset so RC4 and AES password loading does not require a complete-source request on valid files
- Loading without a password captures the bounded raw encryption object and first trailer ID while the source is available; a later
DecryptLoadedDocumentcall uses the exact binaryO,U,OE, andUEvalues without rereading the source - If bounded key recovery cannot establish a supported key, HotPDF retains the complete-source compatibility fallback
The result is the loaded page count, matching LoadFromFile and LoadFromStream. Bounded password-key recovery is available since HotPDF v2.489.0, zero-reread delayed decryption is available since HotPDF v2.490.0, and automatic range coalescing is available since HotPDF v2.524.0
See also: Scalable Loading, THPDFCoalescingRandomAccessSource, LoadFromStream