How to convert HTML to PDF in Salesforce Apex
1 min readFeb 16, 2020
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!