HTML JPG PDF XML DOCX
  Product Family
PDF

Sign PDF in Node.js Cloud API

API for working with Signature in PDF documents using Cloud Node.js SDK

Get Started

How to add Signature to PDF via Node.js SDK

To add signature into PDF, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.

Package Manager Console Command


     
    npm install asposepdfcloud --save
     
     

Steps to add Signature into PDF via Cloud Node.js

Aspose.PDF Cloud developers can easily load & add Signature to PDF in just a few lines of code.

  1. Read the local PDF file.
  2. Uploads the PDF file to the Aspose PDF Cloud storage.
  3. Create and Add the Digital Signature
  4. Downloads the updated PDF file from the Aspose PDF Cloud storage.
 

Add Signature to PDF using Node.js


    import credentials from "../../../Credentials/credentials.json"  with { type: "json" };
    import fs from 'node:fs/promises';
    import path from 'node:path';
    import { PdfApi } from "../../src/api/api.js";
    import {Signature} from "../../src/models/signature.js";
    import {SignatureType} from "../../src/models/signatureType.js";
    import {SignatureField} from "../../src/models/signatureField.js";

    const configParams = {
        LOCAL_FOLDER: "C:\\Samples\\",
        PDF_DOCUMENT_NAME: "sample.pdf",
        LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
        LOCAL_SIGNATURE_PATH: "C:\\Samples\\Signatures\\3",
        SIGNATURE_PFX: "signature.pfx",
        SIGNATURE_FORM_FIELD: 'Signature_1',
        SIGNATURE_PASSWORD: 'Password',
        SIGNATURE_CONTACT: 'Contact',
        SIGNATURE_LOCATION: 'Location',
        SIGNATURE_AUTHORITY: 'Issuer',
        SIGNATURE_DATE: '04/19/2025 12:15:00.000 PM',
        SIGNATURE_RECT:  { lLx: 100, lLy: 100, uRx: 500, uRy: 500 }
    };

    const pdfApi = new PdfApi(credentials.id, credentials.key);

    const pdfSignatures = {
        async uploadFile (folder, fileName) {
            const fileNamePath = path.join(folder, fileName);
            const pdfFileData = await fs.readFile(fileNamePath);
            await pdfApi.uploadFile(fileName, pdfFileData);
            console.log("File '" + fileName + "' successfully uploaded!");
        },

        async uploadDocument () {
            await this.uploadFile(configParams.LOCAL_FOLDER, configParams.PDF_DOCUMENT_NAME);
        },
                        
        async downloadResult () {
            const changedPdfData = await pdfApi.downloadFile(configParams.PDF_DOCUMENT_NAME);
            const filePath = path.join(configParams.LOCAL_FOLDER, configParams.LOCAL_RESULT_DOCUMENT_NAME);
            await fs.writeFile(filePath, changedPdfData.body);
            console.log("Downloaded: " + filePath);
        },

        async addSignature () {
            if (pdfApi)
            {  
                
                const signature = new Signature();
                signature.authority = configParams.SIGNATURE_AUTHORITY;
                signature.contact = configParams.SIGNATURE_CONTACT;
                signature.date = configParams.SIGNATURE_DATE;
                signature.formFieldName = configParams.SIGNATURE_FORM_FIELD;
                signature.location = configParams.SIGNATURE_LOCATION;
                signature.password = configParams.SIGNATURE_PASSWORD;
                signature.rectangle = configParams.SIGNATURE_RECT;
                signature.signaturePath = configParams.SIGNATURE_PFX;
                signature.signatureType = SignatureType.PKCS7;
                signature.visible = true;

                const field = new SignatureField();
                field.pageIndex = 1;
                field.signature = signature;
                field.partialName = 'sign1';
                field.rect = configParams.SIGNATURE_RECT;

                const response = await pdfApi.postSignatureField(configParams.PDF_DOCUMENT_NAME, field);

                if (response.body.code == 200)
                    console.log("addSignature(): Signature '" + configParams.SIGNATURE_CONTACT + "' successfully added to the document.");
                else
                    console.error("addSignature(): Failed to add signature to the document. Response code: " + response.body.code);
            }
        },
    }

    async function main() {
        try {
            await pdfSignatures.uploadFile(configParams.LOCAL_SIGNATURE_PATH, configParams.SIGNATURE_PFX);
            await pdfSignatures.uploadDocument();
            await pdfSignatures.addSignature();
            await pdfSignatures.downloadResult();
        } catch (error) {
            console.error("Error:", error.message);
        }
    }
 

Work with Signature in PDF

Digitally signing a PDF ensures the authenticity, integrity, and legitimacy of a document. It verifies that the content has not been altered since the signature was applied and confirms the identity of the signer. This is especially important in legal, financial, and professional settings where document trust and security are critical. Digital signatures also help meet compliance standards and streamline approval workflows in a secure, verifiable manner. Add the Signature into PDF documents with Aspose.PDF Cloud Node.js SDK.

With our Node.js library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free Apps to test the functionality online.