pdfmake导出页眉页脚问题

最近做项目中遇到一个导出pdf的功能,我用的是pdfmake插件

pdf使用参考

https://blog.csdn.net/qq_24380167/article/details/78735642

但是在添加页脚的时候使用官网提供的

var docDefinition = {
  footer: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; },
  header: function(currentPage, pageCount, pageSize) {
    // you can apply any logic and return any valid pdfmake element

    return [
      { text: 'simple text', alignment: (currentPage % 2) ? 'left' : 'right' },
      { canvas: [ { type: 'rect', x: 170, y: 32, w: pageSize.width - 170, h: 40 } ] }
    ]
  },
  (...)
};

但是footer设置好了,但是怎么也不出来,后来经过好多次实践,网上查资料也没有找到答案

经过一番出错找到了突破口官网提供

pageMargins 把bottom下设置大一点,是bottom把footer遮挡住了,这样设置好了footer设置的就出来
var docDefinition = {
  // a string or { width: number, height: number }
  pageSize: 'A5',

  // by default we use portrait, you can change it to landscape if you wish
  pageOrientation: 'landscape',

  // [left, top, right, bottom] or [horizontal, vertical] or just a number for equal margins
  pageMargins: [ 40, 60, 40, 100 ],
};

希望能帮助到和我遇到一样的问题的童鞋

猜你喜欢

转载自www.cnblogs.com/boshow/p/10283442.html