how to compare two DOCX documents and save the result as PDF?
To compare two DOCX files and write the comparison result as a PDF you can use the static Comparer.Compare method and pass SaveFormat.Pdf as the output format.
Steps
- Make sure the Wordize Comparison for .NET module (and the required Wordize Core for .NET module) is referenced in your project.
- Call the overload that accepts the output format, author initials and a revision date:
public static void Compare(string v1, string v2, string outputFileName, SaveFormat saveFormat,
string author, DateTime dateTime, CompareOptions compareOptions)
- Supply the paths of the two DOCX files, an output file name ending with .pdf,
SaveFormat.Pdf, the author initials and aDateTimevalue (you can also pass aCompareOptionsinstance if you need custom granularity).
Example (adapted from the API reference)
The reference shows a comparison that writes a DOCX file:
CompareOptions compareOptions = new CompareOptions() { Granularity = Granularity.CharLevel };
Comparer.Compare(MyDir + "CompareV1.docx", MyDir + "CompareV2.docx",
ArtifactsDir + "Compare.Granularity.docx", SaveFormat.Docx,
"Wordize", DateTime.Now, compareOptions);
Replace SaveFormat.Docx with SaveFormat.Pdf and change the output file name accordingly (e.g., ArtifactsDir + "Compare.pdf"). The method signature and overload are documented here: Comparer.Comparesource.
Reference
Comparer.Compare– static method that accepts aSaveFormatargument and produces a document with revisions.- How to Compare Documents – overview of the comparison feature and required modules.
Using the SaveFormat.Pdf option will generate a PDF that contains the tracked changes between the two DOCX inputs.