pptxHow to Convert PowerPoint PPTX Files to Plain Text using C/C++

Cloudmersive
2 min readJul 28, 2023

--

Applications with rich formatting capabilities like PowerPoint (and most of the Office file formats) make it slightly difficult to copy and paste text for other use cases. By converting PPTX to text directly, we can extract plain, unformatted text from each slide of a PPTX document and start fresh when we use that text elsewhere across our various projects.

The below code makes that conversion process easy. You can simply copy & paste from ready-to-run C/C++ code examples to incorporate a free PPTX to Text conversion service into your applications, and use the service up to 800 times per month free (with a free-tier Cloudmersive API key).

First things first, install libcurl in your project:

libcurl/7.75.0

Then copy the below code into your file and authorize with your free-tier API key:

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/pptx/to/txt");
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 — no more code required. You’ll receive a simple plain-text string output, which can be written to a variety of different files after the operation is complete.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet