'Cannot create PdfStamper (NullReferenceException)
I have a specific problem that I cannot seem to resolve.
I am trying to create a PdfStamper with the following code.
The line marked with -->
is where the exception pops up.
PdfReader pdfReader = new PdfReader(SourcePdfFileName);
byte[] arr;
using (MemoryStream ms = new MemoryStream())
{
PdfStamper pdfStamper;
--> pdfStamper = PdfStamper.CreateSignature(pdfReader, ms, '\0');
arr = ms.ToArray();
}
and the other method I tried
PdfReader pdfReader = new PdfReader(SourcePdfFileName);
FileStream signedPdf = new FileStream(DestPdfFileName, FileMode.Create, FileAccess.Write);
--> PdfStamper pdfStamper = new PdfStamper.CreateSignature(pdfReader, signedPdf, '\0');
Both methods throw a NullReferenceException
.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=itextsharpStackTrace:
at iTextSharp.text.Version.GetInstance()
The original file exists on the path "SourcePdfFileName" and a blank pdf file is created when the file stream is opened. What am I missing ?
Edit: referring to this answer.
None of the parameters used in PdfStamper.CreateSignature() are null. The only null field here is the variable pdfStamper. I have tried initializing it with
PdfReader pdfReader = new PdfReader(SourcePdfFileName);
FileStream signedPdf = new FileStream(DestPdfFileName, FileMode.Create, FileAccess.Write);
PdfStamper pdfStamper = new PdfStamper(pdfReader,signedPdf);
which in return throws the same exception mentioned above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|