Sign PDF file on last page

ぐ巨炮叔叔 提交于 2019-12-12 04:49:45

问题


I am using C# and iTextSharp 3.1 to sign PDF files. The signing is working, but I want to sign on the last page of the file. The code I use is such :

            reader = new PdfReader(inputPDF);
            int numberOfPages = reader.NumberOfPages;
            PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(outputPDF, FileMode.Create, FileAccess.Write), '\0', null, true);

            PdfSignatureAppearance sap = st.SignatureAppearance;
            if (logoSign != null)
            {
                // Scale img to fit
                logoSign.ScaleToFit(100, 50);
                // Set Signature position on page
                logoSign.SetAbsolutePosition(300, 80);
                sap.Image = logoSign;
            }

            sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
            if (SigReason.Length > 0)
                sap.Reason = SigReason;
            if (SigContact.Length > 0)
                sap.Contact = SigContact;
            if (SigLocation.Length > 0)
                sap.Location = SigLocation;
            if (visible)
                sap.SetVisibleSignature(mySignRect, 1, null);

            try
            {
                st.Close();
            } catch(Exception e) { }

This code signs of the 1st page of the file. I want o sign on the last page of the file. How do I set to sign on last page. I also wonder, the same code doesn't work in iTextSharp5.4.2. It gives error on sap.SetCrypto() and st.Close(). Any idea how to I make it work in 5.4.2.

Thanks


回答1:


Please try the C# version of the examples that come with the white paper referenced by mkl: http://sourceforge.net/p/itextsharp/code/HEAD/tree/tutorial/signatures/



来源:https://stackoverflow.com/questions/17218203/sign-pdf-file-on-last-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!