Question

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??

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top