将网页保存为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`
        );
      });
    },
相关推荐
ZeroNews内网穿透21 小时前
公网访问开源 Stirling-PDF 工具,提升办公效率
linux·运维·服务器·网络·pdf·ssh
千天夜21 小时前
Python合并多个PDF文件:完整指南与实践
windows·python·算法·pdf
Redundantº1 天前
Uniapp 适配安卓与 iOS 的 PDF、DOC 文件上传
android·ios·pdf·uni-app·webview
旺旺的碎冰冰~1 天前
Adobe如何给PDF添加页码
adobe·pdf
YANshangqian1 天前
PDF工具箱 PDF24
pdf
优选资源分享1 天前
PDF 补丁丁 v1.1.3.4663绿色版:PDF编辑软件
pdf·实用工具
南风微微吹2 天前
英语四级作文历年真题及范文模版汇总PDF电子版(2015-2025年6月)
pdf·英语四级
TextIn智能文档云平台2 天前
如何快速提取PDF文档内容
pdf
小马爱打代码2 天前
Spring AI:DeepSeek 整合 RAG 增强检索: 实现与 PDF 对话
人工智能·spring·pdf
南风微微吹2 天前
英语六级作文历年真题及范文模版汇总PDF电子版(2015-2025年6月)
pdf·英语六级