CompareFileVisualsEx

Document comparison, Rendering

Requires the Small Business edition or Enterprise edition

Description

Compares the selected document with a PDF file. Pass JSON options to ignore pixel regions or compare a specific pair of pages and return its mask and overlay

Syntax

Delphi

Function TPDFlib.CompareFileVisualsEx(Const OtherFileName, Password, OptionsJSON: WideString): WideString; Virtual;

DLL

const wchar_t* DLCompareFileVisualsEx(int InstanceID, const wchar_t* OtherFileName,
  const wchar_t* Password, const wchar_t* OptionsJSON);
const char* DLCompareFileVisualsExA(int InstanceID, const char* OtherFileName,
  const char* Password, const char* OptionsJSON);

ActiveX

Function PDFlib::CompareFileVisualsEx(OtherFileName As String, Password As String, OptionsJSON As String) As String

Options

OtherFileName names the PDF file that the selected document is compared with. OptionsJSON is a JSON object; use an empty string or {} for the defaults. Password opens the comparison file and can be empty for an unencrypted PDF

Invalid JSON, an unknown key, a value outside its supported range or an option text longer than 256 Ki UTF-16 code units returns {"status":"error","complete":false,"error":"..."} and sets LastErrorCode to 401

dpiInteger from 36 to 600, default 96
colorTolerancePer-channel difference allowance from 0 to 255, default 0
tileSizeDifference grouping tile size from 4 to 128 pixels, default 32
ignoreRectsUp to 256 objects with integer left, top, right and bottom coordinates. Coordinates start at the rendered page's top left. The right and bottom boundaries are exclusive
firstPage, secondPageOne-based page numbers from the selected PDF and comparison file. Supply both for a single pair or omit both for document alignment
includeMask, includeOverlayOptional booleans, both false by default. Available for an explicit pair with at most 1,048,576 pixels per page
{"dpi":96,"firstPage":2,"secondPage":3,"includeMask":true,
 "ignoreRects":[{"left":8,"top":8,"right":320,"bottom":48}]}

Return values

Returns JSON with complete and either aligned document pairs or a single pair's comparison metrics. Unsupported options and render failures return an error report

maskHex contains one byte per pixel, FF for changed pixels and 00 elsewhere. overlay.dataHex contains top-down RGB24 rows with the returned overlay.stride in bytes. Changed pixels are tinted red on the second page's image

Remarks

ActiveX exposes the method on IPDFlibrary20 with dispatch ID 73011697 and retains the earlier interfaces. The macOS Dylib uses the same export names, with UTF-16 code units for the wide export. Copy the returned C ABI string before the next call on the instance

Align reordered or similar pages

Document comparisons use ordered exact-match alignment by default. Set "alignment":"visual" to pair identical pages across different positions and consider visually similar pages when both sides have a clear best match. Unpaired pages appear as separate additions or removals

{"alignment":"visual","pageAnchors":[{"firstPage":2,"secondPage":5}]}

Anchors reserve one-based page pairs before automatic matching. firstPage is a page of the selected document and secondPage is a page of the other file. Use each page at most once. Supplying anchors also selects visual alignment when the alignment option is omitted

Visual alignment supports up to 256 pages per document. Its pairs report pairing as anchor, exact, similar or unpaired. For a similar pair, signatureDistance is the sampled raster distance in parts per thousand. Pixel comparison and changed-region detection still use the selected full raster resolution

See also

CompareFileVisuals, CompareRenderedPagesWith, SaveVisualComparisonPDF