Why is .pfx file mandatory while e sign?

I am trying to use aspose-pdf-cloud-node.js/test/testFields.ts at master · aspose-pdf-cloud/aspose-pdf-cloud-node.js · GitHub
to understand how e sign can be implemented. Let’s say I want to e-sign with name “test_user”. Then can’t I just set the rectangle coordinates, and sign can be placed at that place? why is signaturePath required? and considering my case, what should i do to generate it, if it is required?

Also, in above test case as well, I don’t understand where is this file “33226.p12”, coming from and what is its use?

@rajatdpw

Could you please clarify what specific issues you are facing with the e-sign implementation and the use of the .pfx file? Additionally, please provide more context about the ‘33226.p12’ file and its relevance to your implementation.

I already provided the reference link to github. I want to understand what pfx is required and why can’t i just provide the text and it should add that as signature?

PS: Also, can you explain what is meant by formFieldName and how should i create it?

@rajatdpw
You can read more about form fields in api reference Working with Form Fields|Documentation
In the part of the question about the signaturePath, this should be the path to the pfx file, previously uploaded to the cloud storage, the pfx file is necessary for signing the document and must contain the private key.

Who will give this pfx file or how to generate it? Can you help understand the flow?

@rajatdpw
You can use third party tools like openssl, it depends on your needs. For example, see:
https://docs.openssl.org/master/man1/openssl-pkcs12/

hey. Thanks for the reply. I downloaded a sample pfx file for testing and trying. got some error for the below curl:
curl -X POST “https://api.aspose.cloud/v3.0/pdf/aaoo.pdf/sign” -H “accept: application/json” -H "authorization: " -H “Content-Type: application/json” -H “x-aspose-client: Containerize.Swagger” -d “{ "SignaturePath": "fred.pfx", "SignatureType": "PKCS1", "Password": "apples", "Visible": true, "Rectangle": { "LLX": 0, "LLY": 0, "URX": 0, "URY": 0 }}”

Error:

"Errors": [
      {
        "Exception": null,
        "ErrorMessage": "FormFieldName must be provided when signing document."
      }
    ],

Now, I am trying to create field for the same pdf. Please see below curl:
curl -X POST “https://api.aspose.cloud/v3.0/pdf/aaoo.pdf/fields/signature” -H “accept: application/json” -H "authorization: " -H “Content-Type: application/json” -H “x-aspose-client: Containerize.Swagger” -d “{ "PageIndex": 1}”
image.png (194.6 KB)

Got this error. can you check what I am missing?

{
“RequestId”: “641dfa8d88455b2a6b2bc72009c6c19c”,
“Error”: {
“Code”: “internalError”,
“Message”: “Object reference not set to an instance of an object.”,
“Description”: “Operation Failed. Internal error.”,
“DateTime”: “2025-01-23T10:17:41.9670344Z”,
“InnerError”: null
}
}

@rajatdpw
Please see documentation at Sign PDF Documents|Documentation, Sign PDF Page|Documentation and you can use Aspose.Pdf Cloud - API References

We have noticed the reported issues and logged the following tickets in our issue tracking system for further investigation and rectification. We will notify you as soon as these issues are resolved.

PDFCLOUD-4682: PostSignatureField - Object reference not set to an instance of an object.

1 Like

FYI, As per this post, I also tried setting signature as null but still the error is same.

curl -X POST “https://api.aspose.cloud/v3.0/pdf/aaoo.pdf/fields/signature” -H “accept: application/json” -H "authorization: Bearer " -H “Content-Type: application/json” -H “x-aspose-client: Containerize.Swagger” -d “{ "PageIndex": 1, "Signature": null}”

{
“RequestId”: “887b18fa9c26cf9fa96ab2b9e69fcd94”,
“Error”: {
“Code”: “internalError”,
“Message”: “Object reference not set to an instance of an object.”,
“Description”: “Operation Failed. Internal error.”,
“DateTime”: “2025-01-24T04:26:21.8142407Z”,
“InnerError”: null
}
}

Hey, we have a hard timeline so I was wondering if you can help me with above issue as the request body seems very simple, so I might be missing something. I wanted to atleast complete POC of e-sign, so would really appreciate if you can shed light on above issue.

Hi, @rajatdpw
In your request you must set the rect property, try using this body:
{ "PageIndex": 1, "Signature": null, "Rect": {lLX: 100, lLY: 100, uRX: 0, uRY: 0}}

Hey. Thank you so much for your reply. So I tried with above request body and got 200 ok message. Although I didn’t see any field created in the file when I downloaded it but for now I am assuming it is created.

Above this api, there was an api to get field:
image.png (393.2 KB)

when I passed the same file name, I got below response.

{
  "Fields": {
    "List": [
      {
        "Signature": null,
        "PartialName": "field_1",
        "FullName": "field_1",
        "Rect": {
          "LLX": 0,
          "LLY": 0,
          "URX": 100,
          "URY": 100
        },
        "Value": null,
        "PageIndex": 1,
        "Height": 100,
        "Width": 100,
        "ZIndex": 0,
        "IsGroup": false,
        "Parent": null,
        "IsSharedField": false,
        "Flags": [
          "Print"
        ],
        "Color": {
          "A": 255,
          "R": 0,
          "G": 0,
          "B": 0
        },
        "Contents": "",
        "Margin": {
          "Left": 0,
          "Right": 0,
          "Top": 0,
          "Bottom": 0
        },
        "Highlighting": "Invert",
        "HorizontalAlignment": "Left",
        "VerticalAlignment": "Top",
        "Border": {
          "Width": 1,
          "EffectIntensity": 0,
          "Style": "Solid",
          "Effect": "None",
          "Dash": null,
          "Color": null
        },
        "Links": [
          {
            "Href": "/aaoo.pdf/fields/signature/field_1",
            "Rel": "self",
            "Type": null,
            "Title": null
          }
        ]
      }
    ],
    "Links": [
      {
        "Href": "/aaoo.pdf/fields/signature",
        "Rel": "self",
        "Type": null,
        "Title": null
      }
    ]
  },
  "Code": 200,
  "Status": "OK"
}

I am assuming that fieldName is ‘field_1’. I used the fieldName in add signature api and got below error:

image.png (226.1 KB)

Response:

{
  "RequestId": "dfce7dfbc4d80154c389d5ca40449bb8",
  "Error": {
    "Code": "internalError",
    "Message": "Certificate file was not provided.",
    "Description": "Operation Failed. Internal error.",
    "DateTime": "2025-01-25T15:42:23.7486097Z",
    "InnerError": null
  }
}

But I think I already provided a pfx file with password right? what certificate is it asking. Btw, I got a sample pfx file from here : Digital Certificate (PFX) which I used.

Just a follow up question on adding fields, I am using below request body:

{ “PageIndex”: 1, “Signature”: null, “Rect”: {lLX: 100, lLY: 100, uRX: 100, uRY: 100}, “ZIndex”: 1000000, “Color”: {
“A”: 10,
“R”: 10,
“G”: 10,
“B”: 10
}}

I am getting a response 200 ok, but I am not able to see this rectangle in my pdf. Note that my pdf is also 1 page pdf. Am i missing something?

Would be really helpful if you can share any body for both of the above mentioned apis for me tro get unblocked.

Hi, @rajatdpw
If you set Signature field to null, it will create an unsigned signature field unsignedField.png (1.8 KB) in result PDF document.
If you want to create a signed field signatureField.png (1.9 KB), you must pass the Signature field in your request, see aspose-pdf-cloud-node.js/docs/PdfApi.md at master · aspose-pdf-cloud/aspose-pdf-cloud-node.js · GitHub for details on the request. The file with the private key for signature must be previously uploaded to the cloud storage.

hey. So that means that atleast a field is created right? because I might not want right away signature to be added. Also, is it possible to view this rectangle in the pdf?

Regarding the pfx file, i believe it is already present in my cloud storage, with the name ‘fred.pfx’

As I mentioned, I downloaded a sample pfx file for the same link: Digital Certificate (PFX). Can you please check this as well if.I am missing something? In the website it says these are pkcs #12 files. Can this cause an issue?

PS: If possible, can you also try with the pfx file:
fred.zip (1.8 KB)

password is : apples

I got it from the above mentioned website.

Hi, @rajatdpw
You can view rectangle of the signature field in PDF Reader.

Try this code snippet

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/storage/file/file.pdf" -H "authorization: Bearer ACCESS_TOKEN" -F "File=@file.pdf"

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/storage/file/fred.pfx" -H "authorization: Bearer ACCESS_TOKEN" -F "File=@fred.pfx"

curl -X POST "https://api.aspose.cloud/v3.0/pdf/file.pdf/fields/signature" -H "authorization: Bearer ACCESS_TOKEN" -H "Content-Type: application/json" -d "{ "PageIndex": 1, "PartialName": 'sign1', "Rect": {"LLX": 100,"LLY": 100,"URX": 0,"URY": 0}, "Signature": {"SignaturePath": 'fred.pfx', "SignatureType": 'PKCS7', "Password": 'apples'}}"

curl -X GET "https://api.aspose.cloud/v3.0/pdf/storage/file/file.pdf" -H "authorization: Bearer ACCESS_TOKEN" --output output.pdf

Hi. Thank you so much for a detailed response. I tried above CURLs and below are their responses:

curl1:
image.png (99.6 KB)

curl2:
image.png (99.3 KB)

curl 3:

image.png (294.3 KB)

curl4:

image.jpg (136.7 KB)

here is the pdf which I got after using curl4:
file11.pdf (514.3 KB)

I don’t see any signature or any field in this. can you check if I am missing something?

PS: In the above request, I think you are setting signature also while creating a field. I wanted to understand:

  • In this case, where is option to add name of the signature? Like what name, what font to be used or image, where is that info getting added?
  • In the second case, where I don’t want this signature to be added while creating a field, and after creating a field, may be I want to use this endpoint: /pdf/{name}/sign. Is there anything else I need to do for that?

@rajatdpw
What application do you use to view PDF files?

  • When you create a field, you can use the Signature.CustomAppearance property to specify the appearance of the signature on the PDF document page.

  • Yes, you can add more than one signature to a PDF document.

I tried viewing it in Adobe. Can you also try as I am not able to see signature in any pdfviewer.

Also, as I asked, can you help me know like how to add a name or image in signature field?

PS: Can you also help me understand what does this means?

image.jpg (97.9 KB)

@rajatdpw
In your case, image.jpg contains a signature field added to the PDF page, but it does not display signature properties. If you want to display signature properties on the page, you should set the showProperties property to true. You can check signature properties in Signature, also you can change visibility or signature properties with CustomAppearance property.

{"ShowProperties":  true, "SignaturePath": 'fred.pfx', "SignatureType": 'PKCS7', "Password": 'apples' }

To add image you can use following code snippet:

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/storage/file/file.pdf" -H "authorization: Bearer ACCESS_TOKEN" -F "File=@file.pdf"

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/storage/file/fred.pfx" -H "authorization: Bearer ACCESS_TOKEN" -F "File=@fred.pfx"

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/storage/file/butterfly.jpg" -H "authorization: Bearer ACCESS_TOKEN" -F "File=@butterfly.jpg"

curl -X POST "https://api.aspose.cloud/v3.0/pdf/file.pdf/pages/1/sign" -H "authorization: Bearer ACCESS_TOKEN" -H "Content-Type: application/json" -d "{ "SignaturePath": 'fred.pfx', "SignatureType": 'PKCS7', "Password": 'apple', "Appearance": 'butterfly.jpg', "Reason": 'reason', "Visible": true, "Rectangle": { "LLX": 100, "LLY": 100, "URX": 500, "URY": 500 }, "ShowProperties": true }"

curl -X GET "https://api.aspose.cloud/v3.0/pdf/storage/file/file.pdf" -H "authorization: Bearer ACCESS_TOKEN" --output output.pdf