将网页保存为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`
        );
      });
    },
相关推荐
放飞自我的Coder3 小时前
【PDF拆分 Python拆分左右并排PDF】
python·pdf
开开心心_Every3 小时前
发票批量打印工具支持双面预览页面方向设置
游戏·微信·pdf·华为云·excel·语音识别·googlecloud
AI刀刀3 小时前
千问 文心 元宝 Kimi公式乱码
ai·pdf·豆包·deepseek·ds随心转
J_liaty8 小时前
Java实现PDF添加水印的完整方案(支持灵活配置、平铺、多页策略)
java·开发语言·pdf
德育处主任Pro8 小时前
『NAS』告别付费和广告,在群晖部署PDF工具箱-bentopdf
pdf·nas
索荣荣8 小时前
Spring Boot 实现DOCX转PDF(基于docx4j的轻量级开源方案)
spring boot·后端·pdf
裴嘉靖8 小时前
uni-app 打包后 PDF 无法生成问题完整解决方案
pdf·uni-app
wujian83118 小时前
AI导出pdf方法
人工智能·pdf
小郎君。10 小时前
PDF-知识图谱全流程前后端实现【工具已实现,搭建前后端pipline】
pdf·状态模式·知识图谱
wujian831110 小时前
ChatGPT和Gemini导出pdf方法
人工智能·ai·chatgpt·pdf·deepseek