我想从Angular 6中的HTML中导出PDF。所以我正在使用“jspdf”库。但是我无法设置样式,如颜色和背景颜色。我该怎么做才能实现这个功能?(如果有其他免费的库可以用来代替“jspdf”,我也可以使用它) 您可以从下面的链接中查看演示。
DEMO
.ts 文件
export class AppComponent {
@ViewChild('reportContent') reportContent: ElementRef;
downloadPdf() {
const doc = new jsPDF();
const specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
const content = this.reportContent.nativeElement;
doc.fromHTML(content.innerHTML, 15, 15, {
'width': 190,
'elementHandlers': specialElementHandlers
});
doc.save('asdfghj' + '.pdf');
}
}
.html 文件
<div #reportContent class="p-col-8 p-offset-2">
<table>
<tr>
<td style="color: red;background-color: blue;border:solid;">1111
</td>
<td style="border:solid;">2222
</td>
</tr>
</table>
</div>
<button pButton type="button" label="Pdf" (click)="downloadPdf()">Export Pdf</button>
doc.setFillColor(0, 0, 0)
来设置背景颜色,使用doc.setTextColor(255)
来设置颜色。 - Bharathkumar kamaldoc.addHtml
在样式方面表现良好。但是在doc.addHtml
中,PDF的质量非常差。@Bharathkumarkamal - realist