How to Convert HTML to PDF in Salesforce Apex

SwagConvertDocumentApi api = new SwagConvertDocumentApi();
SwagClient client = api.getClient();
// Configure API key authorization: Apikey
ApiKeyAuth 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'),
'includeBackgroundGraphics' => true,
'scaleFactor' => 56
};
try {
// cross your fingers
Blob result = api.convertDocumentHtmlToPdf(params);
System.debug(result);
} catch (Swagger.ApiException e) {
// ...handle your exceptions
}

--

--

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
Cloudmersive

Cloudmersive

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