繁体   English   中英

使用 jspdf 将内容导出为 pdf 角度

[英]Export content to pdf angular using jspdf

我正在尝试使用 jspdf 创建 pdf。 但是我收到错误cannot create property 'header' on string 'Details' 。我通过这个问题如何解决:无法在字符串上创建属性 'header'但找不到解决方案。请帮助。提前谢谢。 这是我的转换功能

convert() {

    var doc = new jsPDF();
    var col = ["Details", "Values"];
    var rows = [];

    /* The following array of object as response from the API req  */

    var itemNew = [
      { id: 'Case Number', name: '101111111' },
      { id: 'Patient Name', name: 'UAT DR' },
      { id: 'Hospital Name', name: 'Dr Abcd' }
    ];


    itemNew.forEach(element => {
      var temp = [element.id, element.name];
      rows.push(temp);

    });

    doc.autoTable(col, rows);
    doc.save('Test.pdf');
  }

StackBLitz: https ://stackblitz.com/edit/angular-jspdf-xgoetc ? file = app/app.component.ts

问题出在您指定headbodyautoTable()函数中。

var col = [["Details", "Values"]];

改变autoTable()

 doc.autoTable({
        head: col,
        body: rows
    });

更新片段:

convert() {

    var doc = new jsPDF();
    var col = [["Details", "Values"]];
    var rows = [];

    /* The following array of object as response from the API req  */

    var itemNew = [
      { id: 'Case Number', name: '101111111' },
      { id: 'Patient Name', name: 'UAT DR' },
      { id: 'Hospital Name', name: 'Dr Abcd' }
    ];


    itemNew.forEach(element => {
      var temp = [element.id, element.name];
      rows.push(temp);

    });

    //doc.autoTable(col, rows);
    doc.autoTable({
        head: col,
        body: rows
    });
    doc.save('Test.pdf');
  }

PDF 预览 (Test.pdf):

PDF预览

有关更多信息,请参阅jsPDF-AutoTable 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM