How to control page break

Hi, I whant to make a report in pdf.

The report should like

Title

Section

Label Data
Label Data

Section

Label Data
Label Data

Section

Table with 0 to n row

Title

etc...

My problem is sometime my Title is at end of the page and It's not what we want.

My document have one section.

Title are text in a paragraph

Section and Label/Data or Table are in a table inside a paragraphe

I try to use IsKeptWithNext with the paragraph of Title but doesn't seem to work (because next paragraph is Table???)

Do you have some idea how to do that?

It's is possible before crate a paragraph to know where I am on the page?

Some other people seem to like it https://forum.aspose.com/t/134580

Thank's a lot

Hello Stephane,

Thanks for using our products.

Do you need to display/start the Title text over separate page ? Which means if the previous table occupies the whole page or if there is any space left, Title must start from new page. If so is the case, please try using Text.IsFirstParagraph = true; property. Please take a look over the attached PDF document that I have generated using following code snippet

[C#]

// Create PDF object
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
// create section object and add it to sections collection of Pdf object
Aspose.Pdf.Section section = pdf.Sections.Add();
for (int section_count = 0; section_count <= 2; section_count++)
{
// create title text for the PDF
Aspose.Pdf.Text Title_Text = new Aspose.Pdf.Text("General Information");
Title_Text.IsFirstParagraph = true;
// specify the font size information for the text object
Title_Text.TextInfo.FontSize = 18;
// specify font face information
Title_Text.TextInfo.FontName = "Arial";
// add the text object ot paragraphs collection of section
section.Paragraphs.Add(Title_Text);
// specify the Bottom margin information for text object
Title_Text.Margin.Bottom= 10;

// Create table with 2 Rows and 3 Columns
DataTable(section, "Section", 2, 3);
// Create table with 3 Rows and 2 Columns
DataTable(section, "Section2", 3, 2);
}
// Save the resultant PDF
pdf.Save(@"d:/pdftest/PageBreak_Test.pdf");

internal void DataTable(Section Main_Section, String Table_Title, int Row_Count, int Column_Count)
{
// Add heading before table object
Text Table_Heading = new Text(Table_Title);
// specify the text formatting information for Heading
Table_Heading.TextInfo.FontSize = 16;
Table_Heading.TextInfo.IsUnderline= true;
Table_Heading.TextInfo.FontName = "Arial";
// specify the top margin information for text object
Table_Heading.Margin.Top = 20;
// add the Text object to paragraphs collection of section
Main_Section.Paragraphs.Add(Table_Heading);

// create table object
Table My_Data_table = new Table(Main_Section);
// Add table to paragraphs collection of section
Main_Section.Paragraphs.Add(My_Data_table);
//Set default cell border using BorderInfo object
My_Data_table.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F,new Aspose.Pdf.Color("Blue"));
//Set table border using another customized BorderInfo object
My_Data_table.Border = new BorderInfo((int)BorderSide.All, 0.1F,new Aspose.Pdf.Color("Blue"));
// specify the column count information for table. It will changed later on when creating table cells
My_Data_table.ColumnWidths = "100";
// specify table top margin informtion from heading object
My_Data_table.Margin.Top = 20;
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
My_Data_table.DefaultCellPadding = margin;

// create number of rows and columns for table based over input
for (int Row_Counter=1; Row_Counter <= Row_Count; Row_Counter++)
{
// crate Row object and add it to table
Row DataRow = new Row(My_Data_table);
// add row to table object
DataRow.DefaultCellTextInfo.FontName = "Arial";
My_Data_table.Rows.Add(DataRow);
for (int Column_Counter = 1; Column_Counter <= Column_Count; Column_Counter++)
{
// set the Column width information for table cells
My_Data_table.SetColumnWidth(Column_Counter, 100);
// create column and add it to table row
Cell DataCell = new Cell(DataRow);
DataRow.Cells.Add(DataCell);
// add sample text to table cell
DataCell.Paragraphs.Add(new Text("Data in Cell " + Row_Counter.ToString() + ", " + Column_Counter.ToString()));
}
}
}

In case I have not properly understood your requirement, please share some more details. We apologize for your inconvenience.

No I don't want the section Title to be alway on a new page. It depend, I can say that

if the Title begin in the 2/3 of the page Then
I whant to begin a new page
Else
Continue to the same page

For now I add checkbox in a confirmation page to ask user If he want new page for my section, but I like to make it automatic.

It is more clear?

Hello Stephane,

Thanks for your patience and sorry for replying you late.

We are looking into the details of this requirement and will get back to you soon. We apologize for the delay and inconvenience.

We tried to achieve something like that on some of our sections and the workaround we have used is to put the Section title and the table below in 1 table that cannot be broken.


Hope this helps,

Jean-François Rouleau

Hi Jean-François,


Thanks for sharing the solution. We hope that this information will be helpful to other users who might encounter similar problem.