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
相关产品推荐
相关产品推荐

