I'm creating a PDF by using the entire document.body
, turning it into a canvas and passing that to jsPDF
. But the image/canvas is too wide. I want to scale it for the page, but jsPDF
doesn't have pixel size as a measurement.
The options are: pt
, mm
, cm
. How do I properly size for that? And how do I scale my image if needed?
Should I be using the addImage
function to scale, or scale by using canvas.getContect( "2d" ) and drawing on to 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');
}
});