PDFium Delphi Component Docs

ที่เก็บ random access แบบจำกัดขอบเขต

Component: TPdf  ·  Unit: PDFium
คุมข้อมูลทำงานที่ seek ได้ให้อยู่ใต้เพดานหน่วยความจำที่ผู้เรียกเลือก และปล่อยเนื้อหาที่ใหญ่กว่าลงที่เก็บชั่วคราวส่วนตัว

Syntax

const PdfDefaultStorageMemoryLimit = 64 * 1024 * 1024;

type TPdfStorageBackend = (psbMemory, psbTemporaryFile);

constructor TPdfRandomAccessStore.Create(AMemoryLimit: Int64 = PdfDefaultStorageMemoryLimit; const ATemporaryDirectory: string = '');

destructor Destroy; override;

function Read(var Buffer; Count: Longint): Longint; override;

function Seek(Offset: Int64; Origin: TSeekOrigin): Int64; override;

function Write(const Buffer; Count: Longint): Longint; override;

function ReadAt(Offset: Int64; var Buffer; Count: Longint): Longint;

function WriteAt(Offset: Int64; const Buffer; Count: Longint): Longint;

procedure CopyToStream(Destination: TStream; BufferSize: Integer = 1048576);

procedure Flush;

procedure SpillToDisk;

property Backend: TPdfStorageBackend;

property MemoryBytes: Int64;

property MemoryLimit: Int64;

property PeakMemoryBytes: Int64;

property Spilled: Boolean;

property TemporaryDirectory: string;

property TemporaryFileName: string;

TPdf save settings

property SaveMemoryLimit: Int64;

property SaveTemporaryDirectory: string;

property LastSaveSpillCount: Integer;

property LastSaveLargestMemoryBuffer: Int64;

SaveMemoryLimitความจุหน่วยความจำสำรองสูงสุดของที่เก็บบันทึกภายในแต่ละตัวก่อน spill ลงดิสก์; ค่า default คือ 64 MiB
SaveTemporaryDirectoryไดเรกทอรีที่มีอยู่แล้วซึ่งใช้เก็บไฟล์ spill; ค่าว่างหมายถึงใช้ไดเรกทอรีชั่วคราวของโปรเซส
LastSaveSpillCountจำนวนที่เก็บทำงานภายในที่ spill ระหว่าง pipeline การบันทึกครั้งล่าสุด
LastSaveLargestMemoryBufferความจุหน่วยความจำสำรองเดี่ยวที่ใหญ่ที่สุดที่พบระหว่าง pipeline การบันทึกครั้งล่าสุด

Description

TPdfRandomAccessStore สืบทอดจาก TStream รองรับการอ่าน เขียน seek และกำหนดขนาดแบบลำดับปกติ นอกเหนือจาก I/O แบบระบุตำแหน่งที่ไม่ขึ้นกับ cursor

ข้อมูลยังอยู่ใน buffer หน่วยความจำที่ขยายขนาดได้ ตราบใดที่จุดสิ้นสุดเชิงตรรกะไม่เกิน MemoryLimit

การทำงานแรกที่ข้ามเพดานจะสร้างไฟล์ชั่วคราวแบบ exclusive คัดลอกไบต์เดิมครั้งเดียว ล้าง buffer หน่วยความจำ แล้วใช้ backend แบบไฟล์ต่อไปตลอดอายุของ store

แฮนเดิลชั่วคราวใช้แฟล็ก delete-on-close และ random access ไม่อนุญาตให้ใช้ร่วมกัน และถูกลบเมื่อถูกทำลายตามปกติหรือเมื่อ constructor rollback

การทำงานแต่ละครั้งถูกทำให้เป็นอนุกรมด้วย critical section ภายใน; ควรใช้ ReadAt และ WriteAt เมื่อผู้เรียกพร้อมกันหลายตัวต้องไม่แย่ง cursor แบบลำดับกัน

ส่ง store เข้า LoadCustomDocument ได้โดยตรง; block callback ของ PDFium ใช้การอ่านแบบระบุตำแหน่งและไม่ขยับ cursor ของ store

TPdf ใช้นโยบายที่ตั้งไว้กับการบันทึกหลัก, workspace post-processing ของ PDF ที่บันทึกทุกครั้ง และการจัดเตรียมระหว่างกลางของการแปลงมาตรฐาน การตรวจสอบ การเข้ารหัส DSS และ PAdES

การซ่อม xref-stream แบบ incremental ระดับ native อ่านหน้าต่าง tail และพจนานุกรมขนาดคงที่ แล้วนำการแก้ไขที่ผ่านการตรวจแล้วไปใช้ขณะคัดลอกช่วงที่ไม่เปลี่ยนแปลงเป็น chunk แบบจำกัดขนาด

Memory accounting

Constraints

Example

var
  Store: TPdfRandomAccessStore;
begin
  Pdf.SaveMemoryLimit := 16 * 1024 * 1024;
  Pdf.SaveTemporaryDirectory := TPath.GetTempPath;
  Pdf.SaveAs('output.pdf');
  Log(Pdf.LastSaveSpillCount, Pdf.LastSaveLargestMemoryBuffer);

  Store := TPdfRandomAccessStore.Create(4 * 1024 * 1024);
  try
    Store.CopyFrom(SourceStream, SourceStream.Size);
    Store.Position := 0;
    Pdf.LoadCustomDocument(Store, False);
  finally
    Pdf.Active := False;
    Store.Free;
  end;
end;

See Also

LoadCustomDocument, SaveAs