简体   繁体   English

使用iTextSharp导出为PDF时重复标题行

[英]Repeat header rows when exporting to PDF using iTextSharp

I'm trying to export a table to a pdf document. 我正在尝试将表格导出到pdf文档。

My problem is that the header row is only in the first page, and i can't figure out how to make it repeat. 我的问题是标题行仅在第一页中,我不知道如何使其重复。

Couldn't find a solution online. 找不到在线解决方案。 I'm using ASP.NET and the export to pdf is with iTextSharp. 我正在使用ASP.NET,并且使用iTextSharp导出到pdf。

When creating a PdfPTable object, you can define a row as a header row like this: 创建PdfPTable对象时,可以将一行定义为标题行,如下所示:

table.HeaderRows = 1;

If you need more than one header row, change 1 into another number. 如果需要多个标题行,请将1更改为另一个数字。

If you also need footer rows, you need to be careful. 如果还需要页脚行,则需要小心。 Suppose that you want 2 header rows and 1 footer row, then you need something like this: 假设您想要2个标题行和1个页脚行,那么您需要这样的事情:

table.HeaderRows = 3; // 2 header rows + 1 footer row
table.FooterRows = 1;

I know this is awkward, but there are historical reasons for this. 我知道这很尴尬,但是有历史原因。 You need to set the HeaderRows to the number of all rows that need to be repeated (header and footer rows) and then define the number of actual footer rows. 您需要将HeaderRows设置为需要重复的所有行数(页眉和页脚行),然后定义实际的页脚行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM