Welcome Guest Search | Active Topics | Sign In | Register

EO.Pdf - How to set PdfTextField as Read-Only Options
Beginner
Posted: Thursday, February 12, 2015 7:10:17 PM
Rank: Newbie
Groups: Member

Joined: 2/12/2015
Posts: 2
Hi,

Is there anyway to make PdfTextField as Read-Only in C#?

Thanks.
eo_support
Posted: Monday, February 16, 2015 2:54:38 PM
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!


Beginner
Posted: Monday, February 16, 2015 5:05:19 PM
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).

eo_support
Posted: Monday, February 16, 2015 10:48:43 PM
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!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.