含eachars的html转pdf

import html2canvas from ‘html2canvas’;
import {jsPDF} from ‘jspdf’;

printDivAsPdf() {
console.log(this.baogao.nativeElement);
let a = this.baogao.nativeElement as HTMLElement;

const bjsElement = a.querySelector('#bjs') as HTMLElement; // 获取id="bjs"的子元素
bjsElement.style.backgroundColor = '#fff';
console.log(bjsElement);
html2canvas(a).then((canvas: HTMLCanvasElement) => {
  const imgData = canvas.toDataURL('image/png');
  const pdf = new jsPDF();
  const imgProps = pdf.getImageProperties(imgData);
  const pdfWidth = pdf.internal.pageSize.getWidth();
  const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
  pdf.addImage(imgData, 'PNG', 2, 2, pdfWidth, pdfHeight);
  pdf.save('printable_echarts_div.pdf');
});
bjsElement.style.backgroundColor = 'gainsboro';

}

下面是dom

{{ getriqi() }}{{ getcbname() }}能耗分析报告

你可能感兴趣的:(html,pdf,前端)