自 3.267.0 起,返回的 TPdfReflowDocument 还提供 WriteHtml(Writer: TPdfReportWriter; MaxDepth: Integer = 64),可直接按输出/条目限制、文档 node/文本限制和可配置的深度上界序列化
旧有的 ToHtml 字符串方法保留既有行为;当中间 HTML 构造也必须遵守所选限制时,请使用有界报告写入
function BuildReflowDocument(
const Options: TPdfReflowOptions;
const CancellationToken: IPdfCancellationToken = nil): TPdfReflowDocument;
BuildReflowDocument 通过 GetStructuredText 读取每个选中的页面,优先采用 Tagged PDF 语义,并在缺少结构时回退到物理版式推断
返回的 TPdfReflowDocument.Nodes 数组是一棵带 ParentIndex 和 Depth 的稳定前序树,避免了递归式所有权,同时保留页面、标题、段落、列表、插图、题注、表格、行和单元格的关系
每个 TPdfReflowNode 携带其页面、文本、语言、语义来源、边界、标题级别、带跨度的表格坐标 RowIndex 和 ColumnIndex、IsHeader 状态,以及适用时的置信度
TPdfReflowOptions 选择页面窗口和输出闸门;DetectTables 启用表格检测并使用嵌套的 TableOptions 预算记录,生成的 TPdfReflowDocument 会在节点树之外同时公开检测到的 TableCount
检测到的表格文本会替换重叠的段落块,因此重排结果不会重复表格内容
TPdfReflowDocument.ToHtml 输出语义化的 h1 到 h6、p、ul、li、figure、figcaption、table、th 和 td 元素
文本和属性值始终会被转义,行跨度和列跨度会被保留,可选的响应式 CSS 不需要脚本或外部资源
FullDocument、IncludeCss、IncludePageSections、IncludeGeometry 和 PreserveLineBreaks 控制序列化,而无需重新解析 PDF
FirstPage 和 LastPage 从 1 开始计数,0 表示文档边界MaxCharacters、MaxNodes 和嵌套的表格预算在产生无界输出之前以失败关闭方式生效var
Options: TPdfReflowOptions;
Document: TPdfReflowDocument;
begin
Options := TPdfReflowOptions.Default;
Options.IncludeGeometry := True;
Document := Pdf1.BuildReflowDocument(Options);
Memo1.Text := Document.ToHtml;
end;