It looks like you need to draw 3 table in a PDF file. And you want also make sure that the second table and the third table are placed in the same page. If that, please try:
1. Please refer our demo Table/TableLayout in our SampleCenter (included in installation package), and draw your first table in doc1, you can get the last page and end point of the first table from a PdfLayoutResult object.
2. Create a temp document to draw the second table and the third table. And you can get the height of your second and third table.
3. If the last page of doc1 has enough space, just draw the temp document to the last page. Otherwise, create a new page and the draw the temp document.
- Code: Select all
PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
tableLayout.Break = PdfLayoutBreakType.FitElement;
tableLayout.Layout = PdfLayoutType.Paginate;
PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
y = result.Bounds.Bottom + 5;
//Create pdf template to layout small tables;
PdfDocument temp = new PdfDocument();
//draw small tables
PdfPageBase tempPage = temp.Pages.Add(page.Canvas.ClientSize, new PdfMargins(0));
PdfLayoutResult result2 = DrawSmallTables(tempPage);
float height = result2.Bounds.Bottom;
if (page.Canvas.ClientSize.Height - y >= height)
{
tempPage.CreateTemplate().Draw(result.Page.Canvas, new PointF(0, y));
}
else
{
page = doc.Pages.Add(PdfPageSize.A4, margin);
tempPage.CreateTemplate().Draw(page, PointF.Empty);
}
A full demo is attached, please check it.
If we missed your requirement again, please provide us your data original and the document expected.
Login to view the files attached to this post.