jsPDF HTML2Canvas + HTML + Images切断了捕获

时间:2017-06-28 08:06:22

标签: javascript jquery jspdf html2canvas

使用画布捕捉时,有没有办法调整宽度和高度?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script>
    function demoFromHTML() {
        var pdf = new jsPDF('p', 'pt', 'letter');
        var options = {
            background: '#fff'
        };
        html2canvas(jQuery("#pdf"), {
            onrendered: function(canvas) {         
                var imgData = canvas.toDataURL(
                    'image/png');              
                var doc = new jsPDF('p', 'mm');
                doc.addImage(imgData, 'PNG', 0, 0);
                doc.save('results.pdf');
            }
        });
    }
</script>

1 个答案:

答案 0 :(得分:0)

使用配置选项:https://html2canvas.hertzen.com/configuration

width >>默认值:元素宽度-画布的宽度

height >> DEFAULT:元素高度-画布的高度