html2canvas-AngularJS模态的第二页在中间被切断

时间:2018-12-16 07:08:38

标签: javascript html2canvas

我使用此功能来制作视图的屏幕截图并将其下载为pdf。 我有一个问题,我的第二个pdf会由于任何原因而被截断- onePageCanvas.toDataURL(“ image / png”,0.92); 仍然具有截断的内容。 我已经尝试了很多,但是没有成功。有谁知道我要做什么才能完全打印所有页面的所有内容?

function makePDF(container, pdfName) {
        var quotes = container;
        html2canvas(quotes, {
            onrendered: function(canvas) {

            var pdf = new jsPDF('p', 'pt', 'letter');

            var loop = Math.ceil(quotes.clientHeight/980);
            for (var i = 0; i <= loop; i++) {
                var srcImg  = canvas;
                var sX      = 0;
                var sY      = 980*i;
                var sWidth  = 900;
                var sHeight = 980;
                var dX      = 0;
                var dY      = 0;
                var dWidth  = 900;
                var dHeight = 980;

                window.onePageCanvas = document.createElement("canvas");
                onePageCanvas.setAttribute('width', 900);
                onePageCanvas.setAttribute('height', 980);
                var ctx = onePageCanvas.getContext('2d');
                ctx.drawImage(srcImg,sX,sY,sWidth,sHeight,dX,dY,dWidth,dHeight);
                var canvasDataURL = onePageCanvas.toDataURL("image/png", 0.92);

                var width         = onePageCanvas.width;
                var height        = onePageCanvas.clientHeight;

                var pageHeight = pdf.internal.pageSize.height;

                if (i > 0) {
                    pdf.addPage(612, pageHeight);
                }
                pdf.setPage(i+1);
                pdf.addImage(canvasDataURL, 'PNG', 20, 40, (width*0.62), (height*0.62));

            }
            var today = new Date();
            pdf.save(pdfName + '_' + today.getFullYear() + (today.getMonth()+1) + today.getDate());
        }
      });
    }

0 个答案:

没有答案