Can't save PDF after filling in form fields with iTextSharp

View: New views
1 Messages — Rating Filter:   Alert me  

Can't save PDF after filling in form fields with iTextSharp

by Hogler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

Working on a project using itextsharp and vb.net where I want to produce a partially filled out PDF with editable forms and the option to sign with a digital signature.

I had it working just fine until last week when I started getting an error when trying to save the final document in Adobe Reader. The message says:
"The document could not be saved. There was a problem reading this document (26). "

I have a template PDF with forms and extended features enabled which I want to make an editable copy of with some of the forms filled out with data from database. The idea is to be able to take the pre-filled document out on a laptop to be filled out completely and signed offline.

The problem seems to occur as soon as I open the document with PdfStamper, set the value of a field and then close the document, using the code below. I even tried it with a blank PDF with just one field called "test" and still get the same error.  
' --
Dim reader As PdfReader = New PdfReader(sDocTemplate)
Dim stamper As New PdfStamper(reader, New FileStream(sOutputFile, FileMode.Append))
stamper.AcroFields.SetField("test", "hello")
stamper.Close()
' --

When I open the produced PDF there is a small window saying something about the document being damaged and repaired, then it opens and everything seems fine. The forms contain the proper data and everything, but when trying to save it the mentioned error message is displayed.

As I said, it was working fine right up until this error appeared out of the blue. I haven't updated any relevant software that I know of and I think I've eliminated all sources of error right down to itextsharp when testing with a blank pdf.

Any ideas of what could be wrong would be highly appreciated!

/ Fredrik