How to Convert a PDF Document to a PNG Image Array using C/C++

Cloudmersive
1 min readSep 1, 2023

--

While PDF documents are often used for storing sensitive, high quality image files, PDF format still lacks many of the advantages that other popular image formats like PNG can offer.

Using the ready-to-run code below, we can easily convert our PDF documents to PNG arrays through a simple & free-to-use document conversion API. This service will quickly transition our PDF files (vector or raster) to lightweight PNG format.

To structure our API call, we can start by installing libcurl in our project:

libcurl/7.75.0

After that, we can include the below code examples in our file and provide a free-tier API key to authorize our requests:

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

Now we can easily ask our applications to make a simple & useful file conversion. Easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet