将网页保存为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`
        );
      });
    },
相关推荐
2501_927012571 小时前
修改pdf属性时间和日期怎么改?3种方法,零专业工具上手
经验分享·其他·pdf
诸葛大钢铁3 小时前
如何限制PDF的打印、复制编辑等操作?限制PDF打印编辑复制的三种方法
pdf·word·pdf打印限制·权限限制
南风微微吹3 小时前
2000-2026年国考《行测+申论》历年真题及答案解析PDF电子版(考公)
pdf·考公
开开心心_Every4 小时前
扫描软件,部分文档文字表格识别功能可免费
运维·服务器·pdf·电脑·excel·3dsmax·houdini
无心水10 小时前
15、商业API巅峰对决|Adobe vs Google vs Azure 高精度OCR全方位评测
架构·pdf·pdf解析·pdf抽取·paddlercor
weixin_4166600710 小时前
原创分享:Markdown 转 Word 工具,一键导出Word/PDF文档
pdf·word·latex·deepseek
开开心心就好10 小时前
这款PPT计时工具支持远程控制功能
前端·科技·游戏·edge·pdf·全文检索·powerpoint
开开心心就好1 天前
无需安装的单机塔防游戏轻松畅玩
人工智能·游戏·pdf·音视频·智能家居·语音识别·媒体
枫叶丹41 天前
【HarmonyOS 6.0】ArkWeb PDF预览回调功能详解:让PDF加载状态可控可感
开发语言·华为·pdf·harmonyos
优化控制仿真模型1 天前
【26年6月最新】英语六级2015-2025年12月历年真题及答案PDF
经验分享·pdf