将网页保存为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`
        );
      });
    },
相关推荐
空中湖12 小时前
文档极速转换器 - 免费批量Word转PDF工具
pdf·word
沉到海底去吧Go13 小时前
【工具教程】PDF电子发票提取明细导出Excel表格,OFD电子发票行程单提取保存表格,具体操作流程
pdf·excel
诸葛大钢铁1 天前
PDF转PPT转换方法总结
pdf·powerpoint
漫游者Nova2 天前
PDF转Markdown/JSON软件MinerU最新1.3.12版整合包下载
pdf·json·markdown·mineru
sss191s2 天前
Java 集合面试题 PDF 及常见考点解析与备考指南
java·开发语言·pdf
风筝超冷2 天前
PDF 转 Markdown
pdf
wxgnolux2 天前
网页端 js 读取发票里的二维码信息(图片和PDF格式)
pdf·jsqr
Eiceblue2 天前
C# 快速检测 PDF 是否加密,并验证正确密码
开发语言·pdf·c#·visual studio
耗不尽的先生2 天前
【PDF PicKiller】PDF批量删除固定位置图片工具,默认解密,可去一般图、背景图、水印图!
pdf
weixin_472339463 天前
使用Python提取PDF元数据的完整指南
java·python·pdf