private MemoryStream RenderDocument(ReportTable reportTable)
 {
     PdfWriter.PageEvent = new PageEventHelper {
         Report = this
     };
     PdfDocument.Open();
     reportTable.RenderTable(PdfDocument, PdfWriter);
     PdfDocument.Close();
     PdfWriter.Flush();
     return(PdfStream);
 }
        // Method to get the pdf stream
        public MemoryStream GetPdf <T>(List <T> data, List <ReportColumn> displayColumns)
        {
            InitiateDocument();

            // Add the report data
            var top = (HeaderSectionHeight == 0)
                          ? PdfDocument.PageSize.Height - PdfDocument.TopMargin
                          : PdfDocument.PageSize.Height - PdfDocument.TopMargin
                      - HeaderSectionHeight - 10;
            var reportTable = ReportTable.CreateReportTable <T>(data,
                                                                displayColumns, top, PdfDocument);

            PageCount = reportTable.PageCount;

            return(RenderDocument(reportTable));
        }
        // Static method to create & return an instance object
        public static ReportTable CreateReportTable <T>(List <T> data,
                                                        List <ReportColumn> displayColumns, float top, Document document)
        {
            // Construct an instance object
            var reportTable = new ReportTable(displayColumns, document, top);
            var type        = typeof(T);

            // Add each data item into the PdfPTable.
            int   srartRow     = 0;
            int   pageRowIndex = 0;
            float headerHeight = reportTable.headerTable.GetRowHeight(0);
            float actualHeight = headerHeight;

            for (int i = 0; i < data.Count; i++)
            {
                var       dataItem = data[i];
                BaseColor color    = (pageRowIndex++ % 2 == 0)
                    ? BaseColor.LIGHT_GRAY : BaseColor.WHITE;

                AddRow(dataItem, type, displayColumns, color, reportTable.dataTable);

                actualHeight = actualHeight + reportTable.dataTable.GetRowHeight(i);
                var lastRowReached = i == data.Count - 1;
                if ((actualHeight > reportTable.height) || lastRowReached)
                {
                    reportTable.pageSplitter.Add(new Tuple <int, int>(srartRow,
                                                                      lastRowReached ? -1 : i));

                    if (!lastRowReached)
                    {
                        reportTable.dataTable.DeleteLastRow();
                        AddRow(dataItem, type, displayColumns, BaseColor.LIGHT_GRAY,
                               reportTable.dataTable);
                        pageRowIndex = 1;
                    }

                    actualHeight = headerHeight + reportTable.dataTable.GetRowHeight(i);
                    srartRow     = i;
                }
            }

            return(reportTable);
        }