[Python] HTML to image html2image doesn't save files

Discussão em 'Python' iniciado por Stack, Fevereiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    My main goal is to save pandas dataframe with html and scc styles as image. I'm having problems imgkit so I tried html2image. And it worked for me. But a few days later the same code doesn't do anything. No error either. I even created a new venv with html2imageonly and ran simple code from other examples

    from html2image import Html2Image
    hti = Html2Image()

    html = '<h1> A title </h1> Some text.'
    css = 'body {background: red;}'

    # screenshot an HTML string (css is optional)
    hti.screenshot(html_str=html, css_str=css, save_as='page.png')


    However, it doesn't save anything, and just finishes programm with "Process finished with exit code 0". I also tried looking in Temp\html2image and only found file from when the pachage was working. Tried downgrading to 2.0.4, still no results.

    First version of code looked like this

    html = s.set_td_classes(cell_color).to_html()
    root = get_project_root()
    image_path = pathlib.Path(root, 'resources')
    hti = Html2Image(output_path=image_path)
    image_name = 'top_5_table.png'
    hti.screenshot(html_str=html, css_str=CSS, save_as=image_name)


    And it stopped working. I've tried removing css_str, changing output_path, still no result

    I'm trying all of the versions, 1.1.3 and 2.0.3 at least save html files, not png, and to Temp\html2image

    Continue reading...

Compartilhe esta Página