How to Flatten PDF Forms with cURL

Learn how to use the Flatten Forms API Tool by pdfRest to flatten PDF forms with cURL
Share this page

Why Flatten PDF Forms with cURL?

The pdfRest Flatten Forms API Tool is designed for users who need to convert interactive PDF forms into non-interactive, flat documents. This process is known as "flattening" and it ensures that the form data is displayed as part of the PDF content, preventing any further modifications. This tutorial will guide you through the process of sending an API call to the Flatten Forms endpoint using cURL, a powerful and versatile command-line tool used for transferring data with URLs.

An organization might need to archive submitted forms in a non-editable format for compliance purposes. After collecting data through interactive forms, the organization can use the Flatten Forms API to create a final version of the document that preserves the entered data in a format that can be easily shared, printed, or archived without the risk of further alterations.

Flatten PDF Forms with cURL Code Example

curl -X POST "https://api.pdfrest.com/flattened-forms-pdf" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
  -F "file=@/path/to/file" \
  -F "output=example_out"

Reference: pdf-rest-api-samples on GitHub

Breaking Down the Code

Let's break down the provided cURL command to understand how it works:

-X POST

This specifies the HTTP method for the request, which is POST in this case, indicating that we are sending data to the server to create or update a resource.

"https://api.pdfrest.com/flattened-forms-pdf"

This is the URL of the API endpoint that will process the flattening of the PDF form.

-H "Accept: application/json"

This header tells the server that the client expects a response in JSON format.

-H "Content-Type: multipart/form-data"

This header indicates that the body of the request contains form data encoded as a multipart MIME message, which is necessary for file uploads.

-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

This header provides your unique API key for authentication with the pdfRest API service.

-F "file=@/path/to/file"

The '-F' flag is used to specify each field that will be sent as part of the 'multipart/form-data'. Here, 'file' is the field name and '@/path/to/file' is the file path to the PDF that needs to be flattened.

-F "output=example_out"

Another field is specified using the '-F' flag. 'output' is the field name, and 'example_out' is the desired name for the output file after the PDF has been flattened.

Beyond the Tutorial

By following the steps outlined above, you have learned how to use cURL to make a request to the pdfRest Flatten Forms API, which will process an interactive PDF form and return a flattened version. This is particularly useful for preserving the integrity of form data and preparing documents for distribution or archival.

To explore more capabilities of the pdfRest API, you are encouraged to demo all of the pdfRest API Tools in the API Lab. For further information and to deepen your understanding, refer to the API Reference Guide.

Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at pdf-rest-api-samples on GitHub.

Generate a self-service API Key now!

Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.

Compare Plans
Contact Us