将网页保存为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`
        );
      });
    },
相关推荐
罗政8 小时前
PDF 批量合并工具:本地 AI 自动排序、识别正文日期与合同编号
数据库·pdf·php
Metaphor69212 小时前
使用 Python 添加、隐藏和删除 PDF 图层
python·pdf·图层
SEO-狼术15 小时前
Navigate PDF Documents with Page Thumbnails
pdf
SEO-狼术2 天前
Organize PDF Navigation with Bookmarks
pdf
qetfw2 天前
初中数学教材PDF合集|人教北师大华师大等10个版本
pdf
绘梨衣5473 天前
求助帖:pdf复杂表格解析
爬虫·python·pdf
大飞记Python3 天前
Linux命令速查手册(测试开发4年实战总结,附PDF)
linux·网络·pdf
2501_930707783 天前
如何在不损失质量的情况下将 PDF 转换为 SVG
pdf
eybk3 天前
写一个可以编制pdf文件的python程序
开发语言·python·pdf
YFJ_mily3 天前
**Python 实战:写一个论文 PDF 投稿自检工具|附 IPAT 2026 智能光子学会议征稿信息
人工智能·python·pdf·量子计算·论文投稿·智能光子学