jsPDF 可自动 API?

jsPDF Autotable API?

刚刚找到了 jsPDF 的 Autotable 插件,在我尝试使用它时似乎有一点学习曲线。我看到文件附带的 examples.js,但是在我可以看到所有方法的地方是否有完整的 API?

例如 didParseCell 部分有这样的代码:

  // Use for customizing texts or styles of specific cells after they have been formatted by this plugin.
// This hook is called just before the column width and other features are computed.
  didParseCell: function (data) {
  if (data.row.index === 5) {
    data.cell.styles.fillColor = [40, 170, 100]
  }

  if (
    (data.row.section === 'head' || data.row.section === 'foot') &&
    data.column.dataKey === 'expenses'
  ) {
    data.cell.text = '' // Use an icon in didDrawCell instead
  }

  if (data.column.dataKey === 'city') {
    data.cell.styles.font = 'mitubachi'
    if (data.row.section === 'head') {
      data.cell.text = 'シティ'
    }
    if (data.row.index === 0 && data.row.section === 'body') {
      data.cell.text = 'とうきょう'
    }
  }
},

我想知道 methods/properties 我可以访问哪些“数据”。是否有完整的 API 在某处列出这些内容?

readme.md available as documentation. For more details they are suggesting to read the class definitions for HookData, Table, Row, Cell etc. defined in models.ts:

To see what is included in the Table, Row, Column and Cell types, either log them to the console or take a look at src/models.ts


为了方便参考,这里有定义:

class HookData {
  table: Table
  pageNumber: number
  pageCount: number // Deprecated, use pageNumber instead
  settings: Settings
  doc: jsPDFDocument
  cursor: Pos | null
}

class CellHookData extends HookData {
  cell: Cell
  row: Row
  column: Column
  section: 'head' | 'body' | 'foot'
}

class Table {
  id?: string | number
  settings: Settings
  styles: StylesProps
  hooks: HookProps
  columns: Column[]
  head: Row[]
  body: Row[]
  foot: Row[]
  pageNumber = 1
  finalY?: number
  startPageNumber?: number
}

class Row {
  readonly raw: HTMLTableRowElement | RowInput
  readonly element?: HTMLTableRowElement
  readonly index: number
  readonly section: Section
  readonly cells: { [key: string]: Cell }
  spansMultiplePages: boolean

  height = 0
}

class Cell {
  raw: HTMLTableCellElement | CellInput
  styles: Styles
  text: string[]
  section: Section
  colSpan: number
  rowSpan: number

  contentHeight = 0
  contentWidth = 0
  wrappedWidth = 0
  minReadableWidth = 0
  minWidth = 0

  width = 0
  height = 0
  x = 0
  y = 0
}

class Column {
  raw: ColumnInput | null
  dataKey: string | number
  index: number

  wrappedWidth = 0
  minReadableWidth = 0
  minWidth = 0
  width = 0
}