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.

Thu Jul 16, 2020 8:21 am

Hi

i am creating a grid on a PFD page and have added a header row. I am trying to make the header row repeat when there is a page break but cant seem to get that to work. Bleow is code snippet.

Code: Select all
 newGrid.AllowCrossPages = true;
                   
                    rowIndex = 0;
                    newGrid.Columns.Add(colCount);
                    PdfGridRow headerRow = newGrid.Headers.Add(1)[0];

                   
                    float totalWidth = page.Canvas.ClientSize.Width;

                    for (int c = 0; c < colCount; c++)
                    {
                        headerRow.Cells[c].Value = "Test";

                        newGrid.Columns[c].Format.Alignment = PdfTextAlignment.Center;
                        newGrid.Columns[c].Width = totalWidth * colWidths[c];
                    }
                    newGrid.RepeatHeader = true;

license.manager
 
Posts: 12
Joined: Thu Jul 09, 2015 11:07 am

Thu Jul 16, 2020 9:55 am

Hello,

Thanks for your post.
I tested the below code with the latest Spire.Office Platinum(Hotfix) Version:5.7.3 but found that header row was repeated when there was a page break. Attached is my output file.
Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            PdfGrid newGrid = new PdfGrid();
            newGrid.Columns.Add(3);
            float width = page.Canvas.ClientSize.Width - (newGrid.Columns.Count + 1);
            for (int j = 0; j < newGrid.Columns.Count; j++)
            {
                newGrid.Columns[j].Width = width * 0.20f;
            }

            newGrid.AllowCrossPages = true;

            //Add header row
            PdfGridRow headerRow = newGrid.Headers.Add(1)[0];
            float totalWidth = page.Canvas.ClientSize.Width;

            for (int c = 0; c < 3; c++)
            {
                headerRow.Cells[c].Value = "Test";
                newGrid.Columns[c].Format.Alignment = PdfTextAlignment.Center;
            }

            //Repear header
            newGrid.RepeatHeader = true;

            for (int c = 0; c < 100; c++)
            {
                PdfGridRow row = newGrid.Rows.Add();
                row.Height = 20.0f;
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true);
                row.Cells[0].Value = "Column 1";
                row.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                row.Cells[1].Value = "Column 2";
                row.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                row.Cells[2].Value = "Column 3";
                row.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            }         
            newGrid.Draw(page, new PointF(0, 50));

            doc.SaveToFile("result.pdf");

If you are using an older version, please try again with the latest version. Or if your code is different from mine, please provide your complete code for further investigation.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Jul 17, 2020 8:18 am

Thanks, i discovered that my grid on second page was actually a separate grid hence why it wouldn't repeat

license.manager
 
Posts: 12
Joined: Thu Jul 09, 2015 11:07 am

Fri Jul 17, 2020 8:37 am

Hello,

Thanks for your feedback. Feel free to contact us if you need further assistance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF