How to save HTML to image

As I discussed in How to embed matplotlib figure in html, sometime the return from different third-party tools are HTML. In order to merge different analysis into one, I use image as a media.

How to covert html to image?

  1. Install wkhtmltopdf,
  2. Install python package, imgkit
sudo apt-get install wkhtmltopdf
pip install imgkit

Then you can save HTML to image

import imgkit

imgkit.from_url('http://google.com', 'out.jpg')
imgkit.from_file('test.html', 'out.jpg')

Here is an example to show merged image of backtrader figure report and quantstats html report

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s