You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Guriddo jqGrid导出PDF时添加页脚页码的技术咨询

问题:Guriddo jqGrid导出PDF时添加页脚页码

正在使用Guriddo jqGrid JS-v5.8.2搭配pdfmake 0.2.7,目前已实现jqGrid数据导出为PDF的功能,但希望在导出的PDF页脚中显示页码。当前使用的代码如下:

$("#serialNumbersGrid").jqGrid("exportToPdf", {
  title: 'Property Serial Numbers',
  orientation: 'landscape',
  pageSize: 'A3',
  description: "Date: " + todaysDate,
  customSettings: null,
  download: 'download',
  includeLabels: true,
  includeGroupHeader: true,
  includeFooter: true,
  fileName: "SerialNumbers.pdf",   
});

已大量搜索相关内容,但未找到添加页码的相关参考。

解决方案

要在导出的PDF页脚添加页码,只需通过customSettings参数传入pdfmake的自定义页脚配置,利用pdfmake内置的页码变量实现动态页码生成,具体修改代码如下:

$("#serialNumbersGrid").jqGrid("exportToPdf", {
  title: 'Property Serial Numbers',
  orientation: 'landscape',
  pageSize: 'A3',
  description: "Date: " + todaysDate,
  customSettings: {
    footer: function(currentPage, pageCount) {
      return {
        columns: [
          '',
          { text: `Page ${currentPage} of ${pageCount}`, alignment: 'right', fontSize: 10 }
        ],
        margin: [40, 10]
      };
    }
  },
  download: 'download',
  includeLabels: true,
  includeGroupHeader: true,
  includeFooter: true,
  fileName: "SerialNumbers.pdf",   
});

关键说明

  • customSettings是jqGrid传递pdfmake底层配置的入口,这里定义的footer函数会在每页渲染时触发,接收currentPage(当前页码)和pageCount(总页数)两个参数。
  • 示例中通过columns将页码放在页脚右侧,你可以根据需求调整对齐方式、字体大小、边距等样式,也可以添加其他自定义文本。
  • pdfmake 0.2.7完全支持这种动态页脚的写法,无需额外依赖。

内容的提问来源于stack exchange,提问作者Beachdog

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 05:47:41