We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Need to insert a page break when I have multiple tables in a page

I know that ASPOSE.PDF have an option for table row to start from a new page, but I wanted to insert a page break as I am having 2 diff tables in a page which need to be together when I say 1st table row to start in new page the 2nd one is continuing in the previous page and vice-versa for the other. I have attached the pdf which I generated using ASPOSE. image.png (95.6 KB)
I want to insert a page break after the yellow line

IL Quarterly Monthly Wage Report_01082020_170023.pdf (366.6 KB)

@GaneshGowru

Thanks for contacting support.

Would you kindly share a narrowed down code sample that you have used to add tables in the shared PDF document. We will test the scenario in our environment and share our feedback accordingly.

Hi, bellow is the method to write the pdf body

///


/// To Append MultipleTables each contains a prebody, body and footer
///

public override void AppendMultiTableBodyWithInternalTable()
{
prevColumnWidth = string.Empty;
currentColumnWidth = string.Empty;
string prevPreBodyColumnWidth = string.Empty;
string currentPreBodyColumnWidth = string.Empty;
if (MultiTableReportData?.MultiTableBodyDataRowColumns != null && MultiTableReportData?.MultiTableBodyDataRowColumns?.Count > 0)
{
var documentTables = MultiTableReportData.MultiTableBodyDataRowColumns.OrderBy(x => x.TableSequence).GroupBy(x => x.TableName).Select(c => c.ToList()).ToList();
bool firstTable = true;
foreach (List documentTable in documentTables)
{
DocumentTable currentTable = MultiTableReportData.MultiTableDataRowHeaders.Where(x => x.TableName == documentTable.First().TableName).FirstOrDefault();
currTable = currentTable.TableName;
List currentSubTables = new List();

                currentSubTables = MultiTableReportData.SubTables?.Where(x => x.ParentTable == currTable).ToList();

                if (currentTable?.BodyRowColumns.Count(x => x.HasSubColumns) > 0)
                {
                    FormatParentRow(bodyHeaderRow, currentTable.BodyRowColumns.Where(x => x.ParentColumnPosition == null).ToList(),
                        currentTable.BodyRowColumns.Count(x => x.ParentColumnPosition != null));
                    AddRow(tblBodyData, bodyHeaderRow);

                    bodyHeaderRow = new Row();
                    currentTable.BodyRowColumns.ToList().ForEach(delegate (DocumentColumn column)
                    {
                        column.ColumnData = column.ParentColumnPosition == null ? string.Empty : column.ColumnData;
                    });
                    FormatRow(bodyHeaderRow, currentTable.BodyRowColumns.Where(x => x.HasSubColumns != true).ToList());
                    AddRow(tblBodyData, bodyHeaderRow);
                }
                else
                {
                    bodyHeaderRow = new Row();
                    currentColumnWidth = FormatRow(bodyHeaderRow, currentTable?.BodyRowColumns);
                    if (prevColumnWidth != currentColumnWidth)
                    {
                        tblBodyData = InitializeBodyDataTable(currentColumnWidth);
                    }
                    if (currentTable.RepeatPreBody)
                    {
                        foreach (var item in currentTable.PreBodyColumns)
                        {
                            var columnsList = (List<DocumentColumn>)item;
                            preTablebodyRow = new Row { FixedRowHeight = 15 };
                            FormatRow(preTablebodyRow, columnsList);
                        }
                        AddRow(tblBodyData, preTablebodyRow);
                    }
                    else
                    {
                        if (currentTable.PreBodyColumns != null && currentTable.PreBodyColumns.Count > 0)
                        {
                            _margin = new MarginInfo(-50, 0, 0, 15);
                            if (firstTable)
                            {
                                _margin = new MarginInfo(-50, 0, 0, 0);
                            }
                            tblPreBodyData = null;
                            foreach (var item in currentTable.PreBodyColumns)
                            {
                                var columnsList = (List<DocumentColumn>)item;
                                preTablebodyRow = new Row { FixedRowHeight = 10 };
                                currentPreBodyColumnWidth = FormatRow(preTablebodyRow, columnsList);
                                if (tblPreBodyData == null || prevPreBodyColumnWidth != currentPreBodyColumnWidth)
                                {
                                    if (tblPreBodyData != null)
                                    {
                                        AddParagraph(document.Pages[1], tblPreBodyData);
                                        _margin = new MarginInfo(-50, 0, 0, 0);
                                    }
                                    tblPreBodyData = InitializeTable(currentPreBodyColumnWidth, _margin);
                                }
                                prevPreBodyColumnWidth = currentPreBodyColumnWidth;
                                AddRow(tblPreBodyData, preTablebodyRow);
                            }
                            AddParagraph(document.Pages[1], tblPreBodyData);
                        }
                    }

                    if (!string.IsNullOrEmpty(prevTable) && prevTable != currTable)
                    {
                        bodyHeaderRow.IsInNewPage = currentTable.IsMultipleTablesInNewPage;
                    }
                    

                    AddRow(tblBodyData, bodyHeaderRow);
                }

                if (currentSubTables != null && currentSubTables.Count > 0)
                {
                    prevSubColumnWidth = currentSubColumnWidth;

                    foreach (var subTable in currentSubTables)
                    {
                        #region SubTable Header
                        bodyHeaderRow = new Row();
                        currentSubColumnWidth = FormatRow(bodyHeaderRow, subTable?.Header);
                        tblBodyData = InitializeBodyDataTable(currentColumnWidth);
                        AddRow(tblBodyData, bodyHeaderRow);
                        #endregion

                        #region SubTable PreBody
                        if (subTable.PreBody != null && subTable.PreBody.Count > 0)
                        {
                            _margin = new MarginInfo(-50, 0, 0, 10);
                            tblPreBodyData = null;
                            foreach (var item in subTable.PreBody)
                            {
                                var columnsList = (List<DocumentColumn>)item;
                                preTablebodyRow = new Row { FixedRowHeight = 10 };
                                currentPreBodyColumnWidth = FormatRow(preTablebodyRow, columnsList);
                                if (tblPreBodyData == null || prevPreBodyColumnWidth != currentPreBodyColumnWidth)
                                {
                                    if (tblPreBodyData != null)
                                    {
                                        AddParagraph(document.Pages[1], tblPreBodyData);
                                        _margin = new MarginInfo(-50, 0, 0, 0);
                                    }
                                    tblPreBodyData = InitializeTable(currentPreBodyColumnWidth, _margin);
                                }
                                prevPreBodyColumnWidth = currentPreBodyColumnWidth;
                                AddRow(tblPreBodyData, preTablebodyRow);
                            }
                            AddParagraph(document.Pages[1], tblPreBodyData);
                        }
                        #endregion

                        #region SubTable Body
                        if (subTable.Data != null && subTable.Data.Count > 0)
                        {
                            foreach (var record in subTable.Data)
                            {
                                var columnsList = (List<DocumentColumn>)record;
                                bodyDataRow = new Row { FixedRowHeight = BodyDataRowHeight };
                                FormatRow(bodyDataRow, columnsList);
                                AddRow(tblBodyData, bodyDataRow);
                            }
                            AddParagraph(document.Pages[1], tblBodyData);
                        }
                        #endregion

                        #region SubTable Footer
                        if (subTable.Footer != null && subTable.Footer.Count > 0)
                        {
                            tblBodyTotal = null;
                            foreach (var footer in subTable.Footer)
                            {
                                AddFooterExtensionTableData((List<DocumentColumn>)footer, new MarginInfo(-50, 0, 0, 0));
                            }
                            AddParagraph(document.Pages[1], tblBodyTotal);
                        }
                        #endregion
                    }
                }
                else
                {
                    foreach (var record in documentTable)
                    {
                        var columnsList = (List<DocumentColumn>)record.BodyRowColumns;
                        bodyDataRow = new Row { FixedRowHeight = BodyDataRowHeight };
                        FormatRow(bodyDataRow, columnsList);
                        AddRow(tblBodyData, bodyDataRow);
                    }
                    AddParagraph(document.Pages[1], tblBodyData);
                }

                if (currentTable?.FooterRowColumns != null && currentTable.FooterRowColumns.Count > 0)
                {
                    AddFooterTableData((List<DocumentColumn>)currentTable?.FooterRowColumns);
                }

                if (currentTable?.FooterExtension != null && currentTable.FooterExtension.Count > 0)
                {
                    tblBodyTotal = null;
                    foreach (var footer in currentTable?.FooterExtension)
                    {
                        AddFooterExtensionTableData((List<DocumentColumn>)footer);
                    }
                    AddParagraph(document.Pages[1], tblBodyTotal);
                }
                firstTable = false;
                prevTable = currTable;
            }

            if (MultiTableReportData.FooterRowColumns != null && MultiTableReportData.FooterRowColumns.Count > 0)
            {
                AddFooterTableData((List<DocumentColumn>)MultiTableReportData.FooterRowColumns);
            }

            if (MultiTableReportData.PageFooterExtension != null && MultiTableReportData.PageFooterExtension.Count > 0)
            {
                tblBodyTotal = null;
                foreach (var footer in MultiTableReportData.PageFooterExtension)
                {
                    AddFooterExtensionTableData((List<DocumentColumn>)footer);
                }
                AddParagraph(document.Pages[1], tblBodyTotal);
            }
        }
    }

@GaneshGowru

Thanks for sharing code snippet.

Regretfully, the required functionality is not present in the API at the moment. However, we have logged an enhancement request as PDFNET-47654 in our issue tracking system. We will definitely investigate the feasibility of your requirements and keep you posted with the status of feature implementation. Please spare us some time.

Furthermore, there are some undefined Classes and objects in the code snippet that you have shared. Would you kindly share a sample code snippet with dummy data that can show us how you are generating PDF with two parallel tables? This would help us in investigating the scenario accordingly.