我从组件中获得了以下代码:
<div class="row" ref="content">
.....
</div>
import jsPDF from "jspdf";
import html2canvas from "html2canvas";
methods:{
download(){
const doc = new jsPDF();
var canvasElement = document.createElement('canvas');
html2canvas(this.$refs.content, { canvas: canvasElement
}).then(function (canvas) {
const img = canvas.toDataURL("image/jpeg", 0.8);
doc.addImage(img,'JPEG',20,20);
doc.save("sample.pdf");
});
},
}
我正在尝试以应用的样式(图像形式)下载PDF格式的页面。但是有了上面的代码,我得到了空白的pdf文件。