procedure LoadCustomDocument(AStream: TStream; AOwnsStream: Boolean = False);
procedure LoadCustomDocument(AStream: TStream; AOwnsStream: Boolean; const Options: TPdfLoadOptions; out Report: TPdfLoadReport);
LoadCustomDocument คือคู่แบบ streaming ของ overload แบบ buffered
ของ LoadDocument โดยทำงานบนจุดเชื่อมต่อ
FPDF_LoadCustomDocument ของ PDFium ผ่านคลาสช่วย
TPdfStreamAdapter ที่เพิ่มเข้ามาตั้งแต่ v1.8.0
PDFium จะดึงบล็อกจาก AStream เมื่อจำเป็นเท่านั้น stream จึง
ไม่ถูก คัดลอกลงหน่วยความจำ: TFileStream ที่ชี้ไปยัง PDF ขนาด 4 GB,
TStream บน HTTP หรือ BLOB stream จาก database ล้วนใช้งานได้
โดยไม่ต้องลำเลียง payload ทั้งหมดเข้า RAM ก่อน
AStream ต้องรองรับการ seek และต้องมีอายุการใช้งานยาว
จนกว่าเอกสารจะถูกปิด (เรียก UnloadDocument หรือตั้ง
Active กลับเป็น False) ส่ง
AOwnsStream = True เพื่อโอนความเป็นเจ้าของ stream ให้
TPdf ตัวนี้ — adapter จะ free AStream เองเมื่อ
UnloadDocument ทำงาน ส่วนถ้าผู้เรียกต้องการใช้ stream ต่อหลังปิดเอกสาร ให้ส่ง
False
LoadCustomDocument ถูกแยกออกมาเป็นเมธอดของตัวเองโดยตั้งใจ (ไม่ใช่
overload ตัวหนึ่งของ LoadDocument) เพื่อไม่ให้ผู้เรียกที่ส่ง subclass ของ
TMemoryStream ไปผูกกับ overload แบบ buffered
LoadDocument(TMemoryStream, Boolean) โดยไม่ตั้งใจ — รูปทรงอาร์กิวเมนต์แบบ Pascal เหมือนกันแต่ความหมายต่างกันมาก
(buffered เทียบกับ on-demand)
overload แบบมี policy ใช้พฤติกรรมแบบ compatible, strict หรือ recovery เช่นเดียวกับการตรวจสอบ xref แบบจำกัดขอบเขตที่ LoadDocument อธิบายไว้ การตรวจสอบใช้การอ่านแบบระบุตำแหน่งและคืน cursor ของแหล่งข้อมูลก่อนที่ PDFium จะเข้าถึงแบบ on-demand ต่อไป
TPdfLoadOptions เก็บ Mode, AuditByteLimit, MaxIssues, MaxXrefSections, MaxXrefEntries, MaxObjectNumber, ValidateObjectOffsets และ RequireFinalEndOfFileMarker พร้อม class function แบบ Default
Password ก่อนเรียก LoadCustomDocument เมื่อเปิดเอกสารที่เข้ารหัสAStream — จะเป็น TFileStream, TMemoryStream หรือ subclass ของ TStream ใดก็ได้ที่ทำ Seek และ Read ตามสัญญาAOwnsStream = True
// 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;