We're sorry GroupDocsCloud doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.cloud

Compare pdf using Node.js

There is an error:

let response = await compareApi.comparisons(request);
               ^^^^^

SyntaxError: await is only valid in async function

Code is here:

// initialize api

let compareApi = groupdocs_comparison_cloud.CompareApi.fromKeys(

“”,

“”);

// source file

let source = new groupdocs_comparison_cloud.FileInfo();

source.filePath = “./PDF1.pdf”;

// target file

let target = new groupdocs_comparison_cloud.FileInfo();

target.filePath = “./PDF2.pdf”;

// define compare options

let options = new groupdocs_comparison_cloud.ComparisonOptions();

options.sourceFile = source;

options.targetFiles = [target];

options.outputPath = “./result.pdf”;

// create comparison request

let request = new groupdocs_comparison_cloud.ComparisonsRequest(options);

// compare

let response = await compareApi.comparisons(request);

console.log("Output file link: " + response.href);

@ldlong

Please check the following sample code. Hopefully, it will help you to accomplish the task.

// load the module
var GroupDocs = require('groupdocs-comparison-cloud');

// get your Client ID and Secret at https://dashboard.groupdocs.cloud (free registration is required).
var ClientId = "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx";
var ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// construct ComparisonApi
var infoApi = GroupDocs.InfoApi.fromKeys(ClientId, ClientSecret);
var api = GroupDocs.CompareApi.fromKeys(ClientId, ClientSecret);

let source = new GroupDocs.FileInfo();
source.filePath = "source_files/source.pdf";
let target = new GroupDocs.FileInfo();
target.filePath = "target_files/target.pdf";
let options = new GroupDocs.ComparisonOptions();
options.sourceFile = source;
options.targetFiles = [target];
options.outputPath = "result.pdf";


let request = new GroupDocs.ComparisonsRequest(options);
api.comparisons(request)
                .then((result) => {    
    console.log(result);    			    
//fs.writeFileSync(localPath, result);
}).catch(function(err) {
    // Deal with an error
    console.log(err);
});