将网页保存为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`
        );
      });
    },
相关推荐
大黄说说7 小时前
Python 实战指南:一键批量旋转 PDF 页面方向
开发语言·python·pdf
Jack.Huangjh1 天前
ABAP PDF
pdf
北极象1 天前
Flying-Saucer HTML到PDF渲染引擎核心流程分析
前端·pdf·html
一只酸奶牛^_^2 天前
java实现pdf添加水印
java·pdf
还是叫明2 天前
将PDF每一页导出一张图片(C#,.NET)
pdf
E_ICEBLUE2 天前
Python 实现 PDF 表单域的自动化创建与智能填充
python·pdf·自动化·表单域
莫非技术栈2 天前
51AI工具集:网站更新了图片工具、PDF工具、视频工具、音频工具
pdf
御坂10101号4 天前
爱泼斯坦文件技术细节:伪扫描、元数据清洗与撤销涂黑
图像处理·pdf·ocr
羑悻的小杀马特4 天前
本地PDF处理神器Stirling - PDF搭配cpolar
网络协议·pdf·电脑·cpolar
xiaoliuliu123454 天前
Foxit_PDFOEM_xp85安装步骤详解(附PDF阅读与表单填写教程)
pdf