vue页面上是按钮点击,这个方法就是下面js的方法,pdf是要导出的范围div的属性ref=pdf
toPDF{
downloadPDF(this.$refs.pdf)
}
普通的vue导出PDF
参考Vue页面生成PDF的方法_vue 生成pdf-优快云博客
导出PDF
export const downloadPDF = page => {
html2canvas(page).then(function(canvas) {
canvas2PDF(canvas);
});
};
const canvas2PDF = canvas => {
let contentWidth = canvas.width;
let contentHeight = canvas.height;
//a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
let imgWidth = 595.28;
let imgHeight = 814.89/contentWidth * contentHeight;
// 第一个参数: l:横向 p:纵向
// 第二个参数:测量单位("pt","mm", "cm", "m", "in" or "px")