2
votes

I have a PDF form template that I fill from your C# code with values, to be printed out.

Suddenly, my customer reports errors - when trying to print the PDF (from an ASP.NET page), they get:

Unable to cast object of type 'iTextSharp.text.pdf.PdfName' to type 'iTextSharp.text.pdf.PdfIndirectReference'

When digging in my code, I discovered this error happens on this line of code here:

PdfReader reader = new PdfReader("MyPdfTemplateName.pdf");
PdfStamper stamper = new PdfStamper(reader, ms);

// filling field values here.....

stamper.FormFlattening = true;  // **** EXCEPTION HERE *****
stamper.Writer.CloseStream = false; 
stamper.Close();

The funny thing is: this only happens with the "new" version 5.0 of iTextSharp - I went back to my previous version 4.1.2, and with the exact same code, exact same PDF form, it works flawlessly.....

Anyone have any idea or insight as to why the new v5 of iTextSharp behaves this way??

1
Are you getting this with all PDF forms that you use, or is it just a particular one? - Paddy
@Paddy: some work - other don't - marc_s
The iText support is a bit odd, but have you tried posting on their mailing list: lists.sourceforge.net/lists/listinfo/itext-questions - Paddy
Do you really need to upgrade to the latest version of the library, or could you simply continue to use the preceding version which works? This only reminds me of an expression: "If it's not broken, don't fix it"! That is, indeed, if you don't particularly need what v5.0 offers. - Will Marcouiller
@Will Marcouiller: since the upgrade to v5 didn't solve my other problem either, I'll probably go back. I'm just curious to know what "broke" between v4 and v5, and how to fix it, if I ever do need to go to v5 for some reason. - marc_s

1 Answers

1
votes

Use the source, Marc! Step in and find out what's wrong.

You'll have to use SVN directly to download it from the SourceForge page... I use tortiseSVN which integrates with Windows Explorer quite nicely. Love it.

I'm surprised Paulo isn't offering a source download. I'll ask him about it.

Turns out the non-dll-only zip contains... The Source. Wow, who saw that coming? So any way, step in, see what's up.