Apryse SDK's DOCX Compare utility compares two Microsoft Word documents and produces an output DOCX document in which every difference between them is recorded as a tracked change. DOCX Compare can be used to:
Because the output is a plain DOCX file, the differences can be viewed, accepted, or rejected in any DOCX editor.
The older version of the input Word document is called the original document, while the newer version is the revised document. The differences are always expressed relative to the original: content that exists only in the revised document is recorded as a tracked insertion, and content that exists only in the original document is recorded as a tracked deletion.
The comparison runs entirely within the Apryse SDK with no external or system dependencies. Results are deterministic and identical across Windows, Linux, macOS, and Android.
The comparison operates directly on the DOCX file format:
The DOCX Compare method takes the paths to the original and revised DOCX files and the path where the output DOCX will be written. It returns a result object describing the outcome of the comparison.
The options argument is optional in some languages. When omitted, the comparison uses default settings.
Alternatively, the function CompareWithFilter can be used if the documents are not on disk.
If either input document already contains tracked changes, the changes are automatically accepted before the comparison is performed, so the comparison reflects the final resolved text of each document. The resulting object reports whether each input contained pre-existing tracked changes.
Both Compare and CompareWithFilter return a DOCXCompareResult object with information about the comparison.
The comparison can be customized via a DOCXCompareOptions object, which controls how the resulting tracked changes are authored and how certain content is interpreted.
RevisedAuthor sets the author name recorded on the tracked changes in the output document. If it is not set, the author is taken from the last modified by value in the revised document's metadata. If that value is unavailable, the fixed author string "Comparison" is used.
The date stamped on the tracked changes can be controlled in two ways:
SetRevisedDate sets an explicit date, in ISO 8601 format (YYYY-MM-DDThh:mm:ss). SetDateMode selects how the date is determined automatically:e_revised_save_date (default) — Use the save date recorded in the revised document's metadata.e_current_date — Use the current date and time.e_empty_date — Leave the date empty.TreatStruckoutTextAsDeleted controls how text that carries strikeout formatting is handled.
false (the default), text whose only change is the addition of strikeout formatting is reported as a tracked formatting change. true, both input documents are pre-processed to remove struck-out text before comparison, so that such text is instead reported as a tracked deletion.For example, suppose the original document contains the text ABC, and the revised document contains the same ABC but struck out. With the option disabled, this appears as a formatting change; with the option enabled it appears as a deletion.
For comparison failures, like an invalid revised date or a malformed input document, an exception is thrown. Wrap comparison calls in the appropriate error-handling construct for your language and handle the failure accordingly.
View the DOCX Compare sample code in C#, Go, Java, C++, Javascript, Python, PHP, Ruby, VB, and Objective-C.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales