|
Download html page content, One can follow as: Specify the ref to the element, whose content you want to download as pdf <div ref="content"> .... .. </div>Create a button download like <button @click="download">Download PDF</button>Make sure to add & import jsPDF library into vue-component import jsPDF from 'jspdf' import html2canvas from "html2canvas"Specify the method into the VUE component like methods: { download() { const doc = new jsPDF(); const contentHtml = this.$refs.content.innerHTML; doc.fromHTML(contentHtml, 15, 15, { width: 170 }); doc.save("sample.pdf"); }, downloadWithCSS() { const doc = new jsPDF(); /** WITH CSS */ 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"); }); }, }See the demo @Download PDF via VUEJS. (责任编辑:) |
