type TPdfStreamInspector = class ... end;
| Constructor | Description |
|---|---|
Create(Source: TStream) | 在默认预算下读取可寻址的 PDF 源,并恢复其原始位置 |
Create(Source: TStream; const Options: TPdfStreamInspectOptions) | 在调用方选定的预算下读取可寻址的 PDF 源 |
Create(const Data: TBytes) | 在默认预算下检查现有的 PDF 字节数组 |
Create(const Data: TBytes; const Options: TPdfStreamInspectOptions) | 在调用方选定的预算下检查现有的 PDF 字节数组 |
| Method | Description |
|---|---|
CopyRawData(Index, Destination, out Report) | 复制一个流对象的完整编码负载 |
CopyRawData(Index, Destination, Offset, Count, out Report) | 在不解码过滤器链的情况下复制经过校验的字节窗口 |
DecodeData(Index, Destination, Level, out Report) | 返回原始数据,或按声明顺序应用受支持的通用过滤器 |
PdfStreamFilterKindFromName(Name) | 把完整或缩写的 PDF 过滤器名称映射为 TPdfStreamFilterKind |
| Constant | Value | Purpose |
|---|---|---|
PdfStreamInspectDefaultSourceLimit | 512 MiB | 保留源大小的上限 |
PdfStreamInspectDefaultRawLimit | 256 MiB | 单次操作复制的原始负载上限 |
PdfStreamInspectDefaultDecodedLimit | 256 MiB | 单次操作产生的解码负载上限 |
PdfStreamInspectDefaultExpansionRatio | 100 | 解码数据相对编码数据的最大膨胀比 |
PdfStreamInspectDefaultMaxStreams | 1,000,000 | 清点的流对象数量上限 |
PdfStreamInspectDefaultDictionaryLimit | 1 MiB | 单个流检查的字典字节上限 |
| Type | Description |
|---|---|
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 值 |
TPdfStreamFilterInfos | TPdfStreamFilterInfo 记录的动态数组 |
TPdfStreamInfo | 对象标识(ObjectNumber、Generation、TypeName)、偏移与长度(ObjectOffset、DictionaryOffset、DictionaryLength、RawOffset、RawLength、DecodedLengthHint)、布局标志(LengthIsIndirect、UsedEndStreamFallback)、加密与外部文件标志(HasExternalFile、IsEncryptedDocument)、类型名称(SubtypeName)、原生边界(取 psnaNone、psnaImageObject 或 psnaEmbeddedFile 的 NativeAccess)以及声明的 Filters 链 |
TPdfStreamInfos | TPdfStreamInfo 记录的动态数组 |
TPdfStreamInspectOptions | 调用方选定的源、负载(MaxRawBytes、MaxDecodedBytes)、膨胀(MaxExpansionRatio)、对象数量(MaxStreams)、字典(MaxDictionaryBytes)、标记(MaxTokens)、分配(MaxAllocationBytes)以及 DeadlineMilliseconds 截止预算,附带静态 Default 初始化器 |
TPdfStreamReadReport | 单次读取的状态、输入与输出字节数(InputByteCount、OutputByteCount)、已应用与剩余的过滤器计数(AppliedFilterCount、RemainingFilterCount)、失败的过滤器索引(FailedFilterIndex)以及 ErrorMessage 文本 |
| Member | Type | Description |
|---|---|---|
Count | Integer | 在源中找到的物理流对象或修订数量 |
Infos[Index] | TPdfStreamInfo | 对象编号、代数、偏移、长度、过滤器、DecodeParms 以及原生访问分类 |
Encrypted | Boolean | trailer 是否声明了文档加密 |
Options | TPdfStreamInspectOptions | 检查器使用的规范化资源预算 |
SourceByteCount | Int64 | 为检查而保留的输入字节数 |
psdlRaw 复制编码的流字节,不应用任何过滤器psdlGeneral 应用 ASCIIHex、ASCII85、LZW、Flate、RunLength、TIFF 8 位和 PNG 预测器,当仍剩余图像或未知编解码器时返回 psrsPartiallyDecodedpsdlFull 要求完整链条都使用受支持的通用过滤器,否则返回 psrsUnsupportedFilterpsnaImageObject 把文档级调用方导向原生 FPDFImageObj_GetImageDataRaw、FPDFImageObj_GetImageDataDecoded 和图像过滤器 APIpsnaEmbeddedFile 把附件调用方导向原生 FPDFAttachment_GetFile 路径psrsEncrypted,因为公开的原生 ABI 无法按对象编号解密任意间接流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;