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.

Fri Aug 28, 2020 8:52 pm

I am evaluating spire.pdf specifically for digital signature and everything is good except for the configuretimestamp call. I can get your example to work, but it does not work properly in my code. Adobe is displaying the signature is invalid with corrupted data. Here is the code. If I remove the configuretimestamp call everything is ok.
Code: Select all
            // create a PdfDocument object and load a PDF file
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"DigitalSignature.pdf");
            PdfPageBase newPage = doc.Pages.Add(doc.Pages[0].Size);

            //load the certificate .pfx file
            PdfCertificate cert = new PdfCertificate(@"ari.pfx", "bobo");

            //add a signature to the specified position
            PdfBrush brush = PdfBrushes.Black;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 15, FontStyle.Bold), true);
            string ApprovalsLabel = "approvals";
            // draw an approval report header and
            // center it in the page.
            SizeF size = font.MeasureString(ApprovalsLabel);
            int x = (int)((newPage.Canvas.ClientSize.Width - size.Width) / 2.0);

            newPage.Canvas.DrawString(ApprovalsLabel, font,
            brush, new PointF(x, 0));
            newPage = doc.Pages[doc.Pages.Count - 1];
            RectangleF rect = new RectangleF(new PointF(10, 80),
    new SizeF(newPage.Canvas.ClientSize.Width - 10, 40));
            PdfFont detailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10);

            PdfSignature signature = new PdfSignature(doc, newPage, cert, "signature");

            //set the signature content
            // order of fields in the signature
            signature.NameLabel = "First Approver:";
            signature.Name = "Ari Hartstein";
            // provide a blank line
            signature.DistinguishedNameLabel = " ";
            signature.DistinguishedName = null;
            string bstrComment = "";
            // comment specified.
            if (bstrComment.Length > 0)
            {
                string CommentsLabel = "Comment";
                // here we are using the available fields to format
                // the signature to meet the spec. We are not using contact info
                signature.ReasonLabel = CommentsLabel;
                signature.Reason = bstrComment;

                signature.LocationInfoLabel = null;
                // provide a blank line
                signature.ContactInfoLabel = "  ";
                // increase the size of the signature by the height of the comment
                SizeF reasonSize = detailsFont.MeasureString(signature.ReasonLabel + signature.Reason);
                SizeF reasonSizeBlank = detailsFont.MeasureString(" ");
                // compute the number of lines needed for the comment, hopefully 1
                float fCommentsHeight = (float)Math.Ceiling(reasonSize.Width / rect.Width) * rect.Height;
                rect.Height +=
                    reasonSize.Height + reasonSizeBlank.Height;
            }
            signature.Bounds = rect;
            // signature date.
            string DateLabel = "Date:";
            signature.DateLabel = DateLabel;
            signature.Date = DateTime.Now;
            signature.Bounds = rect;



            bool IsFinal = false;
            // if not final then allow for additional signatures.
            signature.DocumentPermissions = IsFinal ?
             PdfCertificationFlags.ForbidChanges :
            PdfCertificationFlags.AllowComments;

            // certify the document
            signature.Certificated = IsFinal;

            //Set fonts. if not set, default ones will be applied.
            signature.SignDetailsFont = detailsFont;
            signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15, PdfFontStyle.Bold);
            //Display signer name and all the above labels.
            signature.SignImageLayout = SignImageLayout.None;

            if (signature.Certificate.SignatureAlgorithm.FriendlyName ==
                "sha1RSA")
                signature.ConfigureTimestamp("http://timestamp.digicert.com");
            doc.SaveToFile("output.pdf");


hartstein
 
Posts: 5
Joined: Wed Aug 05, 2020 3:50 pm

Mon Aug 31, 2020 8:04 am

Hello,

Thanks for your inquiry.
I did an initial test with Spire.PDF Pack(Hot Fix) Version:6.8.5, but did not reproduce your issue. This is my testing project, please run it directly and then let us know your test result.
If the issue persists, please tell us your OS information (E.g. Window 7, 64bit) and region setting (E.g. China, Chinese). Thanks in advance.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Mon Aug 31, 2020 5:17 pm

The original test I did was with version 6.8.1. What I am seeing with version 6.8.5 is that success or failure of the operation is erratic, almost as though a timeout is occurring. I have modified the program to put it in a loop, and it seems to fail about half the time.

My os version is windows 10 build 1909 (64 bit) and is USA English.

I am using .net framework version 4.6.1 but I can converted to use 4.7.2 if that is needed to correct the problem.

hartstein
 
Posts: 5
Joined: Wed Aug 05, 2020 3:50 pm

Tue Sep 01, 2020 3:56 am

Hello,

Thanks for your feedback.
I tested your case in a similar environment to yours and finally reproduced your issue. I have logged it in our bug tracking system with the ticket SPIREPDF-3547 for further investigation. We will let you know if there is any progress. Sorry for the inconvenience caused.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Thu Oct 15, 2020 2:35 am

Hello,

Hope you are doing well.
Glad to inform you that your issue has been resolved in the recently released Spire.PDF Pack(Hot Fix) Version:6.10.0. Welcome to download it from the following links and test.
Our website: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget: https://www.nuget.org/packages/Spire.PDF/6.10.0

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF

cron