将网页保存为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`
        );
      });
    },
相关推荐
南风微微吹2 小时前
2026英语六级作文模版万能句子PDF电子版
pdf·英语六级
又是被bug折磨的一天3 小时前
对多个pdf合同文件批量命名
pdf
南风微微吹4 小时前
2026年英语四级作文模版万能句子PDF电子版
pdf·英语四级
这是个假程序员6 小时前
PDF分色、智能PDF黑彩识别工具
pdf
夜勤月7 小时前
HarmonyOS 6.0 ArkWeb实战:PDF背景色自定义功能全解析(附完整代码+避坑指南)
华为·pdf·harmonyos
relis7 小时前
AI使用小技巧: 用zed和MinerU本地版,同时学习PDF文档的文字和图片
ai·pdf·大模型·agent
海盗12347 小时前
C#中PDF操作-QuestPDF页面设置与布局
java·pdf·c#
又是被bug折磨的一天8 小时前
发票形式是eml批量下载发票pdf
pdf
hmz85610 小时前
亲测有效,完全免费PDF转换工具,支持PDF压缩、PDF转图片、PDF删除和排序 、PDF转Word、PDF转文本、图片转PDF【附安装教程】
pdf
至善迎风11 小时前
用 Codex / Claude Code Skill 自动完成「文献 PDF → 文献汇报 PPT」:从论文精读到 10–12 页学术汇报
人工智能·pdf·powerpoint