Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Jan 28, 2020 11:29 pm

Hi,

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?

dimulec1
 
Posts: 2
Joined: Sat Jan 25, 2020 10:37 pm

Wed Jan 29, 2020 7:11 am

Hello,

Thanks for your post.
Yes, we made adjustments about Security.SetProperties. Now it needs to use PdfSecurity.Encrypt method instead. Sorry, there is no overloaded method to directly set PdfPermissionsFlags.FillFields. But you can refer to the following code snippet to only set permission password. If there is any other question, just feel free to write back.
Code: Select all
......
pdf.Security.Encrypt("123", PdfPermissionsFlags.FillFields);
......

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Wed Jan 29, 2020 6:58 pm

Could you make another "adjustment" - to allow empty password? In which case PDF will not be encrypted.

dimulec1
 
Posts: 2
Joined: Sat Jan 25, 2020 10:37 pm

Thu Jan 30, 2020 1:32 am

Hello,

Thanks for your quick feedback.
You can refer to the following code snippet to set the empty passwords, if there is any other questions, please share us with your testing PDF file as well as the PDF reader you used to further look into it.
Code: Select all
......
pdf.Security.Encrypt(string.Empty, string.Empty, PdfPermissionsFlags.FillFields, PdfEncryptionKeySize.Key128Bit);
......

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF