A data set is displayed in table format over multiple pages. Based on grouping by a value of a column, my code splits the output into multiple pages – using $pdf->AddPage() when a new grouping by value is encountered.
The partial data set for a grouping by value can span multiple pages. I need to display on each page, the page number ‘within’ the partal data set. I tried the following methods. However, all of them provide the page number of the 1st page of the partial data set regardless of how many pages the partial data set needs.
$pdf->getPage()
$pdf->PageNo()
$pdf->getNumPages()
The $pdf->getAliasNumPage()
method returns the current page number while considering every page of the partial data set. This can be used to calculate the page number within the partial data set $pdf->getAliasNumPage() - $pdf->getSectionStartPage()
However, it is an ‘alias’ that do not have a value until the PDF file is generated. I think it is calculated during the execution of the writeHTML()
method.
Is there anyway to print the page number and reset it at the start of each section (grouping by value)?
An example follows.
Group by value: AAA
page: 1
row-1
row-2
end of page and end of section (group by value)
Group by value: BBB
page: 1
row-1
row-2
...
row-14
end of page
page: 2 <<-- I have a problem printing this page number
row-15
row-16
end of page and end of section (group by value)
Group by value: CCC
page: 1
row-17
row-18
end of page and end of section (group by value)
My code:
foreach ($report_data as $index => $data_row) :
if ($newGroupStarts) :
// 1. END PREVIOUS SECTION
if ($prevFinID !== null) {
echo "</tbody></table>";
$html = ob_get_clean();
$pdf->writeHTML($html, true, false, true, false, '');
}
// 2. START NEW SECTION
$pdf->AddPage();
ob_start();
?>
<!-- table header -->
<table cellpadding="3">
<thead>
<tr>
<td>Page: <?= $pageNumber // I need help populating this page number to reflect the page number within the section ?></td>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php endif; ?>
<!-- DATA ROW -->
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<?php // more code ..... ?>
<?php endforeach; ?>
<?php // more code ..... ?>