How to save HTML to image

Posted on November 27, 2022 at 05:40 PM


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