I have a form generated by FPDF which creates multiple rows based on the client's payment records. I want it to create a bottom border when it has finished creating the last row in the current page. (See below, just above the page number) Is there an FPDF function for this?
My Answer:
Yes, you can achieve this by using the `SetDrawColor()` and `Rect()` functions in FPDF. Here's an example of how you can add a bottom border to a table before moving to the next page:
php
// Set the draw color to black
$pdf->SetDrawColor(0, 0, 0);
// Add a bottom border to the last row of the table
$pdf->Rect($startX, $startY, $width, $height, 'B');
// Check if the next row will fit on the current page
if ($pdf->GetY() + $rowHeight > $pdf->GetPageHeight() - $bottomMargin) {
// Add a bottom border to the last row on the current page
$pdf->Rect($startX, $startY, $width, $height, 'B');
// Add a new page
$pdf->AddPage();
// Reset the Y position for the new page
$pdf->SetY($topMargin);
} else {
// Move to the next row
$pdf->Ln($rowHeight);
}
In this example, `$startX`, `$startY`, `$width`, and `$height` represent the coordinates and dimensions of the last row in your table. You can adjust these values based on your specific table layout. The `'B'` parameter in the `Rect()` function specifies that you want to draw a bottom border.
By checking if the next row will fit on the current page, you can add a bottom border to the last row on the current page before moving to the next page. This will ensure that the bottom border is only added when necessary.
Rate this post
4 of 5 based on 7874 votesComments