Add empty signature field in pdf

Hi, I have a similar need.
I have to add an empty signature field and then, with other library, I add to this field a signature from the smartcard.
Is it possible to add the empty field specifying to it must bu showed in all pages?

Ma code to add the empty field is simply:

Using editor As New FormEditor()
editor.BindPdf(“file.pdf”)
editor.AddField(FieldType.Signature, “Signature1”, 1, 360, 430, 480, 380)
editor.Save(“fileOut.pdf”)
End Using

@itconsult.developer

Yes, you can use the same code to insert empty signature field into PDF. We suggest you please use the latest version of Aspose.PDF for .NET 22.12 and let us know how it goes on your side.

Thank you.
I’m able to add an empty signature field to a pdf, using the code above.
But, it is possible to create a single field, visible on all pages?

I mean a file like this: fileAllPages.pdf (453.1 KB)

@itconsult.developer

You can achieve your requirements using following code example. Hope this helps you.

Document doc = new Document(dataDir + "input.pdf");
            
var editor = new FormEditor();
editor.BindPdf( dataDir + "input.pdf");

for (int page = 1; page <= doc.Pages.Count; page++)
{
    editor.AddField(FieldType.Signature, "Signature", page, 360, 430, 480, 380);
}
            
editor.Save( dataDir + "22.12.pdf");

I already tried this code, but this way N fields are created, each with unique name, like:
Signature
Signature1
Signature2

Instead, I want a unique field, visible on every page.
Alternatively, it is possibile to create N fields with the same name?

@itconsult.developer

You can change the filed name using following code snippet in output PDF.

 editor.AddField(FieldType.Signature, "Signature" + page, page, 360, 430, 480, 380);

Yes, you can create multiple fields with same name.

I’m sorry, maybe I didn’t explain myself well.

I would like to create a field visible on all pages, i.e. a single and unique field, but visible on all pages at the same position: can this be done?

If not, then could I create multiple fields with the same name? If yes, how do you do it?

@itconsult.developer

You can not create single and unique field that is visible on all pages of PDF.

Please check the code example shared in my old post here:

Ok, thank you about this question.

However, regarding the code you proposed to create multiple fields with the same name, it doesn’t work.
Please check the output file generated by your code:

22.12.pdf (536.3 KB)

In the second page, the field name is not “Signature”, but “Signature1”: Aspose library adds a “1” to the name specified by the call, if a field with the same name already exists.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

  Issue ID(s): PDFNET-53486

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@itconsult.developer

We have investigated the issue and prepare next conclusions:

We tested creating multiple fields with the same name, and it does not works correctly (only 1(first) field shown, other fields will be invisible).

But we found the best decision for this case:
Copy link for first field on every page.

I am sure this code snippet will help:

using (var editor = new FormEditor())
{
    editor.BindPdf(dataDir + "53486.pdf");
    //Add field for page #1
    editor.AddField(FieldType.Signature, "Signature", 1, 360, 430, 480, 380);
    //Find added field
    var addedField = editor.Document.Pages[1].Annotations[1];
    //Add link of added field for another pages
    for (int page = 2; page <= editor.Document.Pages.Count; page++)
    {
        editor.Document.Pages[page].Annotations.Add(addedField);
    }
    //Save result
    editor.Save(dataDir + "53486_result.pdf");
}

The field in the result file shown on every page. 53486_codesnippet_result.pdf (46.1 KB)

1 Like