Using the below code, we can take advantage of a free API that allows us to customize the paper size of our PDF documents.
We can enter our selection (A7 — A0; smallest to largest) along with our file in our request, and we’ll receive the encoding for our resized file in return.
To begin structuring our API call, let’s first install libcurl in our project:
Then let’s go ahead and copy the below code into our file and provide a free-tier API key to authorize our requests (this allows up to 800 API calls per month with no additional commitment):
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/edit/pdf/resize");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "paperSize: <string>");
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
That’s all there is to it — no more code required!