How to Convert Microsoft Word to PDF with cURL

Learn how to use pdfRest Convert to PDF API Tool with cURL to transform Word documents into PDF files
Share this page

Why Convert Word to PDF with cURL?

The pdfRest Convert to PDF API Tool is a powerful resource that allows developers to easily convert various file formats into PDFs. This tutorial will guide you through the process of sending an API call to Convert to PDF using cURL, a versatile command-line tool used for transferring data with URLs. cURL is widely supported and can be used to interact with APIs in various programming environments, making it an excellent choice for automating the process of PDF conversion.

You might need to convert documents to PDF for a variety of reasons. For instance, a business might need to convert a batch of invoices or reports generated in different formats into a unified PDF format for archival, compliance, or easy distribution. Using the Convert to PDF API, this can be done programmatically, saving time and reducing the potential for human error associated with manual conversion.

Convert Word 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" \
  -F "output=example_out"

Reference to the code: pdfRest API Samples on GitHub.

Breaking Down the Code

This section will explain the components of the cURL command used to call the pdfRest Convert to PDF API:

-X POST

This specifies the HTTP method for the request, which is POST, indicating that data will be sent to the server.

"https://api.pdfrest.com/pdf"

This is the endpoint URL where the API call is being made to convert files to PDF.

-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"

The Api-Key is a placeholder for your actual API key provided by pdfRest, which is required for authentication.

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

This form field is used to attach the file to be converted. Replace /path/to/file with the actual file path on your system.

-F "output=example_out"

This form field specifies the name of the output PDF. The API will return the converted PDF with this name.

Beyond the Tutorial

In this tutorial, we've walked through how to make a multipart API call to the pdfRest Convert to PDF API using cURL. By following the steps outlined, you can automate the process of converting files to PDF format. This can be incredibly useful for integrating PDF conversion into your workflow or application.

To explore more capabilities and demo all of the pdfRest API Tools, visit the API Lab. For a comprehensive understanding of the API's features and how to use them, refer to the API Reference Guide.

Note: This is an example of a multipart API call. For code samples using JSON payloads, you can find them at pdfRest 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.