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.

Wed Jun 09, 2021 4:24 pm

Attached document has been signed with free Spire.PDF but Acrobat reader says the signature is invalid and the document has been changed. It also reports time is from the PC clock even though I have called ConfigureTimestamp.

Am I doing something wrong or could there be an issue with PdfSignature?

My (slightly simplified) signing method is as follows:

Code: Select all
   
private void SignWithSpire(Stream stream, int pageNum, string fieldName, string documentPath)
{
    Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(stream);
    Spire.Pdf.PdfPageBase page = doc.Pages[pageNum - 1];

    // Load certificate from resources
    var cert = new Spire.Pdf.Security.PdfCertificate(@"Resources\Wacom.Kiosk.IntegratorUI.p12", "password");

    // Find signature field widget
    var formWidget = doc.Form as Spire.Pdf.Widget.PdfFormWidget;
    var fieldWidget = formWidget.FieldsWidget[fieldName] as Spire.Pdf.Widget.PdfSignatureFieldWidget;

    // Create and initialize signature object
    var signature = new Spire.Pdf.Security.PdfSignature(doc, page, cert, fieldWidget.Name, fieldWidget)
    {
        Certificated = true,
        DocumentPermissions = Spire.Pdf.Security.PdfCertificationFlags.ForbidChanges,
    };

    string url = "http://timestamp.wosign.com/rfc3161";
    signature.ConfigureTimestamp(url);
    signature.ConfigureCustomGraphics(DrawSigImage);

    doc.SaveToFile(documentPath);
}

KevParkes
 
Posts: 2
Joined: Thu Apr 22, 2021 1:28 pm

Thu Jun 10, 2021 10:21 am

Hello,

Thanks for your inquiry.
I simulated your scenario to do a test, but didn't encounter your issue. The version I used is the latest Spire.PDF (Spire.PDF Pack Version: 7.6). I recommend that you first give the latest one a try, if the problem still exists, please provide the following information for our investigation. You could sent your file to us via email ([email protected]). Thanks in advance.
1) Your input PDF document and .p12 file.
2) Your test environment, such as OS info (E.g. Windows7, 64bit) and region setting (E.g. China, Chinese).
3) Your app type, such as Console app (.NET framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Jun 11, 2021 11:04 am

Hello,

Thank you for sharing.
I tested your case in the same environment, but still can’t reproduce your problem. Compared with your output file, I found that you have filled textbox fields. I also did a simulation but couldn't reproduce the problem. Below is my test code and attached is my output PDF. I supposed that the invalid signature issue might be that you did some extra operations on the PDF document. Could you please provide the full testing code or a runnable program to help us further investigate your issue? Thanks in advance.
Code: Select all
        static void Main(string[] args)
        {
            FileStream stream = File.OpenRead("WillBank.pdf");
            int page = 1;
            string path = " WillBank_output.pdf";
            SignWithSpire(stream, page, path);
        }

        private static void SignWithSpire(Stream stream, int pageNum, string documentPath)
        {
            PdfDocument doc = new PdfDocument(stream);
            PdfPageBase page = doc.Pages[pageNum - 1];
            // Load certificate from resources
            var cert = new PdfCertificate("Wacom.Kiosk.IntegratorUI.p12", "password");
            List < PdfSignature > signatures = new List<PdfSignature>();
            var form = (PdfFormWidget)doc.Form;
            for (int i = 0; i < form.FieldsWidget.Count; ++i)
            {
                if (form.FieldsWidget[i] is PdfSignatureFieldWidget)
                {
                    var fieldWidget = form.FieldsWidget[i] as Spire.Pdf.Widget.PdfSignatureFieldWidget;
                    // Create and initialize signature object
                    var signature = new Spire.Pdf.Security.PdfSignature(doc, page, cert, fieldWidget.Name, fieldWidget)
                    {
                        Certificated = true,
                        DocumentPermissions = Spire.Pdf.Security.PdfCertificationFlags.ForbidChanges,
                    };

                    string url = "http://timestamp.wosign.com/rfc3161";
                    signature.ConfigureTimestamp(url);
                    signature.ConfigureCustomGraphics(DrawSigImage);
                    void DrawSigImage(PdfCanvas g)
                    {
                        g.DrawString("Signed by:Test", new PdfFont(PdfFontFamily.Helvetica, 12f), PdfBrushes.Red, new Rectangle(0, 0, 120, 20));
                        g.DrawString("Spire.PDF", new PdfFont(PdfFontFamily.Helvetica, 12f), PdfBrushes.Red, new Rectangle(0, 20, 120, 20));
                        g.DrawString(DateTime.Now.ToString(), new PdfFont(PdfFontFamily.Helvetica, 15f), PdfBrushes.Blue, new Rectangle(0, 40, 120, 20));

                    }
                }
                if (form.FieldsWidget[i] is PdfTextBoxFieldWidget)
                {
                    var fieldWidget = form.FieldsWidget[i] as Spire.Pdf.Widget.PdfTextBoxFieldWidget;
                    fieldWidget.Text = "123";
                }
            }
            doc.SaveToFile(documentPath);
        }


Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Jun 22, 2021 8:13 am

Hi,

Greetings from e-iceblue.
How is your issue going? Has your issue been resolved? Can you give us some feedback at your convenience? Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron