Tue Oct 11, 2016 7:00 pm
Hi
protected float AddTableToDocOnPage(ReportTable table, float offset)
{
PdfLayoutResult result;
if(table.InsufficientSpaceOnPage(PdfDocumentSettings))
{
AddNewPage();
}
try
{
result = table.Draw(PdfDocumentSettings.CurrentPage, new PointF(0, PdfDocumentSettings.VerticalPosition));
}
catch (PdfTableException)
{
// In the unlikely event where the Spire library determines there is not enough space to print the table on the page
// and throws an exception, add a new page and print the table again
// Note: this will result in the header being displayed on the previous page unecessarily
AddNewPage();
result = table.Draw(PdfDocumentSettings.CurrentPage, new PointF(0, PdfDocumentSettings.VerticalPosition));
}
float tableSize = result.Bounds.Height;
int pageIndex = PdfDocumentSettings.Document.Pages.IndexOf(PdfDocumentSettings.CurrentPage);
int maxIndex = PdfDocumentSettings.Document.Pages.Count - 1;
if(pageIndex < maxIndex)
{
PdfDocumentSettings.CurrentPage = PdfDocumentSettings.Document.Pages[maxIndex];
PdfDocumentSettings.VerticalPosition = 10;
}
PdfDocumentSettings.VerticalPosition += (tableSize + offset);
return PdfDocumentSettings.VerticalPosition;
}