This article will guide you through the process of converting various files (Doc, Excel, images, etc.) to a PDF file using the ConvertAPI and PSPDFKit API. We’ll start with ConvertAPI; first, create an account here and explore both free and paid plans.
ConvertAPI Configuration:
After creating your account check the available free and paid plans to choose the one that suits your needs. Then refer to the API documentation here for details on converting files to different formats. In our examples we will use our REST API task
In this example, we’ll focus on converting a Word file to a PDF file with CURL code. To configure the conversion, follow these steps:
- Get your secret key from your account
- Obtain a local Word file and note its file path.
- Use the following configuration in the REST API task
URL:
https://v2.convertapi.com/convert/doc/to/pdf?Secret=Your_secret_key
Body :
File=@C:\yourFilePath\Downloads\wordExample.docx
StoreFile=true
Save the resulting JSON, which contains the PDF file URL, in a variable. Filter the response URL using the JSON filter expression: $.Files[*].Url
Now, use a separate REST API task and input the URL variable as follows
Save the response to a local path with the .pdf extension
Finally, run the package, and you should find a new PDF file on your machine
PSPDFKit API Configuration:
Now, let’s explore PSPDFKit API. Create a new account here and review the free and paid plans, similar to the ConvertAPI.
Save your API key, as you’ll need it for your request.
For this example, we’ll use one REST API task with the following configuration
URL
https://api.pspdfkit.com/build
Body (it changes depending on the local file you want to use):
document=@C:\Users\DELL\Downloads\wordExample.docx
instructions={"parts": [{ "file": "document"}]}
Header:
Authorization: Bearer Your_API_key
Save the response in a file, ensuring ‘Treat response as binary’ is checked, and select a valid local path.
You will now obtain a new PDF file through PSPDFKit API