CompareDocumentTextsWith
Page manipulation
Requires the Small Business edition — in Delphi, C++Builder and Lazarus code create the library as TPDFlibSmallBusiness (unit PDFlibSmallBusiness) or TPDFlibEnterprise; the Small Business and Enterprise DLL and ActiveX builds provide it unchanged; the Single edition keeps the method, which returns an empty string and sets LastErrorCode to 901 (PDFLIB_ERROR_SMALLBUSINESS_REQUIRED)
Description
Compares the extracted text of two whole documents word by word or line by line and lists the runs that differ
Syntax
Delphi
Function CompareDocumentTextsWith(Other: TPDFlib; Granularity: Integer): WideString; Virtual;ActiveX
Function PDFlib::CompareDocumentTextsWith(Other As Object, Granularity As Long) As StringDLL
const wchar_t* DLCompareDocumentTextsWith(int InstanceID, int OtherInstanceID, int Granularity);
const char* DLCompareDocumentTextsWithA(int InstanceID, int OtherInstanceID, int Granularity);Parameters
| Other | The second document, loaded in its own library instance. The DLL and the Dylib take the instance handle DLCreateLibrary returned for it as OtherInstanceID; Automation takes the other control object |
|---|---|
| Granularity | 0 compares words, 1 compares lines |
Return values
A JSON report. changes lists each run of differing words or lines with type (changed, this-only or other-only), the page each side starts on (0 for the side that has no text), and the text of both sides; changeCount counts all runs. A report with "status":"error" means a document is missing or the granularity is invalid
Remarks
The text of all pages is compared as one sequence, so text that moves to the next page is not reported as changed. Adjacent differing words or lines are reported as one run
When the documents differ too much to align, everything between the shared beginning and end is reported as a single run and complete is false; it is also false when more than 10000 runs differ and only the first 10000 are listed
Example
Report:= NewDoc.CompareDocumentTextsWith(OldDoc, 0);See also
ComparePageTextsWith, GetPageText, CompareDocumentVisualsWith