问题
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.
回答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.
回答2:
Please consult the example ReaderEnabledForm.cs. It describes different ways to fill out a Reader Enabled form:
- breaking the Reader-enabling
- Removing the Reader-enabling
- 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);
来源:https://stackoverflow.com/questions/15888977/how-can-i-prefill-a-pdf-form-with-itextsharp-while-still-having-it-be-editable-a