0

I need help.

I am writing a PDF digitally signed API application and am using PdfStamper. But when I run it, I get an error and I can't find the cause of the error. The error displayed is: 'Object reference not set to an instance of an object'

Help me! Thank you!

Below is the code that I wrote:

 public void doSign(String src, String dest, float llx, float lly, float urx, float ury, int NumPage, String FieldName)
        {
            try
            {
                PdfReader reader = new PdfReader(src);
                FileStream os = new FileStream(dest, FileMode.Create);
                PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0');
                Byte[] CertificateValue = SignAPI.GetCertificate();
                ICollection<X509Certificate> chain = this.GetCertificateChain(CertificateValue);
                PdfSignatureAppearance appearance = stamper.SignatureAppearance;
                X509CertificateParser cp = new X509CertificateParser();
                appearance.Certificate = cp.ReadCertificate(CertificateValue);
                appearance.SetVisibleSignature(new Rectangle(llx, lly, urx, ury), NumPage, FieldName);
                byte[] hash = this.CreateHash(appearance, chain);
                byte[] exSignature = this.MobilePKIHash(hash);
                this.AddSignature(appearance, exSignature);
            }   
            catch(Exception e)
            {
                File.AppendAllText(Directory.GetCurrentDirectory() + "/Log/Log.txt", "Ngày " + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss +0700") + ": Thực hiện Ký số thất bại! Lỗi --> " + e.ToString() + Environment.NewLine);
            }
        }

This is the error message dialog

0 Answers0