How to convert a PDF to PNG array in Salesforce Apex

Today’s article is going to tackle how to perform file format conversion between PDFs and PNG arrays. Through the use of one of our handy APIs, this is going to be a snap.

First step, download our Document/Conversion client here. Then extract its contents into your Apex project’s folder.

We shall proceed by invoking the convertDocumentPdfToPngArray function:

SwagConvertDocumentApi api = new SwagConvertDocumentApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'inputFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersSwagPdfToPngResult result = api.convertDocumentPdfToPngArray(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

That’s it! We will be returned a list of URLs that correspond to each PNG image in the array.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store