here is my code to convert a web page to pdf through html2canvas.js and jspdf.js
pdf () {
let that = this
this.loading = false
html2Canvas(this.$refs.pictureData).then(canvas => {
var contentWidth = canvas.width;
var contentHeight = canvas.height;
//pdfhtmlcanvas;
var pageHeight = contentWidth / 592.28 * 841.89;
//pdfhtml
var leftHeight = contentHeight;
//
var position = 0;
//a4[595.28,841.89]htmlcanvaspdf
var imgWidth = 595.28;
var imgHeight = 592.28/contentWidth * contentHeight;
var pageData = canvas.toDataURL("image/jpeg", 1.0);
// -----------------
console.log("")
console.log(typeof pageData)
// -----------------
var pdf = new jsPDF("", "pt", "a4");
//htmlpdf(841.89)
//pdf
if (leftHeight < pageHeight) {
pdf.addImage(pageData, "JPEG", 0, 0, imgWidth, imgHeight );
} else {
while(leftHeight > 0) {
pdf.addImage(pageData, "JPEG", 0, position, imgWidth, imgHeight)
leftHeight -= pageHeight;
position -= 841.89;
//
if(leftHeight > 0) {
pdf.addPage();
}
}
}
pdf.save("content.pdf");
this.loading = true
});