How to paginate the text or table based on the table height?
How to paginate the text or table based on the table height?
The actual table height can be calculated before drawing in the PDF document. Please refer the following example to achieve the above requirements:
C#
// Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
PdfPage pdfPage = pdfDocument.Pages.Add();
// Draw the grid
PdfGrid pdfGridTable = new PdfGrid();
pdfGridTable.RepeatHeader = true;
// Add columns.
pdfGridTable.Columns.Add(2);
// Add header.
pdfGridTable.Headers.Add(1);
PdfGridRow pdfGridHeader1 = pdfGridTable.Headers[0];
pdfGridHeader1.Cells[0].Value = "EMP NAME ";
pdfGridHeader1.Cells[1].Value = "ID";
// Add rows.
for (var i = 0; i < 23; ++i)
{
PdfGridRow pdfGridRow = pdfGridTable.Rows.Add();
pdfGridRow.Cells[0].Value = "Gilbert";
pdfGridRow.Cells[1].Value = "1796";
}
// Draw the PdfGrid.
PdfGridLayoutResult gridResult1 = pdfGridTable.Draw(page, new PointF(0, 10));
// Draw the grid
PdfGrid pdfGrid = new PdfGrid();
pdfGrid.RepeatHeader = true;
// Add columns.
pdfGrid.Columns.Add(2);
// Add header.
pdfGrid.Headers.Add(1);
PdfGridRow pdfGridHeader = pdfGrid.Headers[0];
pdfGridHeader.Cells[0].Value = "EMP NAME ";
pdfGridHeader.Cells[1].Value = "ID";
// Add rows.
for (var i = 0; i < 30; ++i)
{
PdfGridRow pdfGridRow = pdfGrid.Rows.Add();
pdfGridRow.Cells[0].Value = "John";
pdfGridRow.Cells[1].Value = "1795";
}
// Get temp result of PDF grid for header and first row
PdfGridLayoutResult tempResult1 = GettempHeaderandRowLayoutResult(pdfGrid);
float bottom = gridResult1.Bounds.Bottom;
pdfPage = CheckPage(pdfDocument, gridResult1, tempResult1);
if (pdfPage != gridResult1.Page)
{
bottom = 0;
}
// Draw the PdfGrid.
PdfGridLayoutResult gridResult2 = pdfGrid.Draw(pdfPage, new PointF(0, bottom + 10));
pdfDocument.Save("sample.pdf");
pdfDocument.Close(true);
Sample link:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample-1123943813
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion
I hope you enjoyed learning about how to paginate the text or table based on the table height.
You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!