Different Table Margins on First Page

How would I achieve a different first page layout with a table that spans multiple pages? I’d like to have a report header and footer on the first page, and then have the table fill the next pages. The page break system is working well for me, but I need to be able to control the first page.

Also, on a side note, it’s more complicated than this. I am using a nested table to solve row grouping and repeating headers. Each row has variable content so the heights of each may be different.

Aspose.PDF .NET 18.9.1

Thanks.

@dirq

Thank you for contacting support.

We would like to share with you that a page which is inserted into Page Collection of a Document when a table overflows from first page, has the same properties as the Parent page on which the table overflow occurs. For instance, if table overflow occurs on the first page then a page will be inserted right after this page and it will have same margins and other properties as previous page. So, we are afraid you may not set different margins on the pages which contain a table that overflows.

Below code snippet well explains the behavior of page insertion. 2nd page in the document has page margins set to zero, but this page becomes Page 3/3 when 2nd page is inserted into the document because of table overflow.

        Document document = new Document();
        var page1 = document.Pages.Add();
        var page2 = document.Pages.Add();

        page1.PageInfo.Margin = new MarginInfo(72, 72, 72, 72);
        //This page2 will become page 3/3 in PDF document when a page is inserted in between, by the API.
        page2.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
        
        // Create header
        TextStamp headerStamp = new TextStamp("Header Text");
        // Set properties of the stamp
        headerStamp.TopMargin = 10;
        headerStamp.HorizontalAlignment = HorizontalAlignment.Center;
        headerStamp.VerticalAlignment = VerticalAlignment.Top;
        // Add header on the page
        page1.AddStamp(headerStamp);
        
        page2.Paragraphs.Add(new TextFragment("SAMPLE PARAGRAPH"));

        TextStamp footerStamp = new TextStamp("Footer Text");
        // Set properties of the stamp
        footerStamp.BottomMargin = 10;
        footerStamp.HorizontalAlignment = HorizontalAlignment.Center;
        footerStamp.VerticalAlignment = VerticalAlignment.Bottom;
        // Add footer on the page
        page1.AddStamp(footerStamp);

        // Initializes a new instance of the Table
        Aspose.Pdf.Table table = new Aspose.Pdf.Table();
        // Set the table border color as LightGray
        table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
        // Set the border for table cells
        table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
        // Create a loop to add 100 rows
        for (int row_count = 1; row_count < 100; row_count++)
        {
            // Add row to table
            Aspose.Pdf.Row row = table.Rows.Add();
            // Add table cells
            row.Cells.Add("Column (" + row_count + ", 1)");
            row.Cells.Add("Column (" + row_count + ", 2)");
            row.Cells.Add("Column (" + row_count + ", 3)");
        }
        // Add table object to first page of input document
        page1.Paragraphs.Add(table);

        document.Save(dataDir + "Margin_18.9.1.pdf");

We hope this clarifies our explanation. Please feel free to contact us if you need any further details.