How to Set a PDF Document’s Metadata using C/C++

Cloudmersive
1 min readAug 28, 2023

--

Did you know it’s possible (and extremely easy) to write metadata to a PDF document? It’s easy with a free API, that is. Using the below code, you can take advantage of a free API service that allows you to write custom metadata to any given PDF document, defining the title, keywords, subject, author/creator, page count, and more.

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

libcurl/7.75.0

And after that you can structure your request using the below ready-to-run C/C++ code 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/edit/pdf/set-metadata");
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: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "InputFileBytes=%3Cbyte%3E&Successful=%3Cboolean%3E&Title=%3Cstring%3E&Keywords=%3Cstring%3E&Subject=%3Cstring%3E&Author=%3Cstring%3E&Creator=%3Cstring%3E&DateModified=%3CdateTime%3E&DateCreated=%3CdateTime%3E&PageCount=%3Cinteger%3E";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);

You can now authorize your requests with a free-tier Cloudmersive API key, which will allow you to make up to 800 API calls per month with no additional commitment (this total resets the following month once reached).

Yep, it’s that easy to take control of your PDF file processing workflows!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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