pythonhtmlvisualizationdpiaspose.words

Image clarity issue in HTML page


I have Matplotlib & Seaborn visualizations that need to be saved in HTML. Since there is no direct method to do so, I first saved the images in PNG & then converted them to HTML. This decreased the quality of my images.

My code:

import aspose.words as aw 
from PIL import Image

def pairplot_fun(eda_file, pairplot_inputs, pairplot_png, pairplot_html):
    pairplot_var=pairplot_inputs[0]
    sns.pairplot(eda_file, hue=pairplot_var, height=4);
    plt.savefig(pairplot_png) 
             
    doc = aw.Document()
    builder_pairplot = aw.DocumentBuilder(doc)
                    
    builder_pairplot.insert_image(pairplot_png)
    doc.save(pairplot_html, dpi=1200)

Specifying the 'dpi' this way isn't making any difference. How do I improve the clarity of my image saved in HTML format?


Solution

  • You can specify image resolution in Aspose.Words HtmlSaveOptions using HtmlSaveOptions.image_resolution property.

    doc = aw.Document("in.docx")
    options = aw.saving.HtmlSaveOptions()
    options.image_resolution = 1200
    doc.save("out.html", options)