将网页保存为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`
        );
      });
    },
相关推荐
乐迁~5 小时前
如何使用html2canvas和jsPDF库来解决PDF导出时分页内容截断问题(下--表格行截断处理)
pdf·js
拆房老料6 小时前
实战复盘:自研 Office / PDF 文档处理平台的高坑预警与 AI Agent 时代架构思考
人工智能·架构·pdf·编辑器·开源软件
开开心心就好6 小时前
PDF密码移除工具,免费解除打印编辑复制权限
java·网络·windows·websocket·pdf·电脑·excel
非凡ghost9 小时前
批量转双层PDF(可识别各种语言)
windows·学习·pdf·软件需求
乐迁~9 小时前
前端PDF导出完全指南:JSPDF与HTML2Canvas深度解析与实战(上)
前端·pdf
月巴月巴白勺合鸟月半1 天前
PDF转图片的另外一种方法
pdf·c#
多则惑少则明1 天前
AI大模型综合(四)langchain4j 解析PDF文档
pdf·springboot·大语言模型
m5655bj1 天前
使用 C# 对比两个 PDF 文档的差异
pdf·c#·visual studio
WXDcsdn1 天前
Windows无法使用Microsoft to PDF输出PDF文件
windows·pdf·电脑·it运维
Yqlqlql1 天前
基于 Python+PySide6 开发的本地复合文件工具:图片转 PDF+PDF 转 Word 双功能
pdf