Marking Form Fields Read Only
Setting form fields as read only in a PDF using DynamicPDF Core Suite for .NET is straightforward. The following C# example illustrates setting a form field as read only and adding encryption to ensure a form is read only.
How to Mark Form Fields as Read Only
Below are the steps and C# sample code to mark form fields as read only.
Steps for Marking Form Fields as Read Only
- Create a
MergeDocument
object with the desired PDF. - Set the field values.
- Set the
IsReadOnly
property on the form to true. - Add the
MergeDocument
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
MergeDocument document = new MergeDocument(pdfFilePath);
document.Form.Fields["TextBox1"].Value = "My Text";
document.Form.IsReadOnly = true;
document.Draw("Output.pdf");
Note: marking form fields as read only does not prevent the PDF from being modified when an end-user uses a PDF viewer. You must add encryption in addition to marking a field read only, as the next example illustrates.
How to Mark Form Fields as Read Only with Encryption
Below are the steps and C# sample code to to mark form fields as read only with encryption.
Steps for Marking Form Fields as Read Only with Encryption
- 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
properties to false. - Set the
MergeDocument
instancesSecurity
property to theRC4128Security
instance. - Add the
MergeDocument
object'sDraw
method to draw and save the PDF document.
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
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - FormFieldsReadOnly.cs
- VB.NET - FormFieldsReadOnly.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Form Fields
- Refer to the Marking Form Fields Read Only documentation topic, or
- Chapter 24, Modifying Forms, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX