How to convert Excel XLSX to PDF in Salesforce Apex

Cloudmersive
1 min readFeb 16, 2020

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.

--

--

Cloudmersive

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