织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

Generate pdf with jspdf and Vue.js

时间:2025-10-26 09:00来源: 作者:admin 点击: 7 次
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">

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.

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-10-28 14:10 最后登录:2025-10-28 14:10
栏目列表
推荐内容