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.

Tue Aug 14, 2018 9:37 am

Hello, i have 2 questions
I use Spire.PDF Pack Version:4.0

1) I am having problem with signing documents with Spire.PDF
I use free trail version to make something that works so I could buy licence for this API.

So far i managed to digitaly sign 1 document with smart card. Problem is that every time i sign doc Windows10 prompts me 4 times to input PIN for smart card. Is it possible to bypass it so i could input PIN only once if i want to digitaly sign PDF?

2)Is it possible to digitaly sign more than one document?
I already tried to merge two documents in one PDF and than sign each page of merged PDF, than split it in multiple PDF-s. It does Sign each document but then windows prompts me 8 times for PIN...

C# code so far:
Code: Select all
string[] path = new string[2];
            path[0] = @"path\to\doc1.pdf";
            path[1] = @"path\to\doc2.pdf";
            string MergePath = @"\path\to\mergeddoc.pdf";

            //MERGE PDF
            PdfDocumentBase doc = PdfDocument.MergeFiles(path);
            doc.Save(MergePath, FileFormat.PDF);
            doc.Close();

            //Load Merged PDF
            PdfDocument doc1 = new PdfDocument(MergePath);
            //Load Certificate
            PdfCertificate cert = new PdfCertificate(@"path\to\certificate", "pass");
           
            for(int i=0; i<doc1.Pages.Count; i++)
            {
               
                PdfPageBase pageVar = doc1.Pages[i];

                var signature = new PdfSignature(doc1, pageVar, cert, "Requestd1");
                signature.Bounds = new RectangleF(new PointF(200, 600), new SizeF(750, 750));
                signature.NameLabel = "Digitally signed by";
                signature.Name = cert.Subject;
                signature.DistinguishedName = "DN:";
                signature.LocationInfoLabel = "Location:";
                signature.LocationInfo = "Rijeka";
                signature.ReasonLabel = "Reason: ";
                signature.Reason = "Potpis dokumenta";
                signature.DateLabel = "Date: ";
                signature.Date = DateTime.Now;
                signature.ContactInfoLabel = "Contact: ";
                signature.ContactInfo = "7441236985";
                signature.Certificated = false;
                if (i == doc1.Pages.Count-1)
                {
                    signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
                    signature.IsConfiguerGraphicFilledBounds = false;
                }               

            }
           
            doc1.CompressionLevel = PdfCompressionLevel.Best;
            doc1.SaveToFile(MergePath + "signed.pdf");

//SPLITTING INTO MLTIPLE PDF-s
            String pattern = "SplitDocument-{0}.pdf";           
            doc1.Split(pattern);           
            String lastPageFileName = String.Format(pattern, doc1.Pages.Count - 1);
            doc1.Close();

urobert
 
Posts: 1
Joined: Tue Aug 14, 2018 7:06 am

Tue Aug 14, 2018 10:22 am

Dear Robert,

Thanks for your inquiry.
The problems you described indeed exist in our Spire.Pdf while signing Pdf file with smart card. Our dev team will investigate the issues. If there is any progress, we will inform you. Sorry for the inconvenience caused.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Jan 08, 2021 9:04 am

Dear Robert,

Sorry for the long silence.
Glad to inform that we released Spire.PDF 7.1.0 which made some adjustments for PIN entering issue. Based on the PDF specification, now it needs to enter two times, one time is to check the length of the signature content, one time is to sign. Meanwhile, please refer to the attached custom class file (CustomPKCS7SignatureFormatter.cs), if adding the signature length parameter like the attached screenshot (CustomSignatureSetting.png), it will only need to enter one time, otherwise it needs to enter two times by default.

Please download the latest version from the following links and refer to the following code to test. If there is any question, just feel free to write back.
Website link: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/
Code: Select all
……
//Create CustomPKCS7SignatureFormatter
 CustomPKCS7SignatureFormatter customPKCS7SignatureFormatter = new CustomPKCS7SignatureFormatter(cert);
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], customPKCS7SignatureFormatter, "signature0");
signature.Bounds = new RectangleF(new PointF(90, 550), new SizeF(270, 90));
signature.GraphicsMode = GraphicMode.SignDetail;
signature.NameLabel = "Signer:";
signature.Name = "Test";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
signature.SignImageLayout = SignImageLayout.None;
//Save pdf file
doc.SaveToFile("output.pdf", Spire.Pdf.FileFormat.PDF);

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF