Search code examples
c#pdfitext

Can we add a digital signature using itextsharp while a pdf file is being created?


I have checked many questions that have been asked on stackoverflow and even read articles and books on itextsharp digital signature but could never find any solution. I want to add a digital signature at the end of my pdf file while I am writing the file. Is it possible to do that as PdfStamper.CreateSignature uses a pdfreader parameter. Could someone please help me with this issue?


Solution

  • No, there is no high-level iText API to allow single pass document creation and signing.

    You can of course try and port the PdfStamper oriented signing code to PdfWriter oriented signing code. But this does not really help that much.

    For example this won't allow you to simply stream the PDF in creation to a response stream as the signature to embed somewhere in the middle of the PDF cannot be created before the whole PDF except the signature is created.

    If you want to sign while creating the PDF because that's when you best know where to put the signature, you can instead create an empty signature field which can be signed in a later step.