将网页保存为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`
        );
      });
    },
相关推荐
诸葛大钢铁1 天前
如何拆分PDF文件?快速拆分PDF文件的2个方法
pdf·pdf拆分
CodeCraft Studio1 天前
国产化PDF处理控件Spire.PDF教程:在Java快速解析PDF文本、表格、图像和元数据
java·python·pdf·pdf解析·spire.pdf·元数据解析·java pdf解析
计算机视觉-Archer1 天前
【免费pdf加水印】Adobe Acrobat PDF
pdf
程序员哈基耄2 天前
本地化PDF工具箱:安全、高效的文档处理解决方案
安全·pdf
qq_451119552 天前
visio 导出pdf无边框无空白边距
pdf
yesyesido2 天前
PDF全能处理平台:高效压缩、精准拆分与智能合并的一站式解决方案
pdf
优选资源分享2 天前
CubePDF Page v5.1.4 | 高效 PDF 合并拆分工具
pdf
浩浩的科研笔记2 天前
投论文常用技术笔记-使用visio导出贴合图像尺寸大小的PDF(无白边、无黑框)
笔记·pdf·论文笔记
m5655bj2 天前
如何通过 C# 将 Markdown 转换为 PDF 文档
开发语言·pdf·c#
stereohomology2 天前
解决某些Typora主题导出PDF分页拦腰截断文字或图片等问题的方法
pdf