none
How to Digitally Sign a PDF File / CryptoAPI RRS feed

Answers

  • I think you cannot just sign a PDF (or any other complex file format) without knowing its structure. You may get a signature of entire file data, but it cannot be embedded in the file itself or recognised by other software.

    For pdf, there's an open-source iTextSharp library which can handle all kind of tasks with pdf files, including digital signing. There's a lot of signature-related samples in the project sources.

    Friday, March 15, 2013 9:43 PM

All replies

  • Hi Harvey,

    Welcome to the MSDN Forum.

    Which part does not work on your side now?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 15, 2013 9:20 AM
    Moderator
  • Hi Mike:

    First, I posted the wrong link - the article I am looking at is http://msdn.microsoft.com/en-us/magazine/cc163454.aspx#S13

    I have not yet tried the code in figs 11 and 12, but I suspect I will need more than that and I dont even know if this code will still work 8 yrs after the article is written.

    we have PIV cards at my org and need users to be able to hit a button on a web page that says, "sign this PDF (or other) document, and the back end code does that.  Users would need to be prompted to enter their piv into the reader to enter their pin and access the signing certificate.

    thanks

    Harvey


    Regards, Harvey

    Friday, March 15, 2013 2:23 PM
  • I think you cannot just sign a PDF (or any other complex file format) without knowing its structure. You may get a signature of entire file data, but it cannot be embedded in the file itself or recognised by other software.

    For pdf, there's an open-source iTextSharp library which can handle all kind of tasks with pdf files, including digital signing. There's a lot of signature-related samples in the project sources.

    Friday, March 15, 2013 9:43 PM
  • Thanks Alex.  Yes, I have been delving into iTextSharp for the last few hours, looks like that's the way to go. 

    thanks for your assistance.


    Regards, Harvey

    Friday, March 15, 2013 9:54 PM
  • You can use GroupDocs.Signature for .NET (https://products.groupdocs.com/signature/net) to add digital signatures to the PDF documents using C#. You will have to provide the document's path and the digital signature options to sign the document, as described in the following code snippet.

    SignatureConfig Config = new SignatureConfig();
    // set the storage path - folder that contains the PDF document
    Config.StoragePath = "D:\\storage\\"; 
    // instantiate the signature handler
    var Handler = new SignatureHandler(Config);
    // setup digital signature options
    var SignOptions = new PdfSignDigitalOptions("sample.pfx", "sign.png");
    SignOptions.SignAllPages = true;
    SignOptions.HorizontalAlignment = Domain.HorizontalAlignment.Center;
    SignOptions.VerticalAlignment = Domain.VerticalAlignment.Top;
    // sign document
    var SignedFilePath = Handler.Sign<string>("Sample.pdf", SignOptions, new SaveOptions { OutputType = OutputType.String });


    • Edited by usman.aziz Friday, May 24, 2019 2:07 PM
    Friday, May 24, 2019 2:07 PM