How to Restrict PDF with cURL

Learn how to apply PDF file restrictions with Restrict PDF API Tool from pdfRest with cURL
Share this page

Why Use Restrict PDF with cURL?

The pdfRest Restrict PDF API Tool is a powerful resource for developers who need to secure their PDF documents by restricting access and permissions. This tutorial will guide you through the process of making an API call to the Restrict PDF endpoint using cURL, a versatile command-line tool used for transferring data with URLs. By leveraging this API, you can programmatically apply restrictions to your PDF files, enhancing their security and ensuring that only authorized users can perform certain actions.

Imagine you are distributing a PDF document containing sensitive information. You might want to restrict the ability to print, copy, or edit the content to prevent unauthorized sharing or alterations. The Restrict PDF API allows you to set a permissions password on your PDF file, ensuring that only users with the correct password can change the document's restrictions. This is particularly useful for businesses that handle confidential reports, legal documents, or proprietary research papers.

Restrict PDF with cURL Code Example

curl -X POST "https://api.pdfrest.com/restricted-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" \
  -F "new_permissions_password=password"

Refer to the source code for this example.

Breaking Down the Code

This cURL command is used to make a POST request to the Restrict PDF endpoint:

-X POST "https://api.pdfrest.com/restricted-pdf"

The -X POST flag specifies that we are making a POST request, which is required for creating or updating resources.

Headers are set to accept JSON responses and to indicate the content type:

-H "Accept: application/json"
-H "Content-Type: multipart/form-data"

The API key is provided for authentication:

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

The file to be restricted is attached:

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

The -F flag is used for multipart/form-data content, which allows you to upload files. Replace /path/to/file with the actual file path.

The desired output filename is specified:

-F "output=example_out"

And finally, the new permissions password is set:

-F "new_permissions_password=password"

Replace password with the password you want to use to restrict the PDF.

Beyond the Tutorial

By following the steps above, you have learned how to use cURL to call the Restrict PDF API, which allows you to apply restrictions to a PDF document. This is just one of the many features offered by the pdfRest API. To explore more possibilities and to demo all of the pdfRest API Tools, visit the API Lab. For detailed information on all available endpoints and parameters, refer to the API Reference Guide.

Note: This is an example of a multipart API call. Code samples using JSON payloads can be found in our GitHub repo.

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