Please check the following sample code to compare two PDF files for differences in Node.js using GroupDocs.Comparison Cloud SDK for Node.js. Hopefully, it will help you to accomplish the task.
How to Compare 2 PDF Documents for Differences in Nodes.js
Install GroupDocs.Comparison Cloud SDK for Node.js from NPM
Create a script file and import groupdocs-comparison-cloud module
Construct Comparison REST API instance
Set ComparisonOptions object for the source and target PDF files
Compare the PDF files using comparisons API Method
Compare Two PDF Documents for Changes Online Node.js
// load the module
var GroupDocs = require('groupdocs-comparison-cloud');
// get your Client ID and Client Secret at https://dashboard.groupdocs.cloud (free registration is required).
var clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx";
var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const comparePDFFiles = async () => {
// construct ComparisonApi
var infoApi = GroupDocs.InfoApi.fromKeys(clientId, clientSecret);
var compareApi = GroupDocs.CompareApi.fromKeys(appSid, appKey);
// set the comparison options
let source = new GroupDocs.FileInfo();
source.filePath = "source_files/source.docx";
let target = new GroupDocs.FileInfo();
target.filePath = "target_files/target.docx";
let options = new GroupDocs.ComparisonOptions();
options.sourceFile = source;
options.targetFiles = [target];
options.outputPath = "result.docx";
// compare 2 PDF documents for changes
try {
let request = new GroupDocs.ComparisonsRequest(options);
let comparePDFFilesResposne = await compareApi.comparisons(request);
} catch (err) {
throw err;
}
}
comparePDFFiles()
.then(() => {
console.log("PDF documents compared successfully");
})
.catch((err) => {
console.log("Error occurred while converting the PDF document:", err);
})