将网页保存为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`
        );
      });
    },
相关推荐
E_ICEBLUE13 小时前
PDF 文件为什么打不开?常见原因与解决思路
pdf·c#·html
思杰软件14 小时前
PDF盖骑缝章
pdf
科技圈快讯14 小时前
免费AIPPT生成工具推荐:一键生成+实时预览,支持Markdown/PDF导入
pdf
六bring个六14 小时前
PDF压缩
pdf
codingPower1 天前
制作ftl文件通过FreeMarke生成PDF文件(含图片处理)
java·开发语言·pdf
拓端研究室1 天前
专题:2025年脑机接口产业蓝皮书:市场规模、专利技术、投融资与临床应用|附40+份报告PDF、数据、可视化模板汇总下载
pdf
日日行不惧千万里1 天前
孤勇者歌词拼音打印版PDF
pdf
小易吾1 天前
VISIO导出高清PDF有效方法
笔记·pdf
A0_張張1 天前
记录一个PDF盖章工具(PyQt5 + PyMuPDF)
开发语言·python·qt·pdf
大卡拉米2 天前
前端组件库 PDF、word、Excel预览
前端·pdf·word