javascript - 如何在jsPdf表格中设置表格

标签 javascript angular jquery-ui ionic2 jspdf

嗨,我正在使用 jsPdf 将报告导出为 pdf 我的代码在这里

 import { Component, OnInit, AfterViewInit, Inject, ViewChild, ElementRef } from '@angular/core';
import * as jsPDF from 'jspdf';

@Component({
  templateUrl: 'goldenSignature.component.html',
  providers: [UserService,
    { provide: 'Window', useValue: window }
  ],
})

export class GoldenSignatureComponent {  

  download() {
    let type;
    if (this.type) {
      type = this.type;
    }
    else {
      type = this.message.allProducts;
    }
    let columns = ["S.No", "Product Name", "Product Type", "Brand Name", "Model Name", "Sample Size", "Status", "Version Number"];
    let data = [];
    let headers = { "S.No": "S.No", "Product Name": "Product Name", "Product Type": "Product Type", "Brand Name": "Brand Name", "Model Name": "Model Name", "Sample Size": "Sample Size", "Status": "Status", "Version Number": "Version Number" };
    data.push(headers);
    if (type == this.message.allProducts) {
      for (let i = 0, j = 1; i < this.data.length; i++) {
        let data1 = {};
        data1 = { "S.No": j, "Product Name": this.data[i].productName, "Product Type": this.data[i].productType, "Brand Name": this.data[i].brandName, "Model Name": this.data[i].modelName, "Sample Size": this.data[i].sampleSize, "Status": this.data[i].status, "Version Number": this.data[i].versionNo };
        data.push(data1);
        j++;
      }
    }
    else {
      for (let i = 0, j = 1; i < this.data.length; i++) {
        if (type == this.data[i].productName) {
          let data1 = {};
          data1 = { "S.No": j, "Product Name": this.data[i].productName, "Product Type": this.data[i].productType, "Brand Name": this.data[i].brandName, "Model Name": this.data[i].modelName, "Sample Size": this.data[i].sampleSize, "Status": this.data[i].status, "Version Number": this.data[i].versionNo };
          data.push(data1);
          j++;
        }
      }
    }
    var doc = new jsPDF('landscape', 'pt');
    doc.setFontSize(18);
    doc.setTextColor(0, 0, 0);
    doc.text(300, 100, type);
    let styles = {
      autoSize: true,
      printHeaders: false,
      columnWidths: 80
    }
    doc.table(100, 150, data, columns, styles);
    doc.save(this.message.pdfGoldenSignature);
  }   

}

一切正常,问题是我想设置表格和表格列的宽度。请任何人告诉如何设置表格的宽度和表格的其他属性 提前致谢

最佳答案

您必须使用 jsPdf 的不同函数给出合适的边距和填充,以合适的方式表示可能是一项繁琐的任务。

尝试jsPDF-autotable插件效果很好,提供了不同的样式/主题。您可以轻松自定义列和行的高度和宽度。

enter image description here

关于javascript - 如何在jsPdf表格中设置表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48768563/

相关文章:

javascript - 排序数组中缺少整数

javascript - 如何更新没有特定类型的 Angular 管

javascript - Angular 返回未定义

javascript - 如何以时间间隔循环列表和淡入?

asp.net-mvc - Jquery UI 对话框发布到 ASP.Net MVC Controller 操作

javascript - Safari iOS7 : Bottom bar can't be hidden when using -webkit-overflow-scrolling: touch;

javascript - ServiceNow - 查询表和插入事件

javascript - 提交动态创建的表单

jquery-ui - jqGrid 没有 jQueryUI?

javascript - 如何将mysql时间戳格式化为mm/dd/yyyy H :i:s in javascript