Multi-page table not rendering correctly

Please see attached sample project with two output pdf files that illustrate how the table renders incorrectly on subsequent pages. I have a production report that essentially uses the same code. This report report worked fine until a week ago when I upgraded to version 7.7 and 7.8 behaves wrong too. Unfortunately I don’t recall which older version was used before the upgrade took place.


In the -200.pdf example you can see on page 2 (even page) that the header row is printed after several data rows have already printed. On page 3 (odd page) the table should have printed several rows higher, there shouldn’t be as much white space between the header and the table.

In the -400.pdf page 2 (even page) is correct but page 3 (odd page) has white space gaps between the header row and the first data row on this page.

This even/odd behavior is what I experience on every even/odd page of my production report.



Hi Mike,

Thanks for using our products.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-35096. We will investigate this issue in details and will keep you updated on the progress.

We apologize for this inconvenient.

I see the status shows FIXED but I don’t see the issue listed in the release log for version 7.9.0. Will this fix be included in the next version?

Hi Mike,


Thanks for your inquiry. Yes you are right, your reported issue has been resolved and issue fix will be included in upcoming release of Aspose.Pdf for .NET 8.0.0. Currently our development team is testing and integrating the build and will publish it soon. We will notify you via this forum thread once it’s released and gets available for download.

Thanks for your patience and cooperation.

Best Regards,

Hi Mike,

In order to generate the correct output, please try using the following code snippet with the upcoming release of Aspose.PDF for .NET 8.0.0.

Document doc = new Document();
Page page = doc.Pages.Add();

// Set pagesize & margins
page.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;
page.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;
page.PageInfo.Margin.Top = 72;
page.PageInfo.Margin.Bottom = 90;
page.PageInfo.Margin.Left = 20;
page.PageInfo.Margin.Right = 20;

page.OnCustomizeHeaderFooter += CustomizeHeaderFooter;
writeReportLines(page, 200);
doc.Save(@"c:/pdftest/LargeTable.pdf");

private static void writeReportLines(Page page, int lines)
{
    Aspose.Pdf.Table table = new Aspose.Pdf.Table();
    page.Paragraphs.Add(table);

    TextState defaultTextState = new TextState();
    defaultTextState.FontSize = 8;

    TextState dateTextState = new TextState();
    dateTextState.FontSize = 8;

    TextState currencyTextState = new TextState();
    currencyTextState.FontSize = 8;

    TextState tableHeaderTextState = new TextState();
    tableHeaderTextState.FontSize = 8;
    tableHeaderTextState.Font = FontRepository.FindFont("Times-Bold");

    table.DefaultCellTextState = defaultTextState;
    table.ColumnWidths = "30 285 40 40 35 35 35 35";
    table.RepeatingRowsCount = 1;

    Aspose.Pdf.Row headerRow = table.Rows.Add();
    headerRow.DefaultCellTextState = tableHeaderTextState;
    headerRow.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom, (float)0.5);
    headerRow.Cells.Add("SKU");
    headerRow.Cells.Add("Product");
    headerRow.Cells.Add("Effective Date");
    headerRow.Cells.Add("End Date");
    headerRow.Cells.Add("FOB");
    headerRow.Cells.Add("Freight");
    headerRow.Cells.Add("Tax");
    headerRow.Cells.Add("Total");

    for (int i = 0; i < lines; i++)
    {
        Aspose.Pdf.Row tableRow = table.Rows.Add();
        tableRow.Cells.Add("01234");
        tableRow.Cells.Add("Product Name - Lines: " + lines.ToString());
        tableRow.Cells.Add("01/01/13");
        tableRow.Cells.Add("02/28/13");
        tableRow.Cells.Add("50.00");
        tableRow.Cells.Add("5.00");
        tableRow.Cells.Add("3.00");
        tableRow.Cells.Add("58.00");
    }

    table.SetColumnTextState(2, dateTextState, Aspose.Pdf.HorizontalAlignment.Center);
    table.SetColumnTextState(3, dateTextState, Aspose.Pdf.HorizontalAlignment.Center);
    table.SetColumnTextState(4, currencyTextState, Aspose.Pdf.HorizontalAlignment.Right);
    table.SetColumnTextState(5, currencyTextState, Aspose.Pdf.HorizontalAlignment.Right);
    table.SetColumnTextState(6, currencyTextState, Aspose.Pdf.HorizontalAlignment.Right);
    table.SetColumnTextState(7, currencyTextState, Aspose.Pdf.HorizontalAlignment.Right);
}

private static Aspose.Pdf.HeaderFooter getFirstPageHeader()
{
    Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
    header.Margin.Top = 10;
    Aspose.Pdf.Table table = new Aspose.Pdf.Table();

    double headerWidth = Aspose.Pdf.PageSize.PageLetter.Width - 20 - 20; // width without margin
    table.ColumnWidths = headerWidth.ToString();

    Aspose.Pdf.Row row = table.Rows.Add();
    Aspose.Pdf.Cell cell = row.Cells.Add();

    // Add document title
    TextFragment title = new TextFragment("PDF Report");
    title.TextState.Font = FontRepository.FindFont("Times-Bold");
    title.TextState.FontSize = 16;
    cell.Alignment = Aspose.Pdf.HorizontalAlignment.Center;
    cell.Paragraphs.Add(title);

    row = table.Rows.Add();
    cell = row.Cells.Add();

    // Add distributor name
    TextFragment text = new TextFragment("Customer Name");
    text.TextState.Font = FontRepository.FindFont("Times-Bold");
    text.TextState.FontSize = 12;
    cell.Alignment = Aspose.Pdf.HorizontalAlignment.Left;
    cell.Paragraphs.Add(text);

    row = table.Rows.Add();
    cell = row.Cells.Add();

    text = new TextFragment("Effective: 01/01/2013 - 06/30/2013");
    text.TextState.Font = FontRepository.FindFont("Times-Bold");
    text.TextState.FontStyle = FontStyles.Bold;
    text.TextState.FontSize = 10;
    cell.Alignment = Aspose.Pdf.HorizontalAlignment.Right;
    cell.Paragraphs.Add(text);

    text = new TextFragment("Date Printed: 04/01/2013 2:00 PM");
    text.TextState.Font = FontRepository.FindFont("Times-Bold");
    text.TextState.FontSize = 10;
    cell.Paragraphs.Add(text);
    cell.Alignment = Aspose.Pdf.HorizontalAlignment.Right;

    header.Paragraphs.Add(table);
    return header;
}

private static Aspose.Pdf.HeaderFooter getAdditionalPageHeader()
{
    Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
    header.Margin.Top = 36;
    Aspose.Pdf.Table table = new Aspose.Pdf.Table();

    double headerWidth = Aspose.Pdf.PageSize.PageLetter.Width - 20 - 20; // width without margin
    table.ColumnWidths = headerWidth.ToString();

    Aspose.Pdf.Row row = table.Rows.Add();
    Aspose.Pdf.Cell cell = row.Cells.Add();

    TextFragment text = new TextFragment("Customer Name");
    text.TextState.Font = FontRepository.FindFont("Times-Bold");
    text.TextState.FontSize = 12;
    cell.Paragraphs.Add(text);
    cell.Alignment = Aspose.Pdf.HorizontalAlignment.Center;

    header.Paragraphs.Add(table);
    return header;
}

public void CustomizeHeaderFooter(ref Aspose.Pdf.HeaderFooter header, ref Aspose.Pdf.HeaderFooter footer, int pageNum)
{
    if (pageNum == 1)
    {
        header = getFirstPageHeader();
    }
    else
    {
        header = getAdditionalPageHeader();
    }
}

The issues you have found earlier (filed as PDFNEWNET-35096) have been fixed in Aspose.Pdf for .NET 8.0.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.