将网页保存为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`
        );
      });
    },
相关推荐
半熟的皮皮虾14 小时前
又重新写了个PDF工具箱-转换office格式/合并/拆分/删除常见操作都有了
python·程序人生·pdf·flask·开源·json·学习方法
waterfeeling15 小时前
AGI 论文复现日记:攻克 PDF 解析的“第一公里”
pdf·agi
qq_5469372717 小时前
PDF工具的天花板!PDF补丁丁:开源免费+无广告,支持Win7~Win11,批量OCR秒完成
pdf·ocr
小真zzz17 小时前
ChatPPT免费功能之【导出PDF】:PPT内容安全+便捷分享
人工智能·ai·pdf·powerpoint·ppt·aippt
Rover Ramble1 天前
提取大型非扫描pdf文件的表格数据
pdf
2501_907136822 天前
电子礼簿系统-红白喜事记账工具,PDF/Execl导出
pdf·软件需求
王五周八2 天前
html转化为base64编码的pdf文件
前端·pdf·html
ComPDFKit3 天前
ComPDF 与 Aspose:转换 SDK 的全面比较
pdf
优选资源分享3 天前
PDF 电子签章工具 v5.0:全能处理PDF电子签章
pdf
Arvin_Zhang20163 天前
使用python实现从PDF格式的control mapping获取gross die数量
python·pdf