将网页保存为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`
        );
      });
    },
相关推荐
伊织code4 小时前
pdftk - macOS 上安装使用
macos·pdf·pdftk
菜鸟-要努力15 小时前
pdf文件转word免费使用几个工具
pdf·word
量化风云2 天前
『量化人的概率 03』PDF is all you need
python·金融·pdf·概率论·量化交易·量化课程
GIS小小研究僧2 天前
免费PDF编辑软件 pdf24-creator 及其安装包
pdf
Python当打之年2 天前
工具分享05 | Python制作PDF合并拆分提取工具V1.0
python·pdf
EkihzniY3 天前
单层 PDF 与双层 PDF:一字之差,功能大不同
pdf·ocr
Dxy12393102163 天前
Python合并两个PDF文件
python·pdf
数据知道3 天前
将英文PDF文件完整地翻译成中文的4类方式
人工智能·学习·自然语言处理·pdf·机器翻译
dxnb223 天前
Datawhale+AI夏令营_让AI读懂财报PDF task2深入赛题笔记
人工智能·笔记·pdf