PDFium Delphi Component Docs

頁面物件快照

元件: TPdf  ·  單元: PDFium
為分析、預檢與匯出消費端一次性擷取由呼叫端擁有的頁面物件資訊,而不保留原生控制代碼

類型

TPdfPageObjectSnapshotOptions = record ... end;

TPdfPageObjectSnapshotStatus = record ... end;

TPdfContentMarkSnapshot = record ... end;

TPdfPageObjectSnapshot = record ... end;

TPdfPageObjectsSnapshot = record ... end;

TPdfPageObjectSnapshot 擁有每個字串與動態陣列,且不含 FPDF_PAGEOBJECT、FPDF_PAGEOBJECTMARK、頁面、字型、點陣圖或文字頁控制代碼

共同資訊包括型別、原始與 RotatedBounds 邊界、矩陣、作用狀態、透明度、填色與線條色彩、alpha、線條寬度、線條接合與 HasLineJoin、線條端點與 HasLineCap、存放在 DashArray 並帶 DashPhase 偏移的虛線樣式,以及標記內容 ID

型別專屬資訊包括透過 PathSegmentCount、ClipPathCount 與 ClipPathSegmentCount 取得、並受 HasPathInfo 與 HasClipPath 閘門控制的路徑與裁剪計數、選用的路徑幾何與 ClipPath 線段陣列、透過 HasImageInfo 取得的輕量影像中繼資料與濾鏡、選用的標記字典、透過 HasText 取得的文字、透過 HasFontInfo 取得的字型名稱與旗標、字重、含 HasFontSize 的 FontSize,以及含 HasRenderMode 的 RenderMode

每個選用的原生資訊都有對應的 Has... 旗標,讓無法取得的值與零或空資料保持區別

有界讀取

function ReadPageObjectsSnapshot(PageNumber: Integer; const Options: TPdfPageObjectSnapshotOptions; out Status: TPdfPageObjectSnapshotStatus): TPdfPageObjectsSnapshot;

ReadPageObjectsSnapshot 會在算繪鎖之下走訪原生頁面物件清單,不查詢也不填入快照快取

PageNumber 以 1 為基底,讀取其他頁面時會保留作用中的 TPdf.PageNumber

TPdfPageObjectSnapshotOptions.Default 會擷取共同資訊、路徑與裁剪計數、影像中繼資料與字型中繼資料,同時停用 IncludePathSegments、IncludeClipPaths、IncludeContentMarks 與 IncludeText 承載

TPdfPageObjectSnapshotOptions.Full 會在相同的明確額度下啟用路徑線段、裁剪路徑、內容標記與物件文字

額度涵蓋透過 MaxObjects 控制的物件數、MaxPathSegments、MaxClipPathSegments、MaxMarkParams、MaxTextCharacters、MaxStringBytes,以及透過 DeadlineMilliseconds 控制的經過時間;IncludeImageMetadata 則作為輕量影像資訊的啟用條件

狀態會回報 NativeObjectCount、ObjectsVisited、PathSegmentsVisited、ClipPathSegmentsVisited、MarksVisited、MarkParamsVisited、TextCharacters 與 StringBytes,並在額度截斷結果時設定 ObjectLimitReached、PathSegmentLimitReached、ClipPathSegmentLimitReached、MarkParamLimitReached、TextCharacterLimitReached、StringLimitReached 或 DeadlineReached;MetadataFailureCount 則回報無法取得的原生資訊,而不中止其餘走訪

可感知修訂的快取

property PageObjectsSnapshot[PageNumber: Integer]: TPdfPageObjectsSnapshot;

property PageObjectSnapshotCacheCapacity: Integer; // default 8

property PageObjectSnapshotCacheCount: Integer;

property PageObjectSnapshotCacheHitCount: Int64;

property PageObjectSnapshotCacheMissCount: Int64;

PageObjectsSnapshot 索引屬性套用預設選項,且只把完整的快照保留在有界的最近最少使用快取中

每個傳回值都是呼叫端擁有的深層複本,因此修改巢狀的虛線陣列、標記參數、路徑線段、裁剪路徑、濾鏡或字串,都無法改動快取資料或文件

頁面編輯會使對應項目失效,而文件替換與頁面樹變更會清空整個快取

PageObjectSnapshotCacheCapacity 預設為 8,拒絕負值;當新項目會超出容量時,撤出最近最少使用的快照

PageObjectSnapshotCacheCount 回報目前保留的頁面快照數量

PageObjectSnapshotCacheHitCount 與 PageObjectSnapshotCacheMissCount 會在元件生命週期內累計,讓呼叫端能衡量容量設定是否符合自身的存取模式

容量為 0 會停用保留,但不會停用直接的有界讀取

PageComplexity 對物件型別、路徑數、影像像素與透明度重用此快取

範例

var
  Snapshot: TPdfPageObjectsSnapshot;
  Obj: TPdfPageObjectSnapshot;
begin
  Pdf.PageObjectSnapshotCacheCapacity := 16;
  Snapshot := Pdf.PageObjectsSnapshot[1];
  if not Snapshot.Status.Completed then
    raise Exception.Create('Page object snapshot is incomplete');

  for Obj in Snapshot.Objects do
    if Obj.ObjectType = otImage then
      IndexImage(Obj.Bounds, Obj.ImageInfo);
end;

另請參閱

PageObjectInfo, PathInfo, PageObjectClipPath, 文字頁快照