Flatten PDF Forms
This guide will show you how to flatten form fields in a PDF document.
Form flattening is the process of rendering dynamic form fields into static fields in the PDF document, just like any other text or image in the document. When a PDF document is flattened, its annotations will be removed; the document can no longer be edited.
Before you begin
You should get your API key from your UniCloud account.
If you are using the UniPDF SDK for the first time, follow this guide to set up a local development environment.
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unipdf-examples.git
Navigate to the
forms folder in the unipdf-examples directory.
How it works
10–19 import the UniPDF packages and other required dependencies.
The init function in lines
21-28 authenticates your request with your
The main function in lines
30–60 validates your input and passes the
outputPath as arguments to the
flattenPdf function in lines
64–96 reads the input PDF and flatten its annotations and form fields such that the PDF document cannot be modified.
Run the code
Run this command to flatten form fields in a PDF document. This will also install the required dependencies to run the program.
The output PDF document is flattened and cannot be modified.