How to Convert a PDF File to PDF/A in C/C++

Cloudmersive
2 min readMay 7, 2021

--

While the PDF format is ideal for ensuring secure sharing of business documents, it may not always be fully compatible with various platforms and systems. When this incompatibility occurs, it can cause degradation of your original message or data. In this brief tutorial, we will demonstrate how you can avoid this potential issue by utilizing the following API in C/C++ to convert a PDF file to the universally standardized PDF/A format.

Our first step is to install libcurl in our C/C++ project:

libcurl/7.75.0

Next, we can call the conversion function with the following code:

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

To ensure the operation runs successfully, be sure to include the valid PDF file path and your API key. If you need to retrieve an API key, you can do so by registering for a free account on the Cloudmersive website; this provides access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet