How to Convert a PDF file to PDF/A using C++
Committing PDF files to long-term storage typically entails converting those documents to specialist PDF/A format.
Using the below code, you can easily take care of those conversions freely at scale with a specialized API. This will allow you to convert your PDF documents to PDF/A-1b or PDF/A-2b depending on your specific needs (you can elect your conformance level by entering ‘1b’ or ‘2b’ respectively when you structure your API request).
First things first, install libcurl in your C/C++ project:
libcurl/7.75.0
After that you can structure your API call using the ready-to-run code examples below:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/edit/pdf/optimize/pdf-a");
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, "conformanceLevel: <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);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);
You can now make up to 800 API calls per month (simply provide a free-tier Cloudmersive API key in the authorization header).