html2canvas,jsPDF - "法律信函"的页面规模/大小。 PDF页面?

时间:2015-09-23 06:51:49

标签: javascript html5 canvas jspdf html2canvas

我使用整个document.body创建PDF,将其转换为画布并将其传递给jsPDF。但图像/画布太宽。我想为页面缩放它,但jsPDF没有像素大小作为度量。

选项包括:ptmmcm。我该如何正确调整尺寸?如果需要,我如何缩放图像?

我应该使用addImage函数来缩放,还是使用canvas.getContect(" 2d")并绘制到新画布来缩放?

html2canvas(
    document.body,
    {
        //When the canvas is created, our callback
        onrendered: function(canvas)
        {         
            //Create jsPDF with what measurements?
            var doc = new jsPDF('p', 'pt');

            /*
             * Put image on page. Are these measurements
             * in pts? How does that compare to pixels?
             *
             * Is the x/y (the 10, 10) the x and y in the image?
             * Or in the page where the image is printed?
             * 
             * Should I be using this to scale, or scale by
             * using canvas.getContect( "2d" ) and drawing on
             * to a new canvas?
             */
            doc.addImage(canvas, 'PNG', 10, 10, 1024, 1000);

            //Save
            doc.save('sample-file.pdf');
    }
});

0 个答案:

没有答案