How to Convert Multiple Common Document Types to PNG using C/C++
Boasting lossless compression and transparency features, PNG is an extremely popular and widely supported image format. Using the below code, you can take advantage of an API that converts over 100 image formats — as well as ALL major Office document formats — to PNG in a single request.
The underlying service will automatically detect the input file format and return a PNG URL. If you’re converting a document with multiple pages/worksheets/slides, you’ll get one image for each.
To structure your API call, start by installing Libcurl in your C/C++ project:
libcurl/7.75.0
After that, copy the below code examples to make your request:
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/autodetect/to/png");
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, "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);