return (string) $dompdf->
output();
} /**
* Replace a predefined placeholder with the total page count in the whole PDF document
*/
private function injectPageCount(Dompdf
$dompdf): void
{ /** @var CPDF $canvas */
$canvas =
$dompdf->
getCanvas();
$search =
$this->
insertNullByteBeforeEachCharacter('DOMPDF_PAGE_COUNT_PLACEHOLDER'
);
$replace =
$this->
insertNullByteBeforeEachCharacter((string) $canvas->
get_page_count());
$pdf =
$canvas->
get_cpdf();
foreach ($pdf->objects
as &
$o) { if ($o['t'
] === 'contents'
) { $o['c'
] =
str_replace($search,
$replace,
(string) $o['c'
]);
} } } private function insertNullByteBeforeEachCharacter(string
$string): string
{