将网页保存为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`
        );
      });
    },
相关推荐
这个需求建议不做18 小时前
pdf.js(pdfdist)踩坑workerSrc报错pdf.worker.mjs无法正确获取
开发语言·javascript·pdf
坐吃山猪19 小时前
Python之PDF小工具
开发语言·python·pdf
极智-99621 小时前
pdf怎么打开?【图文详解】免费的pdf阅读编辑器?pdf文件转换?
pdf·pdf转换·pdf转word·pdf编辑·pdf文件怎么打开·pdf阅读编辑·pdf文件阅读
maogewang2 天前
清朝条约史料三册合辑:从尼布楚到辛丑条约的完整 PDF 文献汇编
pdf
开开心心就好2 天前
版本转换工具,支持Win双系统零售批量版
linux·运维·服务器·pdf·散列表·零售·1024程序员节
DechinPhy2 天前
使用Python免费合并PDF文件
开发语言·数据库·python·mysql·pdf
开开心心就好2 天前
免费卸载工具,可清理残留批量管理启动项
linux·运维·服务器·windows·随机森林·pdf·1024程序员节
mysusheng3 天前
2025年12月Z-Library电子书下载工具
pdf
vfvfb3 天前
pdf转图片 每一页转成图片 pdf转jpg
pdf·pdf每一页转成图片
YJlio3 天前
Python 一键拆分 PDF:按“目录/章节”建文件夹 + 每页单独导出(支持书签识别&正文识别)
开发语言·python·pdf