The pdfRest Convert to PDF API Tool offers a straightforward and powerful way to convert various document formats, such as JPG image, into PDFs. By utilizing this API, developers can easily integrate PDF conversion capabilities into their applications, workflows, or services. This tutorial will guide you through the process of sending an API call to Convert to PDF using cURL, which is a versatile command-line tool used for making all sorts of HTTP requests.
Imagine you are working on an application that handles document management and you need to ensure that all documents are stored in a uniform format for consistency and ease of access. By using the Convert to PDF API, you can automatically convert incoming documents, such as JPGs, into PDFs. This is particularly useful in scenarios where documents need to be archived, shared across different platforms, or prepared for printing.
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.jpg" \ -F "output=example_out"
Reference: pdfRest cURL code example
The code snippet provided is a cURL command that makes a POST request to the pdfRest Convert to PDF API endpoint. Here's what each part of the command does:
-X POST
This specifies the HTTP method for the request, which is POST in this case, indicating that you are creating or updating a resource.
"https://api.pdfrest.com/pdf"
This is the URL of the API endpoint that handles the conversion 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 request body will be sent as multipart/form-data, which is necessary for uploading files.
-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
This header includes your API key, which is required for authentication with the pdfRest API.
-F "file=@/path/to/file.jpg"
The -F flag is used to specify each field that will be sent as part of the multipart request. In this case, it's the JPG that you want to convert, with the path to that file on your system.
-F "output=example_out"
This field specifies the name of the output file after conversion.
In this tutorial, we've covered how to use cURL to call the pdfRest Convert to PDF API to convert a JPG to PDF format. By following the steps above, you can integrate PDF conversion into your applications or automate document processing tasks. To explore and demo all of the pdfRest 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 examples.
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.