Examples

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

  1. Create a MergeDocument object with the desired PDF.
  2. Set the field values.
  3. Make the form read only.
  4. 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

  1. Create a MergeDocument object with the desired pdf.
  2. Set the IsReadOnly property on the Form to true.
  3. Create a RC4128Security with owner and user password.
  4. Set the AllowFormFilling and AllowUpdateAnnotsAndFields property to false.
  5. set the documents security to RC4128Security.
  6. 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.

Clone or View Example Project on GitHub

Getting Started

NuGet Package

DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NETpackage. The easiest way to install the package is through the Visual Studio Package Manager. But you can also download directly from NuGet.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

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.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 22 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!