在vue js中将页面下载为PDF

时间:2020-06-19 13:58:52

标签: vue.js vuejs2 jspdf

我从组件中获得了以下代码:

    <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文件。

0 个答案:

没有答案