我使用的角度9,我有一个要求,转换一个html表与一些内容以上和下面的表为pdf。我使用的是jspdf-autotable.I,我遵循了链接https://github.com/simonbengtsson/jsPDF-AutoTable/blob/master/examples/examples.js中的示例,我能够编写一个标题,然后生成table.The问题,当我需要在表下面添加一些文本行时。
我的代码如下。
generatePdf(){
const doc = new jsPDF();
doc.setFontSize(18)
doc.text('ATTENDANCE REPORT FOR DEPOT - '+this.depotId, 14, 22);
autoTable(doc, { html: '#report-per-depot',startY: 30, });
doc.text(" ", 14, doc.lastAutoTable.finalY + 10)
doc.save('AttandancePerDepot.pdf');
}
我得到的错误是
Property 'lastAutoTable' does not exist on type 'jsPDF'.
我尝试导入lastAutoTable as,从‘jspdf-autotable’导入lastAutoTable;
我没有显示任何错误,但我不知道如何从它得到finalY。
lastAutoTable(doc,{});
上面没有显示错误,但它的返回类型是void.So,这是我被卡住的地方。如何得到角9或10的finalY位置?
发布于 2020-09-08 18:26:49
您会得到这个错误,因为类型记录是一种强类型语言& lastAutoTable没有在index.d.ts文件中定义(在jsPdf节点模块下)。
下面是一个小问题,可以避免这个错误&获取finalY值。
import jsPDF from 'jspdf';
import 'jspdf-autotable';
let finalY = (doc as any).lastAutoTable.finalY;
这在我的10角项目中对我有效。
发布于 2021-12-22 05:25:26
角度12 (打字本)
import jsPDF from 'jspdf'
import autoTable from 'jspdf-autotable'
然后在方法上
crearPDF() {
const doc = new jsPDF();
let finalY = 0;
for (const key in this.entradasIndentificaciones) {
if (Object.prototype.hasOwnProperty.call(this.entradasIndentificaciones, key)) {
const element = this.entradasIndentificaciones[key];
doc.text(element, 30, finalY + 10);
autoTable(doc, { html: '#tableOn-' + key });
finalY = (doc as any).lastAutoTable.finalY;
}
}
console.debug("Guardando");
doc.save("Report_.pdf");
}
尊重
https://stackoverflow.com/questions/63565808
复制相似问题