将网页保存为PDF---不分页

将网页保存为PDF---不分页

1.要下载的内容

复制代码
<div ref="reportContent">

写入要下载的内容
</div>

2.下载的方法

复制代码
    downloadPDF() {
      html2canvas(this.$refs.reportContent, {
        scale: 1.5, // 降低缩放比例来减少图像大小(从2降到1.5)
        useCORS: true,
        width: this.$refs.reportContent.scrollWidth,
        height: this.$refs.reportContent.scrollHeight,
        scrollY: -window.scrollY
      }).then((canvas) => {
        const imgData = canvas.toDataURL('image/jpeg', 1); // 使用JPEG格式并调整质量

        // A4宽度 (单位:mm)
        const pdfWidth = 210;
        // 根据内容计算PDF高度 (单位:mm)
        const imgWidth = pdfWidth;
        const imgHeight = (canvas.height * imgWidth) / canvas.width;
        const pdfHeight = imgHeight;
        const pdf = new jsPDF('p', 'mm', [pdfWidth, pdfHeight]);
        pdf.addImage(imgData, 'JPEG', 0, 0, imgWidth, imgHeight); // 使用JPEG格式
        pdf.save(
          `${this.name}_${this.formatDate}.pdf`
        );
      });
    },
相关推荐
web打印社区2 小时前
前端开发实现PDF打印需求:从基础方案到专业解决方案
前端·vue.js·react.js·electron·pdf
Kratzdisteln4 小时前
【MCM】(x= (N_A),y=(N_G),z=(p))RGB=T*
pdf
Kratzdisteln4 小时前
【1902】process_assignment_pdf()
大数据·人工智能·pdf
AAA_搬砖达人小郝8 小时前
Markdown 一键生成完美 Word(.docx) + PDF 的完整实战方案(JDK 8 环境亲测可用)
pdf·word
Kratzdisteln1 天前
【1902】process_handout_pdf()
服务器·windows·pdf
星月前端1 天前
springboot中使用LibreOffice实现word转pdf(还原程度很高,可以配置线程并发!)
spring boot·pdf·word
qq_171520351 天前
linux服务器springboot(docker)项目word转pdf中文乱码
linux·spring boot·docker·pdf·word
100分简历1 天前
无图标简洁大方的简历模板下载
人工智能·面试·职场和发展·pdf·编辑器
zyplayer-doc1 天前
文档增加访问密码设置,编辑器增加导航,登录日志增加IP归属地和浏览器信息展示,zyplayer-doc 2.5.9 发布啦!
人工智能·pdf·编辑器·飞书·开源软件·有道云笔记
appearappear1 天前
wkhtmltopdf把 html 原生转成成 pdf
前端·pdf·html