kun 19/10/16 9:13

This commit is contained in:
沈学坤
2019-10-16 09:12:43 +08:00
parent baca798863
commit 8cb91aae99
2 changed files with 33 additions and 33 deletions

View File

@@ -7,44 +7,44 @@ export default {
allowTaint: true,
scale: 2 // 提升画面质量,但是会增加文件大小
}).then(function (canvas) {
var contentWidth = canvas.width
var contentHeight = canvas.height
// var contentWidth = canvas.width
// var contentHeight = canvas.height
var pageData = canvas.toDataURL('image/jpeg', 0.4)
// var pageData = canvas.toDataURL('image/jpeg', 0.4)
var pdfWidth = ((contentWidth + 10) / 2) * 0.75
var pdfHeight = ((contentHeight + 200) / 2) * 0.75 // 500为底部留白
// var pdfWidth = ((contentWidth + 10) / 2) * 0.75
// var pdfHeight = ((contentHeight + 200) / 2) * 0.75 // 500为底部留白
var imgWidth = pdfWidth
var imgHeight = (contentHeight / 2) * 0.75 // 内容图片这里不需要留白的距离
// var imgWidth = pdfWidth
// var imgHeight = (contentHeight / 2) * 0.75 // 内容图片这里不需要留白的距离
var pdf = new JsPDF('', 'pt', [pdfWidth, pdfHeight])
pdf.addImage(pageData, 'jpeg', 0, 0, imgWidth, imgHeight)
// pdf.save('report_pdf_' + new Date().getTime() + '.pdf')
pdf.save(title + '.pdf')
// var pdf = new JsPDF('', 'pt', [pdfWidth, pdfHeight])
// pdf.addImage(pageData, 'jpeg', 0, 0, imgWidth, imgHeight)
// // pdf.save('report_pdf_' + new Date().getTime() + '.pdf')
// pdf.save(title + '.pdf')
// let contentWidth = canvas.width
// let contentHeight = canvas.height
// let pageHeight = (contentWidth / 592.28) * 841.89
// let leftHeight = contentHeight
// let position = 0
// let imgWidth = 595.28
// let imgHeight = (592.28 / contentWidth) * contentHeight
// let pageData = canvas.toDataURL('image/jpeg', 0.4)
// let PDF = new JsPDF('', 'pt', 'a4')
// 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(title + '.pdf')
let contentWidth = canvas.width
let contentHeight = canvas.height
let pageHeight = (contentWidth / 592.28) * 841.89
let leftHeight = contentHeight
let position = 0
let imgWidth = 595.28
let imgHeight = (592.28 / contentWidth) * contentHeight
let pageData = canvas.toDataURL('image/jpeg', 0.4)
let PDF = new JsPDF('', 'pt', 'a4')
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(title + '.pdf')
})
}
}

Binary file not shown.