在primular数据表中导出pdf在Angular 9中不起作用

问题描述

我试图在Angular 9的Primeng数据表中实现PDF导出。我的代码如下:

exportPdf() {
  this.cols = [
    { field: 'code',header: 'Code' },{ field: 'name',header: 'Name' },{ field: 'category',header: 'Category' },{ field: 'quantity',header: 'Quantity' }
];

this.exportColumns = this.cols.map(col => ({title: col.header,dataKey: col.field})); console.log(this.exportColumns)
import("jspdf").then(jsPDF => {
  import("jspdf-autotable").then(x => {
      const doc = new jsPDF.default(0,0);
      doc.autoTable(this.exportColumns,this.products);
      doc.save('products.pdf');
      
 })
})
}

但是我收到此错误

error TS2345: Argument of type '0' is not assignable to parameter of type 'string'.

    in       const doc = new jsPDF.default(0,0);

我还安装了这些

"jspdf": "^1.5.3","jspdf-autotable": "^3.5.13"

如何解决错误。有人可以帮我吗?

解决方法

默认方法将第一个参数作为字符串'"p" | "portrait" | "l" | "landscape"',第二个参数作为单位,并采用这些值"pt" | "px" | "in" | "mm" | "cm" | "ex" | "em" | "pc"

import jsPDF from "jspdf";
import "jspdf-autotable";
...

exportPdf() {
    const doc = new jsPDF('p','pt'); // or like this ? new jsPDF();
    doc.autoTable(this.exportColumns,this.products);
    doc.save("products.pdf");
}

demo ?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...