dom-to-pdf
TODO
Install
yarn add element-to-pdf
Usage
const pdfs = await domToPdf.transformToPdfs({
elements: [
document.getElementById('test')! as HTMLDivElement,
document.getElementById('test1')! as HTMLDivElement
],
})
pdfs.forEach(pdf => {
pdf.save('demo.pdf')
})
Options
NOTICE
- 生成pdf时,目标元素会新增class: DomToPdf.TransformingClassName, 可用于修正元素生成pdf的显示问题
eg: 修复table元素border显示问题
.dom-to-pdf-layer {
&.dom-to-pdf-transforming {
table {
tr {
transform: translateY(-0.5px);
td, th {
&:not(:first-of-type,:last-of-type) {
border-left: none;
border-right: none;
}
}
}
}
}
}