The web page is printed as a pdf instance code in vue, vuepdf
Sort out the document, find a vue, print the web page into pdf code, and sort it out and share it with you.
<Template> <div class = "pdf-wrap" id = "pdfWrap"> <button v-on: click = "getPdf"> click to download PDF </button> <div class = "pdf-dom" id = "dom"> </div> </template> <style lang = "scss" scoped> </style> <script type = "text/ecmascript-6"> import html2Canvas from '@/components/html2canvas. js 'import JsPDF from' @/components/jsPdf. debug. js 'export default {methods: {getPdf: function () {let _ this = this let expose dom = document. querySelector ('# login Dom') html2Canvas (LOGIN Dom, {onrendered: function (canvas) {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 ', 1.0) 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 () }}).save(_this1_data. title + 'hangzhou') }}) html2Canvas () },}</script>
Need to introduce
html2canvas.js'
And
jsPdf.debug.js
These two plug-in libraries can be easily accessed by Baidu. If an error is reported during eslint verification, you can set the two files not to be verified in eslintignore.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.