|
Rank: Newbie Groups: Member
Joined: 2/12/2015 Posts: 2
|
Hi,
Is there anyway to make PdfTextField as Read-Only in C#?
Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, Unfortunately there is no way to set a single PDF field as readonly. The closest you can get is to disable the whole form. That way user will not be able to change any form field. The following code would disable all form fields:
Code: C#
//Open the PDF file
PdfDocument doc = new PdfDocument(your_pdf_file_name);
//Change some form fields values
doc.Fields[some_field].Value = some_value;
//Remove all modifying permissions
doc.Security.Disallow(
PdfDocumentPermissions.ModifyingContents |
PdfDocumentPermissions.FillingFormFields |
PdfDocumentPermissions.Commenting);
//Save the result file
doc.Save(result_pdf_file_name);
This will render the whole fill form as readonly. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 2/12/2015 Posts: 2
|
Thanks for your answer. I can't disable the whole form, but pre-populate some fields and disable it so user can't change (for example: pre-populate Company name, Cheque payable) and leave other fields as editable text field (ie. Cheque amount, Date ... etc).
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, We have posted a new build that added PdfField.ReadOnly field. Please download the latest build from our download page and see if it works for you. The code would be something like this:
Code: C#
//Load the PDF file
PdfDocument doc = new PdfDocument(pdf_file_name);
//Get the input field
PdfField field = doc.Fields[field_name];
//Set the field value
field.Value = field_value;
//Set the field to readonly. ReadOnly property is newly added
field.ReadOnly = true;
//Save the result file
doc.Save(result_pdf_file);
Please take a look and let us know how it goes. Thanks!
|
|