I just purchased a pro version and trying to add form and form fields into a PDF. Everything seems nice, fields get created in proper places. But when I open the resulting document in Acrobat or in FoxitReader the fields cannot be edited no matter what I do. Acrobat says that there are fields and I should be able to edit them. But I cannot put cursor in there. What am I doing wrong.
I followed your tutorial on adding fields into an existing pdf.
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromBytes(fileData);
doc.AllowCreateForm = (doc.Form == null) ? true : false;
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13f);
PdfFormWidget widget = doc.Form as PdfFormWidget;
PdfTextBoxField textbox = new PdfTextBoxField(pg, "FieldName");
textbox.Bounds = new RectangleF(100, 100, 100, 15);
textbox.BorderWidth = 0.1f;
textbox.Font = font;
textbox.BorderStyle = PdfBorderStyle.Dashed;
textbox.BackColor = new PdfRGBColor(255, 255, 240);
widget.Fields.Add(textbox);
doc.SaveToStream(ms);
Update:
I found out what was wrong and, hence, another question. Properties of this particular document did not allow any changes. So, I tried
- Code: Select all
doc.Security.SetProperties(Spire.Pdf.Security.PdfPermissionsFlags.FillFields)
It worked but that function (SetProperties) is marked as obsolete. Recommendation is to use Encrypt() instead. I tried to use Encrypt() with password and the above permission flag and it also worked. But I don't want to encrypt this document ant I don't want to set a password. Empty password is not allowed. How do I decrypt it or set an above permission flag without using the Encrypt function?