Html2canvas, jsPDF - how is the page size / page size for a PDF legal page?

I create a PDF using the whole document.body, turning it into a canvas and transferring it to jsPDF. But the image / canvas is too wide. I want to scale it for a page, but jsPDFdoes not have a pixel size as a dimension.

Possible values are pt, mm, cm. How can I choose the right size? And how do I scale the image if necessary?

Should I use a function addImageto scale or scale with canvas.getContect ("2d") and draw on a new canvas?

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');
    }
});
+4

Source: https://habr.com/ru/post/1608625/


All Articles