Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sign PDF with Stamp using a REST API in Node.js

Learn how to sign PDF documents with stamp signatures using a REST API in Node.js.

// This code example demonstrates how to add your Client Id and Secret in the code.
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";
// This code example demonstrates how to download a signed PDF from the cloud.
// Construct FileApi
var fileApi = groupdocs_signature_cloud.FileApi.fromConfig(config);
// Download file
let request = new groupdocs_signature_cloud.DownloadFileRequest("signedStamp_One_page.pdf", myStorage);
let response = await fileApi.downloadFile(request);
// Move to working folder
fs.writeFile("C:\\Files\\Signature\\signedStamp_One_page.pdf", response, "binary", function (err) { });
// This code example demonstrates how to sign PDF document with stamp signatures.
// Create an instance of the API
let signApi = groupdocs_signature_cloud.SignApi.fromKeys(clientId, clientSecret);
// Input file path
let fileInfo = new groupdocs_signature_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
// Define sign stamp options
let opts = new groupdocs_signature_cloud.SignStampOptions();
opts.signatureType = groupdocs_signature_cloud.OptionsBase.SignatureTypeEnum.Stamp;
// Set stamp position and size on a page
opts.left = 200;
opts.top = 400;
opts.width = 300;
opts.height = 300;
opts.locationMeasureType = groupdocs_signature_cloud.SignTextOptions.LocationMeasureTypeEnum.Pixels;
opts.sizeMeasureType = groupdocs_signature_cloud.SignTextOptions.SizeMeasureTypeEnum.Pixels;
opts.rotationAngle = 0;
opts.horizontalAlignment = groupdocs_signature_cloud.SignTextOptions.HorizontalAlignmentEnum.None;
opts.verticalAlignment = groupdocs_signature_cloud.SignTextOptions.VerticalAlignmentEnum.None;
// Add padding
opts.margin = new groupdocs_signature_cloud.Padding();
opts.margin.all = 5;
opts.marginMeasureType = groupdocs_signature_cloud.SignTextOptions.MarginMeasureTypeEnum.Pixels;
// Set stamp appearance
opts.backgroundColor = new groupdocs_signature_cloud.Color();
opts.backgroundColor.web = "DarkOrange";
opts.backgroundColorCropType = groupdocs_signature_cloud.SignStampOptions.BackgroundColorCropTypeEnum.OuterArea;
opts.backgroundImageCropType = groupdocs_signature_cloud.SignStampOptions.BackgroundImageCropTypeEnum.InnerArea;
// Define 1st Outline text appearance
let outline1 = new groupdocs_signature_cloud.StampLine();
outline1.text = " * Electronically Signed by GroupDocs.Signature * ";
// Font
outline1.font = new groupdocs_signature_cloud.SignatureFont();
outline1.font.fontFamily = "Arial";
outline1.font.fontSize = 11;
outline1.font.bold = true;
outline1.textBottomIntent = 6;
// Color
outline1.textColor = new groupdocs_signature_cloud.Color();
outline1.textColor.web = "WhiteSmoke";
outline1.textRepeatType = groupdocs_signature_cloud.StampLine.TextRepeatTypeEnum.FullTextRepeat;
// Background color
outline1.backgroundColor = new groupdocs_signature_cloud.Color();
outline1.backgroundColor.web = "DarkSlateBlue";
outline1.height = 22;
outline1.visible = true;
// Define 2nd Outline text appearance
let outline2 = new groupdocs_signature_cloud.StampLine();
outline2.height = 2;
outline2.backgroundColor = new groupdocs_signature_cloud.Color();
outline2.backgroundColor.web = "White";
outline2.visible = true;
// Define 3rd Outline text appearance
let outline3 = new groupdocs_signature_cloud.StampLine();
outline3.text = " * GroupDocs.Signature * ";
// Font
outline3.font = new groupdocs_signature_cloud.SignatureFont();
outline3.font.fontFamily = "Arial";
outline3.font.fontSize = 16;
outline3.textBottomIntent = 8;
outline3.textRepeatType = groupdocs_signature_cloud.StampLine.TextRepeatTypeEnum.FullTextRepeat;
// Color
outline3.textColor = new groupdocs_signature_cloud.Color();
outline3.textColor.web = "DarkSlateBlue";
// Background color
outline3.backgroundColor = new groupdocs_signature_cloud.Color();
outline3.backgroundColor.web = "White";
outline3.height = 30;
// Inner border
outline3.innerBorder = new groupdocs_signature_cloud.BorderLine();
outline3.innerBorder.color = new groupdocs_signature_cloud.Color();
outline3.innerBorder.color.web = "DarkSlateBlue";
outline3.innerBorder.style = groupdocs_signature_cloud.BorderLine.StyleEnum.Dot;
outline3.innerBorder.weight = 1.2;
// Outer border
outline3.outerBorder = new groupdocs_signature_cloud.BorderLine();
outline3.outerBorder.color = new groupdocs_signature_cloud.Color();
outline3.outerBorder.color.web = "DarkSlateBlue";
outline3.outerBorder.weight = 1.4;
outline3.visible = true;
opts.outerLines = [outline1, outline2, outline3];
// Define 1st inline text
let innerline = new groupdocs_signature_cloud.StampLine();
innerline.text = "GroupDocs";
innerline.font = new groupdocs_signature_cloud.SignatureFont();
innerline.font.fontFamily = "Times New Roman";
innerline.font.fontSize = 20;
innerline.font.bold = true;
innerline.textColor = new groupdocs_signature_cloud.Color();
innerline.textColor.web = "MediumVioletRed";
innerline.textRepeatType = groupdocs_signature_cloud.StampLine.TextRepeatTypeEnum.None;
innerline.height = 40;
innerline.visible = true;
// Define 2nd inline text
let innerline2 = new groupdocs_signature_cloud.StampLine();
innerline2.text = "Signature";
innerline2.font = new groupdocs_signature_cloud.SignatureFont();
innerline2.font.fontSize = 20;
innerline2.font.bold = true;
innerline2.textColor = new groupdocs_signature_cloud.Color();
innerline2.textColor.web = "MediumVioletRed";
innerline2.textRepeatType = groupdocs_signature_cloud.StampLine.TextRepeatTypeEnum.None;
innerline2.height = 40;
innerline2.visible = true;
// Define 3rd inline text
let innerline3 = new groupdocs_signature_cloud.StampLine();
innerline3.text = "Cloud";
innerline3.font = new groupdocs_signature_cloud.SignatureFont();
innerline3.font.fontSize = 20;
innerline3.font.bold = true;
innerline3.textColor = new groupdocs_signature_cloud.Color();
innerline3.textColor.web = "MediumVioletRed";
innerline3.textRepeatType = groupdocs_signature_cloud.StampLine.TextRepeatTypeEnum.None;
innerline3.height = 40;
innerline3.visible = true;
opts.innerLines = [innerline, innerline2, innerline3];
// Page no where to show the stamp
opts.page = 1;
// Define Sign settings
let settings = new groupdocs_signature_cloud.SignSettings();
settings.fileInfo = fileInfo;
settings.options = [opts];
settings.saveOptions = new groupdocs_signature_cloud.SaveOptions();
settings.saveOptions.outputFilePath = "signedStamp_One_page.pdf";
// Create sign request
let request = new groupdocs_signature_cloud.CreateSignaturesRequest(settings);
// Create signatures
let response = await signApi.createSignatures(request);
console.log("Output file link: " + response.downloadUrl);
// This code example demonstrates how to upload a PDF file to the cloud.
// Open file in IOStream from local/disc.
var resourcesFolder = 'C:\\Files\\Signature\\sample.pdf';
fs.readFile(resourcesFolder, (err, fileStream) => {
// Construct FileApi
var fileApi = groupdocs_signature_cloud.FileApi.fromConfig(config);
// Upload file
var request = new groupdocs_signature_cloud.UploadFileRequest("sample.pdf", fileStream, myStorage);
fileApi.uploadFile(request);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment