The web page is printed as a pdf instance code in vue, vuepdf

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.