本文只講html生成pdf
官網(wǎng)文檔地址:http://raw.githack.com/MrRio/jsPDF/master/docs/module-html.html#~html
一菩颖、安裝
npm install jspdf
二、使用
<button onclick="print()">生成PDF</button>
<div id="printID">pdf內(nèi)容</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結(jié)果一樣
width: width, //處理屏幕怎么縮放生成pdf結(jié)果一樣
})
}