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

Cloudmersive
2 min readAug 28, 2023

--

Retrieving a PDF document’s metadata makes it easier for us to carry out subsequent programmatic operations with that document.

Thankfully, we can easily accomplish this by using the below ready-to-run C/C++ code examples to call a free PDF metadata retrieval API. This will return a list of important information stored in any PDF document including its author, subject, creator, modification dates, page count, and much more.

Before we include the below code examples in our file, let’s first install Libcurl in our project:

libcurl/7.75.0

Then let’s go ahead and copy & paste the below code to structure our request, and let’s make sure to supply a free-tier API key in the authorization header:

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/get-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: 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);

We can now make up to 800 requests per month for free with zero additional commitment (the total of API requests will reset the following month when that limit is reached).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet