How to Convert an HTML String to PDF using Python

Hyperlinks aren’t the only way to share & present how a web page looks. By converting HTML to PDF format, you can generate fully rendered web pages in an easily shareable/transferrable way. Our HTML to PDF API makes it possible to include that operation as a service in your app — and it’s free to use. Below, we’ll walk through how you can take advantage of this API using Python code examples to structure your API call.

Start by running the below command to install the Python SDK:

After that, add in the imports:

Lastly, authenticate your API key (you can get one by registering a free account on our website) and call the function:

That’s all you need — easy as pie. You can also take advantage of this API using different code examples on the Cloudmersive API Console, or as a Connector Action in MS Power Automate/Logic Apps.



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

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