How to Convert DOCX Documents to PNG Arrays using C/C++

Cloudmersive
1 min readJul 28, 2023

--

Whether you’re storing iterations of a DOCX draft or sharing an un-editable final draft with an external stakeholder, converting DOCX documents to PNG format is a great solution. Using the below code, you can build an API into your document processing applications that automatically converts DOCX files to PNG Arrays (one image per page), returning the resulting file encodings as strings.

Before copying in the ready-to-run C/C++ examples further down the page, start by installing libcurl in your project:

libcurl/7.75.0

Then incorporate the below 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/docx/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);

That’s all there is to it! You can authorize your requests with a free-tier API key and get up to 800 API calls per month (with no commitment upon reaching that limit — the total resets for the following month).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet