How to Merge HTML Files using C/C++
When we convert Office documents (and other common formats) to HTML, we’re usually trying to make sure that document is viewable on the widest range of devices possible. We can make HTML files even more accessible by programmatically combining our content into multi-page documents in our file processing workflows.
Using the below code, we can easily combine 10+ HTML documents together in a single free-to-use API call. All we need to do is install the SDK, copy code examples into our file, and we’re good to go.
Let’s start by installing Libcurl in our project:
libcurl/7.75.0
Then let’s copy the below code into our file & supply a free-tier API key to authorize our 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/merge/html/multi");
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, "inputFile1");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile2");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile3");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile4");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile5");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile6");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile7");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile8");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile9");
curl_mime_filedata(part, "/path/to/file");
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile10");
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);
We can get our free-tier API key on the Cloudmersive website (this allows up to 800 API calls per month with no additional commitment).