


























npm i html-to-image or npm install html-to-image
看到这里你应该知道我在说什么
<template>
<div id="pdfContent" class="dashboard-container">
好多个div和标签
</div>
<template>
别忘记导入:import * as htmlToImage from 'html-to-image'
async downloadPdf(){ const dom = document.getElementById('pdfContent') const dataUrl = await htmlToImage.toPng(dom, { pixelRatio: 2, backgroundColor: '#fff' }) const pdf = new jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' }) const img = new Image() img.src = dataUrl img.onload = () => { const pageWidth = pdf.internal.pageSize.getWidth() const pageHeight = (img.height * pageWidth) / img.width pdf.addImage( dataUrl, 'PNG', 0, 0, pageWidth, pageHeight ) pdf.save('dashboard.pdf') } }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。