PDF Digital Signature with PAdES-LTV (Long Term Validation) in C#

void PdfLtvSignature(string unsignedDocument, string signedDocument)
      PdfSignature ps = new PdfSignature("");

      //load the PDF document
      ps.SignaturePosition = SignaturePosition.TopRight;
      ps.SigningReason = "I approve this document";
      ps.SigningLocation = "Accounting department";
      ps.SignaturePosition = SignaturePosition.TopLeft;
      //Load the certificate from Microsoft Store. 
      //The smart card or USB token certificates are usually available on Microsoft Certificate Store (start - run - certmgr.msc).
      //If the smart card certificate not appears on Microsoft Certificate Store it cannot be used by the library
      ps.DigitalSignatureCertificate = DigitalCertificate.LoadCertificate(false, "", "", "");

      //PAdES-LTV settings
      ps.HashAlgorithm = SignLib.HashAlgorithm.SHA256;

      //include the revocation info on the PDF file
      ps.PadesLtvLevel = PadesLtvLevel.IncludeCrlAndOcsp;
      //include also very large CRL files
      ps.MaxCrlSize = 2048 * 1024; //2 MB
      ps.SignatureStandard = PdfSignatureStandard.Cades;

      //the signature will be timestamped.
      ps.TimeStamping.ServerUrl = new Uri("http://ca.signfiles.com/TSAServer.aspx");
      ps.TimeStamping.HashAlgorithm = SignLib.HashAlgorithm.SHA256;

      //write the signed file
      File.WriteAllBytes(signedDocument, ps.ApplyDigitalSignature());

See also: