How to convert Excel XLSX to PDF in Salesforce Apex

I’m not going to bore you today with the details of converting between file formats. Instead I’m going to show you an easy shortcut so you can start converting files almost immediately. Let’s dive in.

Our task begins with installing our client. This can be accomplished simply enough by downloading it here and copying the /client folder into your project folder.

Let’s proceed to call convertDocumentXlsxToPdf, as you can see below:

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 fingersBlob result = api.convertDocumentXlsxToPdf(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And our XLSX is now a PDF. Not bad.

Image for post
Image for post

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