PDFium Delphi Component 文件

TPdfStreamInspector 类

单元: FPdfStreamInspect
对任意物理 PDF 流对象进行只读的有界清点与提取

语法

type TPdfStreamInspector = class ... end;

构造函数

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 字节数组

方法

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)、原生边界(取 psnaNone、psnaImageObject 或 psnaEmbeddedFile 的 NativeAccess)以及声明的 Filters 链
TPdfStreamInfosTPdfStreamInfo 记录的动态数组
TPdfStreamInspectOptions调用方选定的源、负载(MaxRawBytes、MaxDecodedBytes)、膨胀(MaxExpansionRatio)、对象数量(MaxStreams)、字典(MaxDictionaryBytes)、标记(MaxTokens)、分配(MaxAllocationBytes)以及 DeadlineMilliseconds 截止预算,附带静态 Default 初始化器
TPdfStreamReadReport单次读取的状态、输入与输出字节数(InputByteCount、OutputByteCount)、已应用与剩余的过滤器计数(AppliedFilterCount、RemainingFilterCount)、失败的过滤器索引(FailedFilterIndex)以及 ErrorMessage 文本

属性

MemberTypeDescription
CountInteger在源中找到的物理流对象或修订数量
Infos[Index]TPdfStreamInfo对象编号、代数、偏移、长度、过滤器、DecodeParms 以及原生访问分类
EncryptedBooleantrailer 是否声明了文档加密
OptionsTPdfStreamInspectOptions检查器使用的规范化资源预算
SourceByteCountInt64为检查而保留的输入字节数

解码级别与原生边界

预算与报告

TPdfStreamInspectOptions.Default 把自身的源、负载、膨胀、字典和流上限与当前 TPdfParserResourceBudget 的标记、对象、解码字节、膨胀比、分配和截止策略组合在一起

TPdfStreamReadReport 记录状态、输入与输出字节数、已应用与剩余的过滤器、失败的过滤器索引以及目标写入错误

当前实现会保留一份有界的源副本,以支持可靠的间接长度解析和可重复的随机流读取;在更紧张的内存预算下处理不受信任的上传时,请使用更低的 MaxSourceBytes

示例

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;