How to Convert HTML to PDF in Power Automate
HTML is chiefly designed to be interpreted by web browsers, but that’s certainly not the only way we can display HTML content.
To preserve a consistent, static iteration of our HTML content, we can convert HTML documents directly to PDF format. This conversion requires a PDF reader capable of translating HTML & CSS elements into the fixed layout elements characteristic of PDF file structure.
Methods for Converting HTML to PDF
If we’re interested in making HTML to PDF conversions, we can either find a PDF reader application to handle our conversion manually, or we can use programmatic services (i.e., a programming library) to automate our conversion.
Both options come with noteworthy challenges depending on the scale of our use-case and the extent of our technical expertise. The former option is a bit inefficient when we’re dealing with a larger volume of documents, and the latter option can be cumbersome and overcomplicated if we aren’t fluent in the necessary programming languages and libraries required to complete the task.
Convert HTML to PDF in Power Automate
Thankfully, Power Automate offers a happy medium. We can automate HTML to PDF conversions in Power Automate without writing any code — and we can leverage a single, fully-realized service to make the conversion on our behalf.
In this walkthrough, we’ll learn how to make HTML to PDF conversions using the Cloudmersive Document Conversion connector. In my example, I’ll convert three HTML files from a SharePoint folder to PDF.
In this example context, we’ll build a manually triggered instant cloud flow. This will give us full control over our data & simplify the testing process.
We’ll begin by using the List folder action from the SharePoint connector to retrieve file information from each HTML document in our target folder. This information includes the file identifiers and file names, which we’ll use to retrieve our HTML file contents and eventually name our resulting PDF documents respectively.
Next, we’ll use a Get file content action to retrieve our HTML file contents using the file identifiers (Id) brought in by our List folder action. Power Automate will wrap this action in a For each control because the Id value is an array.
We’ll now add our HTML to PDF conversion action within the For each control.
To find the action we need, we’ll first search for Cloudmersive connectors and scroll down until we locate the Cloudmersive Document Conversion connector with the green logo.
We’ll click “See more” to view the full actions list, and from there, we’ll CTRL+F search for an action called Convert HTML document file to PDF document.
We’ll notice that these actions carry a “Premium” tag. Cloudmersive connectors are third-party, which means we’ll need a premium Power Automate license to access them. As long as we have a premium license, however, we can use them for free with a free Cloudmersive API key. Free API keys allow a limit of 800 API calls per month with zero additional commitments.
Once we’ve created our connection, we’ll fill each of this action’s two parameters using our HTML file contents and file names respectively.
In our final step, we’ll add a Create file action to write our OutputContent PDF bytes to a series of new documents. We’ll use the original HTML file names (with added PDF extensions) to name the new PDF documents.
After we save and test our flow, we’ll find our new PDF documents in the folder we specified. In my example, I chose to save my PDF documents in the same folder as the original HTML files.
We’ll notice that my files contain both the .html and .pdf extensions; if we want to avoid this, we’ll need to use the Slice function in Power Automate to remove the original extension by character index.
And that’s all there is to it! We’ll find advanced HTML5 and JavaScript features supported by this conversion service. We can now easily render our HTML files as PDF documents through a quick Power Automate flow.