将网页保存为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`
        );
      });
    },
相关推荐
普通网友4 小时前
Docker 磁盘占用分析和清理方法
pdf
盐焗西兰花6 小时前
鸿蒙学习实战之路-PDF转换指定页面或指定区域为图片
学习·pdf·harmonyos
切糕师学AI7 小时前
轻量pdf阅读器推荐
pdf
一个无名的炼丹师7 小时前
DeepSeek+LangGraph构建企业级多模态RAG:从PDF复杂解析到Agentic智能检索全流程实战
python·pdf·大模型·多模态·rag
开开心心_Every9 小时前
时间自动校准工具:一键同步网络服务器时间
游戏·随机森林·微信·pdf·逻辑回归·excel·语音识别
weixin_318088119 小时前
PDF订单数据和尺码对不上。怎么办?python说好办
pdf·pdfplumber
蓝净云9 小时前
如何从pdf中提取带层级的标题结构
python·pdf
DS随心转小程序10 小时前
ChatGPT和Gemini转pdf
人工智能·ai·chatgpt·pdf·豆包·deepseek·ds随心转
souyuanzhanvip1 天前
PDF24 工具箱 V11.23.0 免费离线 PDF 处理工具
pdf·实用工具
非凡ghost1 天前
批量校正图像方向(校正PDF页面方向)
windows·学习·pdf·软件需求