本文只讲html生成pdf
官网文档地址:http://raw.githack.com/MrRio/jsPDF/master/docs/module-html.html#~html
一、安装
npm install jspdf
二、使用
<button onclick="print()">生成PDF</button>
<div id="printID">pdf内容</div>
import { jsPDF } from "jspdf"
print(){
const doc = new jsPDF({
unit:"px",
hotfixes: ["px_scaling"],
compress: true
});
const pdf:any = document.querySelector("#printID")
const width = doc.internal.pageSize.width - 80
doc.html(pdf,{
callback: doc=> {
window.open(doc.output("bloburi"))
},
margin:[30,40,30,40],
windowWidth: width, //处理屏幕怎么缩放生成pdf结果一样
width: width, //处理屏幕怎么缩放生成pdf结果一样
})
}