PDFium Delphi Component 文件

TPdfStreamInspector 類別

單元: FPdfStreamInspect
對任意實體 PDF 串流物件的唯讀有界清點與擷取

Syntax

type TPdfStreamInspector = class ... end;

Constructors

ConstructorDescription
Create(Source: TStream)在預設額度下讀取可搜尋的 PDF 來源,並還原其原始位置
Create(Source: TStream; const Options: TPdfStreamInspectOptions)在呼叫端選擇的額度下讀取可搜尋的 PDF 來源
Create(const Data: TBytes)在預設額度下檢查現有的 PDF 位元組陣列
Create(const Data: TBytes; const Options: TPdfStreamInspectOptions)在呼叫端選擇的額度下檢查現有的 PDF 位元組陣列

Methods

MethodDescription
CopyRawData(Index, Destination, out Report)複製一個串流物件的完整編碼承載
CopyRawData(Index, Destination, Offset, Count, out Report)在不解碼濾波器鏈的情況下複製經驗證的位元組視窗
DecodeData(Index, Destination, Level, out Report)傳回原始資料,或依宣告順序套用支援的一般濾波器
PdfStreamFilterKindFromName(Name)將完整或縮寫的 PDF 濾波器名稱映射到 TPdfStreamFilterKind

預設限制

ConstantValuePurpose
PdfStreamInspectDefaultSourceLimit512 MiB保留來源的大小上限
PdfStreamInspectDefaultRawLimit256 MiB單一操作複製的原始承載上限
PdfStreamInspectDefaultDecodedLimit256 MiB單一操作產生的解碼承載上限
PdfStreamInspectDefaultExpansionRatio100解碼對編碼的最大膨脹比
PdfStreamInspectDefaultMaxStreams1,000,000清點的串流物件數上限
PdfStreamInspectDefaultDictionaryLimit1 MiB單一串流檢查的字典位元組上限

公開類型

TypeDescription
TPdfStreamFilterKind將濾波器分類為 psfkUnknown、psfkASCIIHex、psfkASCII85、psfkLZW、psfkFlate、psfkRunLength、psfkCCITTFax、psfkJBIG2、psfkDCT、psfkJPX、psfkCrypt 或 psfkBrotli
TPdfStreamNativeAccess選擇無原生路徑、影像物件存取或內嵌檔案存取
TPdfStreamDecodeLevel選擇原始、支援的一般濾波器,或必要的完整鏈解碼
TPdfStreamReadStatus回報 psrsCompleted、psrsPartiallyDecoded、psrsInvalidIndex、psrsInvalidRange、psrsSourceLimitExceeded、psrsRawLimitExceeded、psrsDecodedLimitExceeded、psrsExpansionRatioExceeded、psrsUnsupportedFilter、psrsUnsupportedDecodeParameters、psrsEncrypted、psrsExternalData、psrsMalformed 或 psrsWriteError
TPdfStreamFilterInfo濾波器名稱、Kind、HasDecodeParameters 的 DecodeParms 存在與否、Predictor、Colors、BitsPerComponent、Columns,以及 LZW EarlyChange 值
TPdfStreamFilterInfosTPdfStreamFilterInfo 記錄的動態陣列
TPdfStreamInfo物件識別(ObjectNumber、Generation、TypeName)、位移與長度(ObjectOffset、DictionaryOffset、DictionaryLength、RawOffset、RawLength、DecodedLengthHint)、布局旗標(LengthIsIndirect、UsedEndStreamFallback)、加密與外部檔案旗標(HasExternalFile、IsEncryptedDocument)、類型名稱(SubtypeName)、原生邊界(NativeAccess 為 psnaNone、psnaImageObject 或 psnaEmbeddedFile),以及宣告的 Filters 鏈
TPdfStreamInfosTPdfStreamInfo 記錄的動態陣列
TPdfStreamInspectOptions呼叫端選擇的來源、承載(MaxRawBytes、MaxDecodedBytes)、膨脹(MaxExpansionRatio)、物件數(MaxStreams)、字典(MaxDictionaryBytes)、語彙單元(MaxTokens)、配置(MaxAllocationBytes)與 DeadlineMilliseconds 期限額度,並附靜態 Default 初始化器
TPdfStreamReadReport單次讀取的狀態、位元組計數(InputByteCount、OutputByteCount)、已套用與剩餘濾波器數(AppliedFilterCount、RemainingFilterCount)、失敗濾波器索引(FailedFilterIndex)與 ErrorMessage 文字

Properties

MemberTypeDescription
CountInteger在來源中找到的實體串流物件或修訂版數量
Infos[Index]TPdfStreamInfo物件編號、世代、位移、長度、濾波器、DecodeParms 與原生存取分類
EncryptedBooleantrailer 是否宣告文件加密
OptionsTPdfStreamInspectOptions檢查器使用的正規化資源額度
SourceByteCountInt64為檢查而保留的輸入位元組數

解碼層級與原生邊界

額度與報告

TPdfStreamInspectOptions.Default 將其來源、承載、膨脹、字典與串流上限,與目前的 TPdfParserResourceBudget 語彙單元、物件、解碼位元組、膨脹比、配置與期限政策結合

TPdfStreamReadReport 記錄狀態、輸入與輸出位元組計數、已套用與剩餘的濾波器、失敗的濾波器索引,以及目的地寫入錯誤

目前的實作會保留一份有界的來源副本,以支援可靠的間接長度解析與可重複的隨機串流讀取;在更緊的記憶體額度下處理不受信任的上傳時,請使用較低的 MaxSourceBytes

Example

var
  Inspector: TPdfStreamInspector;
  Output: TMemoryStream;
  Report: TPdfStreamReadReport;
begin
  Inspector := TPdfStreamInspector.Create(PdfBytes);
  Output := TMemoryStream.Create;
  try
    if Inspector.Count > 0 then
      Inspector.DecodeData(0, Output, psdlGeneral, Report);
  finally
    Output.Free;
    Inspector.Free;
  end;
end;