Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Jun 04, 2024 8:53 pm

Issue_RepeatHeader.zip
Hi,

I am currently facing an issue with the RepeatHeader property while generating a PDF. The problem occurs when I generate a PDF for printing a table that spans multiple pages. We expected the table header to repeat on each new page using the RepeatHeader property. However, as demonstrated in the code below, when a row is split between pages, the table header does not appear on the new page.

I´ve attached some files to help you understand and simulate the issue:
- spire.pdf test code.txt: code to reproduce the issue;
- test spire.pdf.pdf: pdf generated by the code, showing the issue;
- Explanation.pdf: visual explanation of the issue

Some addicional information:

- version used: Spire.Pdf for .NET 10.6.0
- Environment: Visual Studio 2022 Professional + Windows 10 Pro 64 bits
- .NET Framework 4.8

Thank you for your assistance!

Tribunalcontasrj
 
Posts: 6
Joined: Tue May 18, 2021 9:07 pm

Wed Jun 05, 2024 3:18 am

Hello,

Thanks for your inquiry.
Actually, there is nothing wrong with the test code and results you provided. Because the last cell at the page break has too much content, the extra content will be displayed on the next page. In this case, the cells are actually continuous, so the header will not be repeated. You can verify this by commenting out the "test = test + " test";" in your code. If you have any questions, please feel free to write back.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Wed Jun 05, 2024 1:25 pm

Hello William.Zhang,

Thank you for your previous response. However, the behavior described is indeed undesirable for our use case, where we need to ensure that the table header is repeated on all pages.

I would like to know if there is any way to work around this issue. For instance, is it possible to implement a check to identify when the content of a row does not fit on the current page (which would cause it to split), and then force a page break before this happens, thereby ensuring the header is correctly repeated on the next page? Or, if this suggestion is not possible, another solution/workaround?

Any guidance or code examples you could provide to resolve this issue would be greatly appreciated.

Thank you in advance for your attention and support.

Best regards,
Tribunalcontasrj

Tribunalcontasrj
 
Posts: 6
Joined: Tue May 18, 2021 9:07 pm

Thu Jun 06, 2024 2:36 am

Hello,

Thanks for your feedback.
Sorry, there is currently no way to meet your needs. However, I have submitted your requirements to our dev team with ticket SPIREPDF-6816. They will further investigate whether there is a suitable solution. I will inform you as soon as there is any progress. Thank you for your understanding.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Fri Jun 28, 2024 8:56 am

Hello,

Thank you for your patience.
Glad to inform that we just releasedSpire.PDF Pack(Hot Fix) Version:10.6.25 which fixed the issue of SPIREPDF-6816, welcome to test it.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/
Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(15), PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);
PdfGrid grid = new PdfGrid();
PdfTrueTypeFont boldFont = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
PdfBrush brush = PdfBrushes.LightSlateGray;
grid.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Regular), true);
grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
grid.Columns.Add(2);
grid.Columns[0].Width = 75.5f;
grid.Columns[1].Width = 135.5f;
PdfGridRow[] header = grid.Headers.Add(1);
header[0].Cells[0].Value = "Column1";
header[0].Cells[1].Value = "Column2";
for (int i = 0; i < header[0].Cells.Count; i++)
{
    header[0].Cells[i].Style.BackgroundBrush = brush;
    header[0].Cells[i].Style.Font = boldFont;
}
grid.RepeatHeader = true;
string test = "test";
for (int i = 0; i < 205; i++)
{
    PdfGridRow row = grid.Rows.Add();
    row.Cells[0].Value = i.ToString();
    row.Cells[1].Value = test;
    test = test + " test";
}

PdfGridLayoutFormat gridLayout = new PdfGridLayoutFormat();
gridLayout.PaginateBounds = new RectangleF(0, 115, page.Size.Width, page.Size.Height);
PdfLayoutResult result = grid.Draw(page, new PointF(0, 115), gridLayout);
doc.SaveToFile("res.pdf", FileFormat.PDF);

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron