HTML2canvas generates Blurry images

前端 未结 8 1431
庸人自扰
庸人自扰 2020-12-01 06:45

I am using jsPDF and it uses html2canvas to generate an image from some html element and insert on the .pdf file. But there is a problem on html2canvas, it generates blurry

相关标签:
8条回答
  • 2020-12-01 07:25

    you can use scale options in html2canvas.

    In the latest release, v1.0.0-alpha.1, you can use the scale option to increase the resolution (scale: 2 will double the resolution from the default 96dpi).

    // Create a canvas with double-resolution.
    html2canvas(element, {
        scale: 2,
        onrendered: myRenderFunction
    });
    // Create a canvas with 144 dpi (1.5x resolution).
    html2canvas(element, {
        dpi: 144,
        onrendered: myRenderFunction
    });
    
    0 讨论(0)
  • 2020-12-01 07:25

    Try the Canvas2Image library, it gives a better quality image at least for me div to image (fiddle).

        html2canvas($("#widget"), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                Canvas2Image.saveAsPNG(canvas);  // Convert and download as image with a prmompt. 
            }
        });
    

    Good luck!

    0 讨论(0)
提交回复
热议问题