PDFium Delphi Component Docs

TPdfProgressiveDocument class

Unit: PDFium  ·  Base class: TPdf
Native PDFium progressive-download session with sparse byte availability, prioritised range scheduling, bounded retries, cancellation, and document, form and page gates

Syntax

type TPdfProgressiveDocument = class(TPdf) ... end;

Methods

MethodDescription
CreateCreates the document component and its owned range-request scheduler
DestroyCancels progressive state before releasing inherited document resources
BeginProgressiveLoad(AStream, AFileSize, AOwnsStream, AInitialAvailableByteCount)Creates the native availability provider while keeping the logical final size separate from the bytes currently stored
CheckDocumentAvailabilityReturns pdaAvailable, pdaNotAvailable or pdaError and returns merged byte ranges requested by PDFium
OpenProgressiveDocumentOpens a linearised PDF through FPDFAvail_GetDocument or a fully received non-linearised PDF through FPDF_LoadCustomDocument
CheckFormAvailabilityGates form-fill initialisation until the native form data is available
LoadAvailablePageGates and loads one one-based page after form availability has reached a terminal state
CancelProgressiveLoadCloses the page, form, document, availability handle, callbacks and stream adapter in dependency order

Properties and events

MemberTypeDescription
ProgressiveLoadingBooleanTrue whilst the native availability session is alive
LogicalFileSizeUInt64Final content length supplied by the server or container
AvailableByteCountUInt64Monotonic length of the contiguous prefix already readable from the stream
LinearizationTPdfLinearizationNative linearisation verdict once enough header bytes are available
FirstAvailablePageNumberIntegerOne-based first page after the document handle is open
OnDataAvailableTPdfDataAvailableEventOverrides the prefix test for sparse or out-of-order range stores
RangeRequestsTPdfRangeRequestSchedulerOwned scheduler populated from every native document, form and page download hint

Description

TPdfProgressiveDocument owns the native FPDF_AVAIL handle and the callback records that PDFium may revisit throughout a remote or growing-stream load

Start with the server content length and any initial prefix, call the relevant availability method, dequeue work from RangeRequests, write each response into the backing random-access store, call CompleteRequest and repeat until a terminal availability state is returned

For a contiguous download, advance AvailableByteCount after writing new bytes; for a sparse range cache, assign OnDataAvailable and answer whether each requested offset and size is readable

The scheduler accepts the same native hints returned through the legacy DownloadHints output, removes ranges already known through the prefix or sparse callback, pre-empts overlapping background transfers for page-critical bytes without promoting adjacent tails, and splits transport work at MaxRequestSize

Linearised PDFs can open their document metadata and first page before the entire file arrives; non-linearised PDFs require the complete file and automatically use the normal native custom-stream loader

Example

var
  Hints: TPdfDownloadRanges;
  Request: TPdfRangeRequest;
  State: TPdfDataAvailability;
begin
  Progressive.BeginProgressiveLoad(CacheStream, ContentLength,
    False, InitialPrefixLength);
  repeat
    State := Progressive.CheckDocumentAvailability(Hints);
    while Progressive.RangeRequests.TryDequeue(Request) do
    begin
      FetchRangeIntoCache(Request.Offset, Request.Size);
      Progressive.RangeRequests.CompleteRequest(Request);
    end;
  until State <> pdaNotAvailable;
  if State = pdaAvailable then
    Progressive.OpenProgressiveDocument;
end;

Remarks

Related types

TPdfDataAvailability, TPdfDownloadRange, TPdfDownloadRanges, TPdfRangeRequest, TPdfRangeRequestPriority, TPdfRangeRequestStatistics, TPdfRangeRequestScheduler, TPdfDataAvailableEvent, TPdfLinearization, TPdfFormAvailability