将网页保存为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`
        );
      });
    },
相关推荐
企鹅侠客8 小时前
开源免费文档翻译工具 可支持pdf、word、excel、ppt
人工智能·pdf·word·excel·自动翻译
近冬的阳光13 小时前
PDF文档管理系统V2.0
pdf
Driver_tu13 小时前
在windows10上基于Python部署marker,实现PDF转markdown文件(保姆级)
pdf
黄铎彦13 小时前
使用GDI+、文件和目录和打印API,批量将图片按文件名分组打包成PDF
c++·windows·pdf
梅如你13 小时前
IEEE官方期刊缩写查询pdf分享
pdf
jxf_jxfcsdn17 小时前
python读取pdf文档
开发语言·python·pdf
蜗牛沐雨17 小时前
如何生成美观且内容稳定的PDF文档:从基础到进阶的全方案解析
人工智能·pdf·tensorflow
Jamence17 小时前
国产开源PDF解析工具MinerU
人工智能·pdf·aigc
伟贤AI之路1 天前
清华大学:DeepSeek与AI幻觉(31页PDF)
人工智能·pdf
d3soft1 天前
deepseek清华大学第二版 如何获取 DeepSeek如何赋能职场应用 PDF文档 电子档(附下载)
ai·pdf·教程·deepseek·赋能职场