How to Split DOCX Files into Separate Documents (by Page) using C/C++
Thanks to the simplicity and accessibility of OpenXML file formatting, it’s easy to programmatically edit Office documents with relevant libraries and APIs. Using the below code, you can quickly and easily take advantage of an API that splits DOCX files into separate documents — one per page — returning a separate object for each.
You’ll just need to install libcurl in your C/C++ project first:
libcurl/7.75.0
And after that you can copy the ready-to-run code examples below into your file:
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/split/docx");
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, "returnDocumentContents: <boolean>");
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);
Now simply provide a free-tier API key to authorize your requests (these allow 800 API calls per month with no commitment), and you’re all set.