将网页保存为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`
        );
      });
    },
相关推荐
manjianghong861 天前
如何将一本书PDF扫描件转word 并打印(免费工具)
pdf·word·pdf处理工具
zhangfeng11331 天前
大语言模型llm学习路线电子书 PDF、开源项目、数据集、视频课程、面试题、工具镜像汇总成一张「一键下载清单」
学习·语言模型·pdf
manjianghong862 天前
PDF扫描件图片太大如何批量裁剪(免费工具)
pdf·pdf免费工具·pdf文件处理
YJlio2 天前
杨利杰YJlio|博客导航目录(专栏总览 + 推荐阅读路线)
开发语言·python·pdf
꧁༺℘₨风、凌๓༻꧂2 天前
C# WPF 项目中集成 Pdf查看器
pdf·c#·wpf
liliangcsdn2 天前
常用pdf解析提取工具的分析和示例
pdf
有趣灵魂2 天前
Java-Spingboot根据HTML模板和动态数据生成PDF文件
java·pdf·html
mfxcyh2 天前
使用html2canvas和jsPDF导出pdf文件、把pdf文件传给后端
pdf
ComPDFKit3 天前
从爱泼斯坦案文件泄露,看“涂黑≠删除”的 PDF 脱敏陷阱
pdf·脱敏·pdf redaction·标记密文·涂黑
今夕资源网3 天前
PDF与图片在线处理工具纯HTML网页源码 PDF 多功能魔方
pdf·pdf在线处理