PDFium Delphi Component Docs

有資源上限的遮除幾何輔助功能

FPdfRedaction 提供 TPdf.SaveAsRedacted 使用的保守來源檢查與幾何操作;高階方法負責交易、註解處理、不透明疊圖、內容重新產生、清理與資源裁除

輔助功能修改呼叫端隔離交易副本中的原生物件,遇到不支援幾何或預算耗盡時拋出 EPdfRedactionGeometry;單靠它們無法完成安全匯出

公開宣告

type
  EPdfRedactionGeometry = class(Exception);
  TPdfRedactionGeometryOptions = record
    MaxFormDepth, MaxObjects, MaxPathSegments, MaxFragments: Integer;
    MaxImagePixels, MaxGeometryOperations: Int64;
    CurveTolerance: Double;
    class function Default: TPdfRedactionGeometryOptions; static;
  end;
  TPdfRedactionGeometryReport = record
    ExpandedFormCount, ScannedChildCount, ClippedPathCount: Integer;
    FlattenedCurveCount, GeneratedPointCount, FragmentCount: Integer;
    MaskedImageCount: Integer;
    ScannedPixelCount, MaskedPixelCount, PixelIntersectionTestCount: Int64;
    GeometryOperationCount: Int64;
  end;

procedure ValidateDetailedRedactionSource(Source: TStream);
procedure ValidateDetailedRedactionText(PageObject: FPDF_PAGEOBJECT);
procedure ExpandRedactionForms(Page: FPDF_PAGE;
  const Options: TPdfRedactionGeometryOptions;
  var Report: TPdfRedactionGeometryReport);
procedure ClipRedactionPath(Page: FPDF_PAGE; PageObject: FPDF_PAGEOBJECT;
  ObjectIndex: Integer; const Redactions: array of FS_RECTF;
  const Options: TPdfRedactionGeometryOptions;
  var Report: TPdfRedactionGeometryReport);
procedure MaskRedactionImage(Document: FPDF_DOCUMENT; Page: FPDF_PAGE;
  PageObject: FPDF_PAGEOBJECT; ObjectIndex: Integer;
  const Redactions: array of FS_RECTF;
  const Options: TPdfRedactionGeometryOptions;
  var Report: TPdfRedactionGeometryReport);

座標與支援的幾何

所有遮除矩形與曲線容差使用 PDF 使用者空間的點;路徑點先轉換至頁面空間再裁切,ObjectIndex 是原始從零起算的原生頁面物件索引,用來保留繪製順序

展開及部分幾何會拒絕透明或混合狀態、不支援的子類型、奇異矩陣、圖樣填色,以及複雜或非冗餘裁切路徑;受支援的冗餘矩形裁切必須涵蓋完整物件邊界

選項與累計報告

選項預設意義
MaxFormDepth32巢狀 Form 展開深度
MaxObjects1000000頁面列舉及累計展開子物件上限
MaxPathSegments262144每條路徑輸入線段與累計產生路徑點
MaxFragments1000000保留矩形區域與累計取代片段
MaxImagePixels16777216累計處理的解碼影像像素
MaxGeometryOperations67108864累計幾何與像素交集工作
CurveTolerance0.01以 PDF 點表示的三次曲線展平容差

請以 TPdfRedactionGeometryOptions.Default 初始化選項,在交易開始前將報告歸零一次;輔助功能呼叫間使用同一份報告,讓產生點、影像像素、片段與操作預算累計

ExpandedFormCount 與 ScannedChildCount 描述展開工作,走訪數包含根 Form 執行個體與子物件;ClippedPathCount、FlattenedCurveCount 及 GeneratedPointCount 描述路徑工作,包含中間裁切點;MaskedImageCount、ScannedPixelCount、MaskedPixelCount 及 PixelIntersectionTestCount 描述影像工作

FragmentCount 計算取代物件,並非多邊形輪廓或像素;GeometryOperationCount 累計有上限的輔助處理工作。例外留下的報告可能描述已捨棄交易副本中的部分工作

來源檢查與匯出邊界

ValidateDetailedRedactionSource 在修改前檢查使用中的物件與解碼內容;TPdf.SaveAsRedacted 在所有處理模式都會呼叫,包括整個物件移除與較簡單的部分保留模式

目前模式不重建 Tagged PDF 結構、不保留任意透明效果、不支援任意筆畫或裁切,也不保證無損保留編碼影像;安全輸出需要在重新產生內容後移除原始串流與未使用資源,TPdf.SaveAsRedacted 會完成這些處理

直接呼叫端必須提供隔離文件副本、驗證原生功能及有限的正值預算、失敗時捨棄副本、重新產生修改過的頁面內容,並在匯出之前完成清理與資源裁除

另請參閱

TPdf.SaveAsRedacted, TPdf.SaveAsSanitised, FPdfCompress