I'm using jspdf.js to create pdf from HTML 5 canvas. However, regardless of what the contents are and how big the canvas size is, the generated file size is always 32,874 KB, even when the canvas is completey empty. Why the file size is always the same? jsPDF version is 1.1.135. My code is like this:
var imgData = canvas.toDataURL("image/jpeg", 1.0);
var width = $("canvas").attr('width');
var height = $("canvas").attr('height');
var pdf = new jsPDF('p', 'pt', [width,height]);
pdf.addImage(imgData, 'JPEG', 0, 0, width, height);
pdf.save("download.pdf");
UPDATE: Full code:
$scope.rasterizePDF = function() {
if (!fabric.Canvas.supports('toDataURL')) {
alert('This browser doesn\'t provide means to serialize canvas to an image');
}
else {
var imgData = canvas.toDataURL("image/jpeg", 1.0);
var width = $("canvas").attr('width');
var height = $("canvas").attr('height');
var pdf = new jsPDF('p', 'pt', [width,height]);
pdf.addImage(imgData, 'JPEG', 0, 0, width, height);
pdf.save("download.pdf");
}
};