将网页保存为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`
        );
      });
    },
相关推荐
阿幸软件杂货间16 小时前
Office转PDF转换器v1.0.py
开发语言·pdf·c#
reembarkation20 小时前
使用pdfjs-dist 预览pdf,并添加文本层的实现
前端·javascript·pdf
reembarkation20 小时前
vue-pdf 实现blob数据的预览
javascript·vue.js·pdf
Light601 天前
领码方案|Linux 下 PLT → PDF 转换服务超级完整版:异步、权限、进度(一气呵成)
linux·spring boot·pdf·gpcl6/ghostpcl·s3/oss·权限与审计·异步与进度
伟贤AI之路1 天前
【分享】中小学教材课本 PDF 资源获取指南
人工智能·pdf
东风西巷1 天前
PDFgear:免费全能的PDF处理工具
前端·pdf·软件需求
Sunny_yiyi2 天前
Java根据模版导出PDF文件
java·开发语言·pdf
小*-^-*九3 天前
php 使用html 生成pdf word wkhtmltopdf 系列2
pdf·html·php
千册3 天前
pyside6 的pdf显示测试 -- 01
开发语言·python·pdf
qq_172805593 天前
Go 语言 PDF 生成库综合比较与实践指南
开发语言·golang·pdf