Marking Form Fields as Read Only in PDF (.NET Core/Framework)
Setting form fields to read only in a PDF using DynamicPDF Merger is straightforward.
How to Mark Form Fields as Read Only in PDF
Below are the steps and sample code to mark form fields as read only. After marking them as read only, the fields cannot be modified.
Steps for Marking Form Fields as Read Only in PDF
- Create a
MergeDocument
object with the desired PDF. - Set the field values.
- Make the form read only.
- Save the PDF.
Sample Code - C#
MergeDocument document = new MergeDocument(pdfFilePath);
document.Form.Fields["TextBox1"].Value = "My Text";
document.Form.IsReadOnly = true;
document.Draw(@"Output.pdf");
How to Mark Form Fields as Read Only with Encryption in PDF
Below are the steps and sample code to to mark form fields as read only with encryption. Marking form fields as read only does not prevent the PDF from being modified (through a PDF viewer) so that the read only property is turned off and then the form field content can be modified again. Adding encryption to the PDF document after the form fields have been set to read only will prevent users of the PDF from being able to modify the form fields.
Steps for Marking Form Fields as Read Only with Encryption in PDF
- Create a
MergeDocument
object with the desired pdf. - Set the IsReadOnly property on the Form to true.
- Create a
RC4128Security
with owner and user password. - Set the
AllowFormFilling
andAllowUpdateAnnotsAndFields
property to false. - set the documents security to
RC4128Security
. - Save the MergeDocument.
Sample Code - C#
MergeDocument document = new MergeDocument(pdfFilePath);
document.Form.IsReadOnly = true;
RC4128Security security = new RC4128Security("owner", "user" );
security.AllowFormFilling = false;
security.AllowUpdateAnnotsAndFields = false;
security.AllowEdit = false;
document.Security = security;
document.Draw(@"Output.pdf");
GitHub Project
Clone or view the example project at GitHub. This example code is contained in the Examples/FormFieldsReadOnly.cs file.
Getting Started
NuGet Package
DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is through the Visual Studio Package Manager. But you can also download directly from NuGet.
DynamicPDF Merger Information
More information can be found at the DynamicPDF Core Suite website.
Available on Other Platforms
DynamicPDF Core Suite is also available for Java and COM/AxtiveX platforms. Refer to the respective product pages for more details.
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX