Using a REST API to convert DOCX files is easy
PDF Gen Pro makes it incredibly easy to convert any office file, especially word files, to a PDF file format. This first step it to generate a client id and client secret in the API Credentials section of the app. Once that is done, a access token needs to be generated. This is done by calling the auth endpoint.
curl /auth/token \
--request POST \
--header 'Content-Type: application/json' \
--data '{
"clientId": "YOUR_CLIENT_ID",
"clientSecret": "YOUR_CLIENT_SECRET"
}'
An access token is sent back and this is used for each subsequent call.
{
"accessToken": "YOUR_SECRET_TOKEN",
"expiresIn": 3600,
"tokenType": "Bearer"
}
To convert the word docx file, use the conversion/word2pdf endpoint. See below:
curl '/api/conversion/word2pdf?download=false' \
--request POST \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
--form 'file='
The return response defaults to a JSON response unless download is set to true. In that case, a downloadable file is returned. The outline of the JSON is shown below:
{
"response": null,
"meta": {
"name": null,
"displayName": null,
"encoding": null,
"contentType": null,
"publicId": null
}
}