Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Mar 13, 2023 4:56 pm

Hello, which AATL certificates are compatible with Spire PDF Java? Because I see that some require a digital token or a USB security key. I would like to know which one you recommend to acquire my CERT.

mike2023
 
Posts: 1
Joined: Thu Jan 26, 2023 4:00 pm

Wed Mar 15, 2023 5:59 am

Hello,

Thanks for your inquiry.
Sorry we are not familiar with the AATL(Adobe Approved Trust List) certificate. I can confirm that our Spire.PDF supports signing PDF document with the USB Token(As the following code1). Maybe you can do a preliminary test first using the certificate with adobe AATL approved. In addition, for how to add digital signature, you can refer to the following code2.


Code1:
Code: Select all
//Load PDF document
 PdfDocument doc = new PdfDocument();
doc.LoadFromFile("test.pdf");
PdfPageBase page = doc.Pages[0];

//Get the certificate
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySerialNumber, "Your USB Token Cert", false);
X509Certificate2 cert1 = certs[0];
PdfCertificate cert = new PdfCertificate(cert1);

Spire.Pdf.Security.PdfSignature signature = new Spire.Pdf.Security.PdfSignature(doc, page, cert, "signature");
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
signature.GraphicsMode = Spire.Pdf.Security.GraphicMode.SignDetail;
signature.Certificated = true;
doc.CompressionLevel = PdfCompressionLevel.Best;

//Set the dispay mode of graphics
signature.GraphicsMode = Spire.Pdf.Security.GraphicMode.SignImageAndSignDetail;
signature.NameLabel = "Signer:";
signature.ContactInfoLabel = "ContactInfo:";
signature.ContactInfo = signature.Certificate.GetNameInfo(X509NameType.SimpleName, true);
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Chengdu";
signature.ReasonLabel = "Reason: ";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

//Set font
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);

 //Save the Pdf document
string output = "output.pdf";
doc.SaveToFile(output);


Code2:
Code: Select all
static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"../../data/WorkOrderPass_2623_2015621_263316.pdf");

            string pfxPath1 = @"../../data/gary.pfx";
         

            float x = 50;
            float y = 600;
            float width = 120;
            float height = 70;
            string signName = "Abel";
            //load the certificate
            PdfCertificate cert1 = new PdfCertificate(pfxPath1, "e-iceblue");
            sign(pdf, cert1, signName,x, y,width,height);
         
            //Save the result document
            pdf.SaveToFile(@"../../data/result.pdf",FileFormat.PDF);

        }
       
        static void sign(PdfDocument pdf, PdfCertificate cert, string signName, float x, float y, float width, float height)
        {
            //Create PdfOrdinarySignatureMaker
            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(pdf, cert);

            //Create signature1 and set details for the signature1
            Spire.Pdf.Interactive.DigitalSignatures.PdfSignature signature1 = signatureMaker.Signature;
            signature1.Name= signName;
            signature1.ContactInfo="Tom Tang";
            signature1.Location="China";
            signature1.Reason="protect document data";

            //Create appearance1
            PdfSignatureAppearance appearance1 = new PdfSignatureAppearance(signatureMaker.Signature);
            appearance1.NameLabel="Signer";
            appearance1.ContactInfoLabel="ContactInfo:";
            appearance1.LocationLabel="Location:";
            appearance1.ReasonLabel="Reason:";

            //Add signature1 to first page of PDF document.
            signatureMaker.MakeSignature(signName, pdf.Pages[0], x, y, width, height, appearance1);
        }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 951
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF