Digital Signing of PDF Documents in Node.js with GroupDocs.Signature Cloud API Issue

Hello, first post here.
I followed the Node.js SDK example and so far I got this:

certificate = Assets.getBinary('keyStore.pfx')
imagePath = Assets.getBinary('base_icon_transparent_background.png')

axios.get(url, { responseType: 'arraybuffer' })
        .then (response) ->
          existingPdfBytes = response.data
          fileApi = GSignatureC.FileApi.fromConfig(config)
          request = new GSignatureC.UploadFileRequest("sample.pdf", existingPdfBytes, myStorage)

          await fileApi.uploadFile(request)
          signApi = await GSignatureC.SignApi.fromKeys(clientIdGroupDocs, clientSecretGroupDocs)

          fileInfo = new GSignatureC.FileInfo()
          fileInfo.filePath = "sample.pdf"

          opts = new GSignatureC.SignDigitalOptions()
          opts.signatureType = GSignatureC.OptionsBase.SignatureTypeEnum.Digital
          opts.imageFilePath = imagePath
          opts.certificateFilePath = certificate
          opts.password = ""

          settings = new GSignatureC.SignSettings()
          settings.fileInfo = fileInfo
          settings.options = [opts]

          settings.saveOptions = new GSignatureC.SaveOptions()
          settings.saveOptions.outputFilePath = "signedDigital_sample2.pdf"

          request = new GSignatureC.CreateSignaturesRequest(settings)
          response = await signApi.createSignatures(request)

However I keep getting error on the last line while waiting to sign. API log detail shows this: “Error: CreateSignatures. Error result: Dynabic.ProductsRestApi.Common.DTO.ApiErrorResponse.”

The “sample.pdf” is uploaded correctly.

What could be the issue?

Thanks in advance!

@biglesias

I have tested the scenario using the following sample node.js code with my sample files using the latest version of GroupDocs.Signature Cloud SDK for Node.js and was unable to notice the issue. Please share your sample script file with us. We will try to replicate and investigate the issue.

// Get your application information from https://dashboard.groupdocs.cloud
signature_cloud = require("groupdocs-signature-cloud");

const digitalSign = async () => {
// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
const clientId = "xxxx-xxxx-xxxxx-xxxxx-xxxx";
const clientSecret= "xxxxxxxxxxxxxxxxxxxxx";

// Initiate Signature API
signApi = signature_cloud.SignApi.fromKeys(clientId, clientSecret);

// Set input file path
let fileInfo = new signature_cloud.FileInfo();
fileInfo.filePath = "sample2.pdf";

// Set Signature Options
let opts = new signature_cloud.SignDigitalOptions();
opts.signatureType = signature_cloud.OptionsBase.SignatureTypeEnum.Digital;
opts.imageFilePath = "signature.jpeg";
opts.certificateFilePath = "signature.pfx";
opts.password = "xxxxxxx";
opts.visible = true;
opts.left = 167;
opts.top = 791;
opts.width = 180;
opts.height = 60;

let settings = new signature_cloud.SignSettings();
settings.fileInfo = fileInfo;
settings.options = [opts];

// Set SaveOption of signed document
settings.saveOptions = new signature_cloud.SaveOptions();
settings.saveOptions.outputFilePath = "signedDigital_sample2.pdf";

// Sign the document
let request = new signature_cloud.CreateSignaturesRequest(settings);
let response = await signApi.createSignatures(request);
}

digitalSign()
.then(() => {
console.log("PDF document signed successfully");
})
.catch((err) => {
console.log("Error occurred while signing the PDF document:", err);
})

I created a new file just to test using your new code and it’s still not working, displaying the same error on the API logs.

This is the whole file, just skipped the keys:

import axios from 'axios'
import signature_cloud from 'groupdocs-signature-cloud'

Meteor.methods
  "firma_simple_interlex.groupdocs": (doc) ->
    unless @userId
      return false

    clientIdGroupDocs = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    clientSecretGroupDocs = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    myStorage = ""
    config = new signature_cloud.Configuration(clientIdGroupDocs, clientSecretGroupDocs)
    config.apiBaseUrl = "https://api.groupdocs.cloud"

    url = doc.url

    certificate = Assets.getBinary('keyStore.pfx')
    usuario = Meteor.user()
    nombre = usuario.nombre.toUpperCase()
    rut = usuario.rut
    email = usuario.emails[0].address
    imagePath = Assets.getBinary('base_icon_transparent_background.png')

    axios.get(url, { responseType: 'arraybuffer' })
      .then (response) ->
        existingPdfBytes = response.data

        signApi = signature_cloud.SignApi.fromKeys(clientIdGroupDocs, clientSecretGroupDocs)

        fileInfo = new signature_cloud.FileInfo()
        fileInfo.filePath = "sample.pdf"

        opts = new signature_cloud.SignDigitalOptions()
        opts.signatureType = signature_cloud.OptionsBase.SignatureTypeEnum.Digital
        opts.imageFilePath = imagePath
        opts.certificateFilePath = certificate
        opts.password = ""
        opts.visible = true
        opts.left = 167
        opts.top = 791
        opts.width = 180
        opts.height = 60

        settings = new signature_cloud.SignSettings()
        settings.fileInfo = fileInfo
        settings.options = [opts]

        settings.saveOptions = new signature_cloud.SaveOptions()
        settings.saveOptions.outputFilePath = "signedDigital_sample2.pdf"

        request = new signature_cloud.CreateSignaturesRequest(settings)
        response = await signApi.createSignatures(request)

Is there another way to share it?

Please ensure that your input files (PDF, certificate file and image) exist on your cloud storage. However, if the issue persists, then please share your credentials (client ID and secret) via a private message.

Hello @tilal.ahmad,
Is it possible to edit how digital signature looks on PDF? I would love to mixture the signers info (name, email, etc.), our company logo behind while also be certificated with our PFX file.

Thanks

@biglesias

Please set the visible property of SignDigitalOptions to true, as its default value is false. It will help you to show the signature image in the output document. Hopefully, it will help you accomplish the task.

@tilal.ahmad
I already have it set to true:

opts = new signature_cloud.SignDigitalOptions()
opts.signatureType = signature_cloud.OptionsBase.SignatureTypeEnum.Digital
opts.imageFilePath = "sample_imagen.png"
opts.certificateFilePath = "sample_certificado.pfx"
opts.password = ""
opts.visible = true
opts.left = 300
opts.top = 791
opts.width = 180
opts.height = 60

But I want to be able to edit what is shown. To use the signer’s info from my database and use the “sample_imagen.png” as a background image for the signature. Is it possible?

@biglesias

Thanks for sharing additional information. You can use multiple signatures; digital, image, and text to get the desired look.

1 Like

@tilal.ahmad

Great, thanks!

Is there a way to place the text signature on top of the image signature? No matter the order in which I place each signature, text is always appearing below the image.

Or maybe be able to adjust the image transparency?

@biglesias

Please try the zOrder property of SignTextOptions to set the position of the text signature. It determines the display order of overlapping signatures.

@tilal.ahmad

Something like this?
TextOpts.zOrder = 1

Also, is it possible to change image transparency?

@biglesias

Yes.

Please try Transparency property of SignImageOptions for this purpose. Please note that it has 0 for opaque and 1 for clear, default value is 0.

1 Like

@tilal.ahmad

If one of my clients does a signature some time after another client did one on the same document, will the first signature be invalidated? Is incremental signing enabled by default?

Thanks

@biglesias

You can sign a PDF document with multiple digital signatures. Please let us know if you face any issues in this regard.

@tilal.ahmad

But if I mixture digital signature with other types like image and text, will it work? Or does it only need to be ‘signature_cloud.OptionsBase.SignatureTypeEnum.Digital’ to make valid all signatures?

@biglesias

Yes, it is expected to function with various types of signatures. However, if you encounter any challenges in it, please inform us.

@tilal.ahmad

I just signed twice with two different test users and I got this info from Adobe, what could it be, is not validating correctly?

I also uploaded the pdf doc itself.

Thanks

Group N°2 (1).pdf (550.8 KB)

groupdoc_signature.PNG (9.9 KB)

Also, I noticed that when I signed, the date timestamp on digital shows 3 hours into the future. Is there a way to specify the date and time?

I’ve just signed at 18:42 and it looks like this:
image_2024-04-11_184647711.png (2.4 KB)

Hi, @biglesias, we are looking into the issue and will update you as we get answers

To investigate the validation errors, we need input files (PDF, signature file, and password), you can send it in Private message, then we can perform analysis