TableOverflow with different header and footer

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v4)  /  Re: TableOverflow with different header and footer

DynamicPDF Generator for .NET (v4) Forum

I have the following document setup

First Page
HeaderType1(only on first page)
     Table data starts, could be 100 pages long
FooterType1

SecondPage to Second Last page
HeaderType2 (on all pages except first page)
      continuation of table data rows
FooterType1

LastPage
HeaderType2(on all pages except first page)
      continuation of table data rows
      Final Summary information added that could span several pages(should this be a new table or add into the existing tables rows?)
FooterType1

I am very confused how to set this up. Right now i hard code how many rows per page for the table data but i don't like that. It also messes up when the last page arrives and i don't know how long the Final Summary information would be.

If you could give me a clear example of how to set this up it would be greatly appreciated.

Cheers
Posted by a ceTe Software moderator
Hello,

Yes, you can create a PDF as you described above without any problem using our Generator product. Can you please send a mail to our Support Team so that they can send you some sample example for this.

Thanks,
ceTe Software Support Team.
Can you send me an example of code for the issue mentioned in the previous post?
Posted by a ceTe Software moderator
Hello,

Here is the code sample you requested.

            float x = 0;
            float y = 0;
            float span = 20;
            float headerGap = 30;
            Document document = new Document();
            Page page = new Page();

            Label footer = new Label("Footer Type 1", x, page.Dimensions.Body.Height - span, 200, 20);
            Template footerTemplate = new Template();
            footerTemplate.Elements.Add(footer);
            document.Template = footerTemplate;

            Label header = new Label("Header Type 1", x, y, 200, 20);
            y += headerGap;
            page.Elements.Add(header);

            Table2 table = new Table2(x, y, 200, 200);
            table.Columns.Add(100);
            table.Columns.Add(100);
            for (int i = 0; i < 100; i++)
            {
                Row2 row = table.Rows.Add();
                row.Cells.Add("Row " + (i + 1) + "; Cell 1");
                row.Cells.Add("Row " + (i + 1) + "; Cell 2");
            }

            if (page.Dimensions.Body.Height - 60 < table.GetRequiredHeight())
                table.Height = page.Dimensions.Body.Height - 60;
            else
                table.Height = table.GetRequiredHeight();
            page.Elements.Add(table);
            table = table.GetOverflowRows();
            document.Pages.Add(page);

            y = 0;
            Label header1 = new Label("Header Type 2", x, y, 200, 20);
            y += headerGap;
            Template header1Template = new Template();
            header1Template.Elements.Add(header1);

            Section section1 = document.Sections.Begin();
            section1.Template = header1Template;
            float lastY = 0;
            do
            {
                page = new Page();
                if (page.Dimensions.Body.Height - 60 < table.GetRequiredHeight())
                    table.Height = page.Dimensions.Body.Height - 60;
                else
                    table.Height = table.GetRequiredHeight();
                page.Elements.Add(table);
                document.Pages.Add(page);
                lastY = table.Height + headerGap + span;

                table = table.GetOverflowRows();
            } while (table != null);

            Table2 summary = new Table2(x, lastY, 400, 200);
            summary.Columns.Add(200);
            summary.Columns.Add(200);
            for (int i = 0; i < 2; i++)
            {
                Row2 row = summary.Rows.Add();
                row.Cells.Add("Summary Row " + (i + 1) + "; Summary Cell 1");
                row.Cells.Add("Summary Row " + (i + 1) + "; Summary Cell 2");
            }

            page.Elements.Add(summary);

            document.Draw("output.pdf");

All times are US Eastern Standard time. The time now is 4:22 AM.