将网页保存为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`
        );
      });
    },
相关推荐
弓.长.35 分钟前
ReactNative for OpenHarmony项目鸿蒙化三方库:react-native-pdf — PDF文档查看器
react native·pdf·harmonyos
开开心心就好3 小时前
绿色版PDF多功能工具,支持编辑转换
人工智能·windows·pdf·ocr·excel·语音识别·harmonyos
月巴月巴白勺合鸟月半8 小时前
一次PDF文件的处理(二)
pdf·c#
开开心心就好8 小时前
免费无广告的礼金记账本,安卓应用
java·前端·ubuntu·edge·pdf·负载均衡·语音识别
优化控制仿真模型8 小时前
2015-2025年12月英语六级历年真题及答案PDF电子版(含听力音频)
经验分享·pdf
爱编程的小吴8 小时前
LangChain基础入门:DocumentLoader加载PDF/Markdown文档实战
python·langchain·pdf
软件工程小施同学9 小时前
区块链论文速读 CCF A--CCS 2025 (1) 附pdf下载
pdf·区块链
葡萄城技术团队1 天前
SpreadJS 中“打印”和“导出 PDF”到底该选哪个?
pdf
优化控制仿真模型1 天前
2025年12月英语六级真题及答案解析完整版(第一、二、三套全PDF)
经验分享·pdf
芒果大胖砸1 天前
uniapp 在h5中预览pdf hybrid方法
pdf·uni-app