PDFium Delphi Component Docs

LoadCustomDocument 메서드

컴포넌트: TPdf  ·  유닛: PDFium
PDFium의 온디맨드 블록 리더로 seek 가능한 임의의 TStream에서 PDF를 로드합니다. 수 GB 문서나 원격·데이터베이스 기반 소스도 미리 메모리에 올려 두지 않고 사용할 수 있습니다

Syntax

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

procedure LoadCustomDocument(AStream: TStream; AOwnsStream: Boolean; const Options: TPdfLoadOptions; out Report: TPdfLoadReport);

Description

LoadCustomDocument는 버퍼링 LoadDocument 오버로드의 스트리밍 짝입니다. v1.8.0에서 도입된 TPdfStreamAdapter 헬퍼 클래스를 통해 PDFium의 FPDF_LoadCustomDocument 진입점으로 구동됩니다. PDFium은 필요할 때만 AStream에서 블록을 끌어오므로 스트림은 메모리로 복사되지 않습니다. 4 GB PDF를 덮은 TFileStream, HTTP 기반 TStream, 데이터베이스 BLOB 스트림 모두 페이로드 전체를 RAM에 임시 저장하지 않고 사용할 수 있습니다

AStream은 시킹을 지원해야 합니다. 수명은 문서가 닫힐 때까지 이어져야 합니다(UnloadDocument를 호출하거나 Active를 False로 되돌리세요). AOwnsStream = True를 넘기면 스트림 소유권이 이 TPdf로 넘어가고, UnloadDocument가 실행될 때 어댑터가 AStream을 해제합니다. 문서가 닫힌 뒤에도 호출자가 스트림을 살려 두려면 False를 넘기세요

LoadCustomDocument는 의도적으로 별개의 메서드입니다(또 다른 LoadDocument 오버로드가 아닙니다). TMemoryStream 서브클래스를 넘기는 호출자가 버퍼링 LoadDocument(TMemoryStream, Boolean) 오버로드에 실수로 묶이는 일을 막기 위해서입니다. Pascal 인자 모양은 같지만 의미는 전혀 다릅니다(버퍼링 대 온디맨드)

정책 오버로드는 LoadDocument에 문서화된 호환·엄격·복구 동작과 유한한 xref 감사를 똑같이 적용합니다. 감사는 positioned read를 사용하며 PDFium이 온디맨드 접근을 계속하기 전에 소스 커서를 복원합니다

TPdfLoadOptions는 Mode, AuditByteLimit, MaxIssues, MaxXrefSections, MaxXrefEntries, MaxObjectNumber, ValidateObjectOffsets, RequireFinalEndOfFileMarker와 Default 클래스 함수를 담습니다

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