PDFiumVCL Docs

LoadCustomDocument method

이 API 항목은 식별자, 시그니처, 코드 블록, PDF 용어를 원래 형태로 유지합니다.
Component: TPdf  ·  Unit: PDFium
Loads a PDF from any seekable TStream using PDFium's on-demand block reader, so multi-GB documents and remote / database-backed sources do not need an up-front in-memory copy.

Syntax

procedure LoadCustomDocument(AStream: TStream; AOwnsStream: Boolean = False);

Description

LoadCustomDocument is the streaming counterpart to the buffered LoadDocument overloads. It is backed by PDFium's FPDF_LoadCustomDocument entry point through the TPdfStreamAdapter helper class introduced in v1.8.0. PDFium pulls blocks from AStream only when needed, so the stream is not copied into memory: a TFileStream over a 4 GB PDF, an HTTP-backed TStream, or a database BLOB stream all become usable without staging the entire payload in RAM first.

AStream must support seeking. Its lifetime must extend until the document is closed (call UnloadDocument or set Active back to False). Pass AOwnsStream = True to hand stream ownership over to this TPdf — the adapter then frees AStream when UnloadDocument runs. Pass False when the caller wants to keep the stream alive after the document closes.

LoadCustomDocument is intentionally a separate method (not another LoadDocument overload) so callers passing a TMemoryStream subclass cannot accidentally bind to the buffered LoadDocument(TMemoryStream, Boolean) overload — the Pascal argument shape is identical but the semantics are very different (buffered vs. on-demand).

Remarks

Example

// Streaming load with stream ownership transferred to Pdf1
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create('C:\Huge.pdf', fmOpenRead or fmShareDenyWrite);
  Pdf1.LoadCustomDocument(Stream, True); // Pdf1 frees Stream on UnloadDocument
  Pdf1.Active := True;
  ShowMessage('Pages: ' + IntToStr(Pdf1.PageCount));
end;

// Externally-owned stream — caller frees it after UnloadDocument
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create('C:\Live.pdf', fmOpenRead or fmShareDenyNone);
  try
    Pdf1.LoadCustomDocument(Stream, False);
    Pdf1.Active := True;
    DoWork;
    Pdf1.Active := False;
  finally
    Stream.Free;
  end;
end;

See Also

LoadDocument, Active, Password, FileName