
The stamp signature allows electronically signing PDF documents the same way that we use a rubber signature stamp on a paper document. We can sign PDF documents with a customized stamp signature programmatically on the cloud. In this article, we will learn how to sign PDF documents with stamp signatures using a REST API in Node.js.
The following topics shall be covered in this article:
PDF Signature REST API and Node.js SDK
For signing PDF documents, we will be using the Node.js SDK of GroupDocs.Signature Cloud API. It enables us to create, verify and search various types of signatures such as image, barcode, QR-Code, text-based, digital, and stamp signatures. Please install it using the following command in the console:
npm install groupdocs-signature-cloud
Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:
// 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"; |
Sign PDF Documents using a REST API in Node.js
We can sign PDF documents on the cloud by following the simple steps given below:
- Upload the file to the cloud
- Sign PDF Documents With Stamp Signatures
- Download the signed file
Upload the Document
Firstly, we will upload the PDF document to the cloud using the code example given below:
// 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); | |
}); |
As a result, the uploaded PDF file will be available in the files section of the dashboard on the cloud.
Sign PDF Documents with Stamp Signatures using Node.js
We can sign PDF files with stamp signatures programmatically by following the steps given below:
- Create an instance of the SignApi.
- Provide the uploaded PDF file path.
- Initialize the SignDigitalOptions object and set various properties.
- Define stamp text using StampLine objects.
- Assign input file, SignDigitalOptions and SaveOptions to the SignSettings object.
- Finally, sign the PDF using the SignApi.createSignatures() method.
The following code example shows how to sign a PDF document with stamp signatures using a REST API in Node.js.
// 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); |

Sign PDF Documents with Stamp Signatures using Node.js.
Download the Signed File
The above code sample will save the signed PDF file on the cloud. It can be downloaded using the following code sample:
// 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) { }); |
Try Online
Please try the following free online documents signature tool, which is developed using the above API. https://products.groupdocs.app/signature/
Conclusion
In this article, we have learned:
- how to sign PDF documents with stamp signatures;
- upload PDF file to the cloud;
- how to download signed PDF file from the cloud.
Besides, you can learn more about GroupDocs.Signature Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.