0

Right now I have a form template that has some fields that are prefilled from a database using the iTextSharp library. Users will then fill in the rest of the fields and save the filled out forms. I'll then extract the data and put it in the database.

Currently I am able to create the PDFs and they are pre-filling just fine. I'm even able to edit and save them in Adobe Reader on my computer. However I'm finding when anyone else opens those same files, they're not allowed to save the forms.

What do I need to do to allow the forms to be saved by all users using Adobe Reader? Here's the code I have to create the PDF:

Dim pdfReader As PdfReader = New PdfReader(formPath)
pdfReader.RemoveUsageRights()
Dim pdfStamper As PdfStamper = New PdfStamper(pdfReader, New FileStream(outputPath, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
Dim xfdfReader As XfdfReader = New XfdfReader(xfdfPath)

pdfFormFields.SetFields(xfdfReader)
pdfStamper.Close()

I used to have the problem that even I couldn't save the forms in Reader, and that's why I added this line:

pdfReader.RemoveUsageRights()

That made it so that I can edit the PDF it creates, which made me think everything was resolved. But nobody else can.

Charles
  • 50,943
  • 13
  • 104
  • 142
Brian Schroth
  • 2,447
  • 1
  • 15
  • 26
  • 1
    Are you sure you only have Adobe Reader and not Adobe Acrobat instead? And which version is it? – mkl Apr 08 '13 at 22:12
  • Yep.I used Acrobat to create the PDF form but I am definitely opening the files in Reader. I use Reader XI (apparently Adobe decided roman numerals are cool somewhere along the line). I have tried opening the file on another computer using Reader 9, so it could be as simple as a version issue and I need my users to install Reader XI. – Brian Schroth Apr 10 '13 at 15:34
  • Indeed Adobe changed what they allow their Reader users by default. Still, if you used PdfStamper in append mode, you might even be able to serve user of older Adobe Reader versions. – mkl Apr 10 '13 at 21:55

2 Answers2

1

Please consult the example ReaderEnabledForm.cs. It describes different ways to fill out a Reader Enabled form:

  1. breaking the Reader-enabling
  2. Removing the Reader-enabling
  3. Preserving the Reader-enabling

You've already tried 1 and 2, whereas you're asking for 3, involving adding extra parameters when creating a PdfStamper instance:

new PdfStamper(pdfReader, New FileStream(outputPath, FileMode.Create), '\0', true);
mkl
  • 90,588
  • 15
  • 125
  • 265
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
1

You just use this in your code. When creating PdfStamper you need to add extra parameters like this:

PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
    newPath, FileMode.CreateNew, FileAccess.Write), '\0', true);

This will do the trick.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
Robin Joseph
  • 1,210
  • 1
  • 11
  • 12