Examples

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


  1. Create a MergeDocument object with the desired PDF.
  2. Set the field values.
  3. Set the IsReadOnly property on the form to true.
  4. Add the MergeDocument object's Draw 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


  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 properties to false.
  5. Set the MergeDocument instances Security property to the RC4128Security instance.
  6. Add the MergeDocument object's Draw 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


Clone or View Example Project on GitHub

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.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

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

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.


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!