Learn how to use the new option for flattening form fields in PdfProcessing.
With R2 2021, the TelerikPdfProcessing library shipped a brand new functionality—the ability to easily remove all fields and preserve their values by calling a single method instead of doing it manually. This new feature allows you to make the document read-only after the user has filled it, and, in this blog post, we will walk you through that functionality.
To flatten a form field means to merge its current value with the other content on the page. With this action, the fields are converted to text content and cannot be edited anymore. Since the release of the interactive forms (form fields) support in PdfProcessing, many of you asked about flattening these fields. As we are constantly listening to your feedback, we are now introducing that functionality with R2 2021.
In this post, I will show you how to fill the values of a predefined template with interactive forms and how to flatten them.
In the following picture, you will see the example document we are going to fill using PdfProcessing and its API:
In this sample document, the form fields are named as follows:
To start manipulating the document, first we should import it into a RadFixedDocument instance:
This RadFixedDocument instance gives us access to the AcroForm that keeps all the form fields inside the document. The next snippet shows how you can obtain the fields by their names and fill their values:
Now, if you decide to save the document at its current stage, the values will be preserved along with the interactivity of the form fields. The content will look like shown in the next image:
As you can see, the fields still can be modified. With the new option in PdfProcessing to flatten the forms fields, you can merge the content of the document with the values of the fields just by invoking a single method.
Let’s try the flattening option. The method that flattens the fields values is exposed by the document’s AcroForm:
To see the results, we will need to also save the document that we have already modified:
And here is how the flattened document looks like:
All the content inside that document is now simple text and the users cannot further modify it.
That was easy, no?
Still haven’t tried Telerik Document Processing? Download a free trial and explore all the great features that come with the libraries.
If you are already familiar with the package, don’t forget that we are always happy to hear your feedback. Feel free to drop us a comment below sharing your thoughts. Or visit our Document Processing Libraries Feedback Portal and let us know if you have any suggestions or if you need any particular features.
Happy flattening! 🤘🏼
Tanya Dimitrova is a Tech Support Engineer in the Telerik XAML Team. In her work her main responsibility is to assist clients to implement different scenarios using the document processing libraries and editors. She is passionate in finding new adventures and in her free time enjoys travelling, reading, swimming, dancing or just spending time with friends.
Subscribe to be the first to get our expert-written articles and tutorials for developers!