将网页保存为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`
        );
      });
    },
相关推荐
海绵波波1079 小时前
Zotero使用(一)PDF文件导入不会自动识别
pdf
2401_856926939 小时前
图片转PDF技巧揭秘:四款高效工具推荐!
学习·pdf·图片转pdf·图片转pdf工具
alex180115 小时前
python实现多个pdf文件合并
java·python·pdf
似璟如你20 小时前
Vue点击按钮生成pdf文件/Vue点击按钮生成png图片
pdf
deephub21 小时前
概率分布深度解析:PMF、PDF和CDF的技术指南
人工智能·python·机器学习·pdf·概率论
William.csj21 小时前
PDF——压缩大小的方法
pdf
百事牛1 天前
【方法】如何禁止PDF转换成其他格式文件?
windows·pdf
白手小弟2 天前
docker部署Stirling-PDF
docker·容器·pdf
咔咔学姐kk2 天前
2024最新版,人大赵鑫老师《大语言模型》新书pdf分享
数据库·人工智能·语言模型·自然语言处理·pdf·知识图谱·产品经理
zhang-ge2 天前
python提取pdf表格到excel:拆分、提取、合并
python·pdf·excel