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

Free Support Forum - aspose.com

Horizontal split of table in to new page

Hi Team,

I have a table with some data which does’nt fit in the current page. It cuts the few columns.
It is possible to split the table in horizontal and move it to the new page.


// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
//Instantiate a table object
Aspose.Pdf.Generator.Table mytable = new Aspose.Pdf.Generator.Table();
mytable.Margin.Top = 300;
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(mytable);
//Set with column widths of the table
mytable.ColumnWidths = “100 100 100 100 100 100 100”;
// if you increase the counter to 17, table will break
//because it cannot be accommodated any more over this page
for (int RowCounter = 0; RowCounter <= 50; RowCounter++)
{
//Create rows in the table and then cells in the rows
Aspose.Pdf.Generator.Row row1 = mytable.Rows.Add();
row1.Cells.Add("col " + RowCounter.ToString() + “, 1”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 2”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 3”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 4”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 5”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 6”);
row1.Cells.Add("col " + RowCounter.ToString() + “, 7”);
}
// get the Page Height information
float PageHeight = pdf.PageSetup.PageHeight;
// get the total height information of Page Top & Bottom margin,
// table Top margin and table height.
//float TotalObjectsHeight = section.PageInfo.Margin.Top + section.PageInfo.Margin.Bottom + table1.Margin.Top + table1.GetHeight(pdf);

// pdf.Save(@“D:/pdftest/TableIsBrokenTest.pdf”);
mytable.IsBroken = true;
// add table to paragraphs collection of section
// sec1.Paragraphs.Add(mytable);
// save the resultant PDF document
pdf.Save(@“D:\test\DynamicTableWidth.pdf”);

Hi team,

As i have mentioned in the earlier post. In the table i have few columns (ex 10 columns).The last 2 columns are getting sliced in the pdf. The column column will be dynamically getting prepared.

Is there a way we can push few of the columns which are sliced in pdf 1 pages to the next pages.

Hi Manish,


Thanks for your inquiry. You are using old generator(Aspose.Pdf.Generator). It is recommended to use new generator.I am afraid currently new generator( Aspose.Pdf) does not support breaking table horizontally. We have logged an enhancement ticket PDFNEWNET-38865 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

However, as a workaround you can set Page width as per table width as following. So column will fit on same page.

// Instantiate an object PDF class<o:p></o:p>

Document pdf = new Document();

// add the section to PDF document sections collection

Aspose.Pdf.Page sec1 = pdf.Pages.Add();

//Instantiate a table object

Aspose.Pdf.Table mytable = new Aspose.Pdf.Table();

mytable.Margin.Top = 300;

//Add the table in paragraphs collection of the desired section

sec1.Paragraphs.Add(mytable);

//Set with column widths of the table

mytable.ColumnWidths = "100 100 100 100 100 100 100";

// if you increase the counter to 17, table will break

//because it cannot be accommodated any more over this page

for (int RowCounter = 0; RowCounter <= 50; RowCounter++)

{

//Create rows in the table and then cells in the rows

Aspose.Pdf.Row row1 = mytable.Rows.Add();

row1.Cells.Add("col " + RowCounter.ToString() + ", 1");

row1.Cells.Add("col " + RowCounter.ToString() + ", 2");

row1.Cells.Add("col " + RowCounter.ToString() + ", 3");

row1.Cells.Add("col " + RowCounter.ToString() + ", 4");

row1.Cells.Add("col " + RowCounter.ToString() + ", 5");

row1.Cells.Add("col " + RowCounter.ToString() + ", 6");

row1.Cells.Add("col " + RowCounter.ToString() + ", 7");

}

mytable.IsBroken = true;

sec1.PageInfo.Width = 700 + sec1.PageInfo.Margin.Left + sec1.PageInfo.Margin.Right;

// save the resultant PDF document

pdf.Save(myDir+"DynamicTableWidth.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

The issues you have found earlier (filed as PDFNEWNET-38865) have been fixed in Aspose.Pdf for .NET 10.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.