How to print full page using Html2Canvas and JsPDF

时间:2017-08-04 13:04:32

标签: javascript jspdf html2canvas html2pdf

I wanted to save full page as pdf using html2canvas and JsPDF. none of the methods I ever tried seems to work.

html2canvas(document.body, {
        allowTaint: true,
        onrendered: function(canvas) {
            var image = canvas.toDataURL('image/png');

            var pdf = new jsPDF();
            pdf.addImage(image, 'JPEG', 0, 0);
            pdf.save('invoice.pdf');
        }
    });

Currently this prints only the viewport

How to print full page/ container. or any other better alternatives?

1 个答案:

答案 0 :(得分:0)

使用打印介质查询

@media print {
      body, html {
          width: 100%;
          margin-top: 0%;
          display: block;
          height: 100%;
      }
}