How to convert HTML to PDF in Salesforce Apex

The goal of today’s post is to demonstrate an easy method for conversion between HTML and PDF. Get ready to save a lot of time!

Let’s start off with downloading the Cloudmersive API client and then dragging the /client folder into our project.

Rolling right along, we can now proceed to call convertWebHtmlToPdf, as you see here:

SwagConvertWebApi api = new SwagConvertWebApi();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>{'input' => SwagHtmlToPdfRequest.getExample()};try {// cross your fingersBlob result = api.convertWebHtmlToPdf(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And it’s just that easy. If you want more like this simple approach, I encourage you to peruse our other API functions, which offer hundreds of other fantastic solutions like this!

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