将网页保存为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`
        );
      });
    },
相关推荐
shadowcz0072 小时前
关于GEO的研究总结#使用 Notebooklm 来研究论文和整理报告#PDF分享
人工智能·pdf
czliutz20 小时前
使用pdfplumber库处理pdf文件获取文本图片作者等信息
python·pdf
archko21 小时前
用rust+slint编写一个pdf阅读器
pdf
jimmyleeee1 天前
人工智能基础知识笔记二十四:构建一个可以解析PDF简历的Agent
笔记·pdf
archko1 天前
用rust+slint编写一个pdf阅读器2
pdf
坚定信念,勇往无前1 天前
vue3图片,pdf,word,excel,ppt多格式文件预览组件Vue Doc Viewers Plus
pdf·word·excel
拓端研究室2 天前
2025医疗健康行业革新报告:AI赋能、国际化|附170+份报告PDF、数据、可视化模板汇总下载
人工智能·pdf
小年糕是糕手2 天前
【C++】类和对象(六) -- 友元、内部类、匿名对象、对象拷贝时的编译器优化
开发语言·c++·算法·pdf·github·排序算法
libolei2 天前
压缩 pdf 文件大小 完全免费
pdf·pdf压缩
一只小羊啊2 天前
Vue + Android WebView 实现大文件 PDF 预览完整解决方案
android·vue.js·pdf·webview