I'm attempting to use ITextSharp (version 5.5.13.3) in C# console app to open a pdf file for filling out the form fields, but am stuck as soon as I attempt to instantiate the PdfStamper with a stream. I've tried about a dozen or so pdf fillable files (not locked, nor encrypted) and verified permissions (set to "EveryOne"), but can't figure out what is actually null! The stream is valid from what I can tell and the PdfReader is, indeed, opening the file. This is my first attempt at doing this, but can't find a genuine working example (I copied this from a website as an example, and it doesn't work). Could it be the stream is of the wrong type? The error message is:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Since both the reader (which I can debug and see all the properties of the pdf file and form fields, no problem) and the stream are supposedly instantiated, what could this be?
using (MemoryStream ms = new MemoryStream())
{
PdfReader pdfReader = new PdfReader("D:/TestData/Direct Deposit Signup Form.pdf");
using (PdfStamper pdfStamper = new PdfStamper(pdfReader, ms, '\0', true))
{ ... }
The error appears on the
using pdfStamper
line. Doesn't seem to matter where the files are nor the security settings.
The full error (though, as usual, it's so cryptic who knows what is really going on):
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=itextsharp
StackTrace:
at iTextSharp.text.Version.GetInstance()
I haven't used this tool before, but would love to see a working example - perhaps the MemoryStream is the problem. Not sure where to start looking. Maybe I should download their source into another project and debug? Any ideas?