将网页保存为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`
        );
      });
    },
相关推荐
zyplayer-doc5 小时前
目录支持批量操作,文档增加可见范围、锁定功能,PDF查看优化,zyplayer-doc 2.5.8 发布啦!
数据库·人工智能·pdf·编辑器·飞书·石墨文档
2501_9307077813 小时前
如何使用C#代码在 PDF 文档添加页码
pdf
AI人工智能+13 小时前
文档抽取技术结合OCR、NLP和计算机视觉,能智能提取PDF、扫描件等版式文档中的结构化数据
pdf·ocr·文档抽取
梵克之泪14 小时前
根据表格内容和模板文件批量创建word文件,一次性生成多个word文档和批量生成创建PDF文件
pdf·word
December31014 小时前
【图文教程】图片转pdf,从入门到精通
pdf·图片·格式转换·图片转换·图片转pdf·图转pdf
g***969018 小时前
【Spring Boot 实现 PDF 导出】
spring boot·后端·pdf
zyplayer-doc1 天前
重写OFD查看器,完善PDF查看器,增加搜索历史记录、滚动分页、目录排序等,zyplayer-doc 2.5.7 发布啦!
pdf·编辑器·飞书·开源软件·创业创新·有道云笔记
傻啦嘿哟1 天前
Python实现PDF文档高效转换为HTML文件:从基础到进阶的完整指南
python·pdf·html
流浪猪头拯救地球2 天前
利用 Python 解密 / 加密 PDF 文件
python·pdf·php
兰琛2 天前
Android Compose展示PDF文件
android·pdf