How to Digitally Sign PDF Files with cURL

Learn how to apply digital signatures to PDF files using cURL with pdfRest's Sign PDF API Tool.
Share this page

Why Digitally Sign PDFs with cURL?

The pdfRest Sign PDF API Tool is a powerful resource that allows users to digitally sign PDF documents programmatically. This tutorial will guide you through the process of sending an API call to the Sign PDF endpoint using cURL, a command-line tool for transferring data with URLs. By leveraging cURL, users can automate the signing process, integrate it into scripts, and handle multiple files efficiently.

Businesses and individuals often need to sign PDF documents for contracts, agreements, or official communications. For instance, a company might need to sign hundreds of contracts with clients or partners. Automating this process with the Sign PDF API can save time and reduce errors, ensuring that all documents are signed consistently and securely.

Sign PDF with cURL Code Example

SIGNATURE_CONFIG='{"type": "new","name": "esignature","logo_opacity": "0.25","location": {"bottom_left": { "x": "0", "y": "0" },"top_right": { "x": "216", "y": "72" },"page": 1},"display": {"include_distinguished_name": "true","include_datetime": "true","contact": "My contact info","location": "My location","name": "John Doe","reason": "My reason for signing"}}'

curl -X POST "https://api.pdfrest.com/signed-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 "pfx_credential_file=@/path/to/file" \
  -F "pfx_passphrase_file=@/path/to/file" \
  -F "logo_file=@/path/to/file" \
  -F "signature_configuration=$SIGNATURE_CONFIG" \
  -F "output=example_out"

Source: GitHub Repository

Breaking Down the Code

The code begins by defining a SIGNATURE_CONFIG variable, which is a JSON string specifying the signature's properties. It includes details such as the signature type, name, logo opacity, location on the page, and display options like the signer's name and reason for signing.

SIGNATURE_CONFIG='{"type": "new","name": "esignature","logo_opacity": "0.25","location": {"bottom_left": { "x": "0", "y": "0" },"top_right": { "x": "216", "y": "72" },"page": 1},"display": {"include_distinguished_name": "true","include_datetime": "true","contact": "My contact info","location": "My location","name": "John Doe","reason": "My reason for signing"}}'

The curl command is used to make a POST request to the https://api.pdfrest.com/signed-pdf endpoint. The -X POST option specifies the HTTP method, while the -H flags set the request headers. The Accept header indicates that the response should be in JSON format, and the Content-Type header specifies that the request body is multipart/form-data.

curl -X POST "https://api.pdfrest.com/signed-pdf" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

The -F flags are used to specify the form data being sent in the request. Each -F option corresponds to a different part of the request:

  • file=@/path/to/file: The PDF file to be signed.
  • pfx_credential_file=@/path/to/file: The PFX credential file for signing.
  • pfx_passphrase_file=@/path/to/file: The passphrase for the PFX file.
  • logo_file=@/path/to/file: The logo file to be used in the signature.
  • signature_configuration=$SIGNATURE_CONFIG: The signature configuration JSON defined earlier.
  • output=example_out: The name of the output file.

Beyond the Tutorial

In this tutorial, you learned how to use cURL to send a request to the pdfRest Sign PDF API, allowing you to digitally sign PDF documents programmatically. This process can be integrated into larger workflows to automate document signing.

To explore more, try out all the pdfRest API Tools in the API Lab. For more detailed information, refer to the API Reference Guide. Additionally, note that this example uses a multipart API call, and code samples using JSON payloads can be found here.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.