How to Convert Microsoft Excel to PDF with cURL

Learn how to convert Excel spreadsheets to PDF files with pdfRest Convert to PDF API Tool using cURL
Share this page

Why Convert Excel to PDF with cURL?

The pdfRest Convert to PDF API Tool offers a simple yet powerful way to programmatically convert various file formats into PDFs. This tutorial will guide you through the process of using cURL, a command-line tool for making HTTP requests, to send an API call to the Convert to PDF endpoint provided by pdfRest. Utilizing cURL for API interactions is common due to its availability on most Unix-based systems, including Linux and macOS, and its ability to handle complex HTTP requests with ease.

A business might need to convert batches of Excel invoices or reports into PDFs for archival purposes. The Convert to PDF API makes this process seamless and can be integrated into automated workflows, saving time and ensuring consistency in document formats across an organization.

Convert Excel to PDF with cURL Code Example

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

Reference: pdfRest cURL code example

Breaking Down the Code

The provided cURL command is structured to send a POST request to the pdfRest Convert to PDF API. Here's what each part of the command does:

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

This specifies that the HTTP request is a POST method, which is required to send data to the server for the conversion process.

-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 data being sent in the request is in multipart form-data format, which is necessary for uploading files.

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

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

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

The -F flag is used to specify each field that will be sent with the request. In this case, it's the file that you want to convert. The "@" symbol tells cURL to get the file data from the specified path on your filesystem.

-F "output=example_out"

This field specifies the name of the output file (without the .pdf extension) that will be generated by the API.

Beyond the Tutorial

By following the tutorial above, you've learned how to make a multipart API call to the pdfRest Convert to PDF endpoint using cURL. This enables you to integrate Excel to PDF conversion into your applications and scripts, automating the process and improving efficiency. To further explore the capabilities of pdfRest and demo all of the API Tools, visit the API Lab. For more detailed information on the API, 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 pdfRest JSON payload code examples.

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