Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sign Documents with Digital Signatures using REST API in Node.js
Sign Documents with Digital Signatures using REST API in Node.js
1. Sign Word Documents using a REST API in Node.js
2. Sign PDF Documents using a REST API in Node.js
3. Verify Digital Signatures using a REST API in Node.js
4. Upload Word File
5. Download Signed File
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972";
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618";
global.myStorage = "";
const config = new groupdocs_signature_cloud.Configuration(clientId, clientSecret);
config.apiBaseUrl = "https://api.groupdocs.cloud";
// construct FileApi
var fileApi = groupdocs_signature_cloud.FileApi.fromConfig(config);
// create download file request
let request = new groupdocs_signature_cloud.DownloadFileRequest("signedDigital_sample.docx", myStorage);
let response = await fileApi.downloadFile(request);
// save file to the working directory
fs.writeFile("C:\\Files\\signedDigital_sample.docx", response, "binary", function (err) { });
// initialize api
let signApi = groupdocs_signature_cloud.SignApi.fromKeys(clientId, clientSecret);
// create file info
let fileInfo = new groupdocs_signature_cloud.FileInfo();
fileInfo.filePath = "sample.docx";
// define sign digital options
let opts = new groupdocs_signature_cloud.SignDigitalOptions();
opts.signatureType = groupdocs_signature_cloud.OptionsBase.SignatureTypeEnum.Digital;
opts.imageFilePath = "signature.jpg";
opts.certificateFilePath = "certificate.pfx";
opts.password = "1234567890";
// set signature position on a page
opts.left = 350;
opts.top = 450;
opts.width = 200;
opts.height = 100;
opts.location_measure_type = "Pixels";
opts.size_measure_type = "Pixels";
opts.rotation_angle = 0;
opts.horizontal_alignment = "None";
opts.vertical_alignment = "None";
opts.margin = new groupdocs_signature_cloud.Padding();
opts.margin.all = 5;
opts.margin_measure_type = "Pixels";
// set page to show signatures
opts.page = 1;
// define sign settings
let settings = new groupdocs_signature_cloud.SignSettings();
settings.fileInfo = fileInfo;
settings.options = [opts];
// define save options
settings.saveOptions = new groupdocs_signature_cloud.SaveOptions();
settings.saveOptions.outputFilePath = "signedDigital_sample.docx";
// create signature request
let request = new groupdocs_signature_cloud.CreateSignaturesRequest(settings);
let response = await signApi.createSignatures(request);
console.log("Output file link: " + response.downloadUrl);
// initialize api
let signApi = groupdocs_signature_cloud.SignApi.fromKeys(clientId, clientSecret);
// create file info
let fileInfo = new groupdocs_signature_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
// define sign digital options
let opts = new groupdocs_signature_cloud.SignDigitalOptions();
opts.signatureType = groupdocs_signature_cloud.OptionsBase.SignatureTypeEnum.Digital;
opts.imageFilePath = "signature.jpg";
opts.certificateFilePath = "certificate.pfx";
opts.password = "1234567890";
opts.allPage = true;
// define sign options
let settings = new groupdocs_signature_cloud.SignSettings();
settings.fileInfo = fileInfo;
settings.options = [opts];
// define save options
settings.saveOptions = new groupdocs_signature_cloud.SaveOptions();
settings.saveOptions.outputFilePath = "signedDigital_sample.pdf";
// create signature request
let request = new groupdocs_signature_cloud.CreateSignaturesRequest(settings);
let response = await signApi.createSignatures(request);
console.log("Output file link: " + response.downloadUrl);
var resourcesFolder = 'C:\\Files\\sample.docx';
fs.readFile(resourcesFolder, (err, fileStream) => {
// construct FileApi
var fileApi = groupdocs_signature_cloud.FileApi.fromConfig(config);
// create upload file request
var request = new groupdocs_signature_cloud.UploadFileRequest("sample.docx", fileStream, myStorage);
fileApi.uploadFile(request)
});
// initialize api
let signApi = groupdocs_signature_cloud.SignApi.fromKeys(clientId, clientSecret);
// create file info
let fileInfo = new groupdocs_signature_cloud.FileInfo();
fileInfo.filePath = "signedDigital_sample.docx";
// define verify options
let opts = new groupdocs_signature_cloud.VerifyDigitalOptions();
opts.signatureType = groupdocs_signature_cloud.OptionsBase.SignatureTypeEnum.Digital;
// define verify settings
let settings = new groupdocs_signature_cloud.VerifySettings();
settings.fileInfo = fileInfo;
settings.options = [opts];
// create verify signature request
let request = new groupdocs_signature_cloud.VerifySignaturesRequest(settings);
let response = await signApi.verifySignatures(request);
// show results
if (response.isSuccess) {
console.log("Successfully verified!");
}
else{
console.log("Not verified!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment