将网页保存为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`
        );
      });
    },
相关推荐
TextIn智能文档云平台12 小时前
PDF格式转化,哪款软件的准确率更高?
人工智能·pdf
帧栈13 小时前
开发避坑指南(73):itext7 pdf表单字体加粗解决方案
java·pdf
裤裤兔15 小时前
如何搜索多个PDF文件中的关键字?
pdf
TextIn智能文档云平台17 小时前
PDF提取文字全是乱码怎么解决?
pdf
伟贤AI之路19 小时前
原创分享:Markdown 转 Word 工具,一键导出Word/PDF文档
pdf·word·markdown·markdown转
yesyesido1 天前
PDF全能管家:3合1智能处理,一键解锁高效文档管理新体验
科技·考研·安全·pdf·生活·交互·改行学it
南风微微吹1 天前
2015-2025年英语四级历年真题及答案解析PDF电子版(可下载)
pdf·英语四级
拓端研究室1 天前
专题:2026年中国消费零售行业新图景报告:消费者行为、品牌增长与AI应用|附540+份报告PDF、数据、可视化模板汇总下载
人工智能·pdf·零售
YongCheng_Liang2 天前
Python实现PDF 转 JPG 批量转换工具
运维·python·pdf
weixin_462446232 天前
【原创实现】Python 实现 PDF 批量压缩工具(支持逐个确认 / 批量处理 / 多级压缩)
开发语言·python·pdf