CompareDocumentTextsWith

页面操作

需要 Small Business 版。在 Delphi、C++Builder 与 Lazarus 代码中,请以 TPDFlibSmallBusiness(单元 PDFlibSmallBusiness)或 TPDFlibEnterprise 创建库;Small Business 与 Enterprise 的 DLL 及 ActiveX 构建原样提供该方法。Single 版保留该方法,其返回 0、空字符串或 False,并将 LastErrorCode 设为 901(PDFLIB_ERROR_SMALLBUSINESS_REQUIRED)

描述

逐词或逐行比较两个完整文档提取出的文本,并列出存在差异的片段

语法

Delphi

Function CompareDocumentTextsWith(Other: TPDFlib; Granularity: Integer): WideString; Virtual;

ActiveX

Function PDFlib::CompareDocumentTextsWith(Other As Object, Granularity As Long) As String

DLL

const wchar_t* DLCompareDocumentTextsWith(int InstanceID, int OtherInstanceID, int Granularity);
const char* DLCompareDocumentTextsWithA(int InstanceID, int OtherInstanceID, int Granularity);

参数

Other第二个文档,加载在其自身的库实例中;DLL 与 Dylib 以 DLCreateLibrary 为其返回的实例句柄作为 OtherInstanceID,Automation 则传入另一个控件对象
Granularity0 比较词语,1 比较行

返回值

JSON 报告。changes 列出每段有差异的词语或行,包括 type(changed、this-only 或 other-only)、双方各自的起始页(无文本的一方为 0)以及两侧的文本;changeCount 统计全部片段。报告中出现 "status":"error" 表示缺少文档或粒度无效

备注

所有页面的文本作为单一序列比较,因此移动到下一页的文本不会被报告为变更。相邻的有差异词语或行会作为同一段报告

当两份文档差异过大无法对齐时,共同开头与结尾之间的所有内容会作为单一段报告,且 complete 为 false;差异片段超过 10000 个而仅列出前 10000 个时,它同样为 false

示例

Report:= NewDoc.CompareDocumentTextsWith(OldDoc, 0);

另请参阅

ComparePageTextsWith, GetPageText, CompareDocumentVisualsWith