How to Convert PDF to Word with cURL

Learn how to convert a PDF to a Word document using cURL to call the PDF to Word API Pro Tool from pdfRest.
Share this page

Why Use PDF to Word with cURL?

The pdfRest PDF to Word API Tool is a powerful resource for developers looking to automate the conversion of PDF documents into editable Word files. This tool simplifies the process by providing a straightforward API that can be accessed using cURL, a command-line tool for making network requests. This tutorial will show how to send an API call to the PDF to Word endpoint using cURL, enabling you to integrate PDF to Word conversion into your applications seamlessly.

In a business scenario, you might need to convert a batch of reports or contracts saved as PDFs into Word documents for further editing and review. Using the PDF to Word API, you can automate this process, saving time and reducing the risk of manual errors. This is particularly useful for organizations that handle a large volume of documents and need to maintain consistency and efficiency in their workflows.

PDF to Word with cURL Code Example

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

The provided code is sourced from the pdfRest API samples on GitHub.

Breaking Down the Code

The provided cURL command is used to make a POST request to the PDF to Word conversion endpoint. Let's break down each part of the command:

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

This specifies that you are making a POST request to the endpoint that handles PDF to Word conversions.

-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 request body will be sent as multipart/form-data, which is necessary for uploading files.

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

Here you replace 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with your actual API key provided by pdfRest. This key is used to authenticate your request.

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

This is the form field where you specify the file path for the PDF you want to convert. The '@' symbol is used to upload a file from your filesystem.

-F "output=example_out"

This form field specifies the desired output filename for the converted Word document.

Beyond the Tutorial

In this tutorial, we've learned how to use cURL to make a POST request to the pdfRest PDF to Word API endpoint, including how to set headers for content type and authentication, and how to specify the input and output files for the conversion. This is a practical example of automating document conversion to streamline workflows.

To explore and demo all of the pdfRest API Tools, visit the API Lab. For further details on how to use 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 API samples with JSON payload.

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