lsxHow to Convert Excel XSLX to PDF using C/C++

Cloudmersive
1 min readJul 26, 2023

--

Excel allows us to export individual spreadsheets as PDF files with relative ease, but we need access to specialized file conversion libraries if we want to perform that same task programmatically at scale (saving time and resources). Thankfully, using the below C/C++ code, you can take advantage of a free Excel to PDF conversion API that generates PDF file encoding strings based on file paths.

You’ll first need to install libcurl in your project:

libcurl/7.75.0

Then you can structure your request using the below examples:

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/xlsx/to/pdf");
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);

And you can complete your request by providing an API key in the authorization header. You can get a free-tier API key on the Cloudmersive website by registering a free account — this allows a limit of 800 API calls per month (each request above uses 1 API call).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet