From 26cce3805fcea8254e45adda30e379444064701e Mon Sep 17 00:00:00 2001 From: Christoph Massmann Date: Sat, 19 Dec 2020 11:19:31 +0100 Subject: [PATCH] page count is now injected via placeholder as described in https://github.com/dompdf/dompdf/issues/1636 Signed-off-by: Christoph Massmann --- src/Model/Generator/Dompdf.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Model/Generator/Dompdf.php b/src/Model/Generator/Dompdf.php index b837b8b..a39ae02 100644 --- a/src/Model/Generator/Dompdf.php +++ b/src/Model/Generator/Dompdf.php @@ -31,6 +31,8 @@ */ final class Dompdf extends AbstractGenerator { + const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__'; + /** * @var \Dompdf\Dompdf */ @@ -51,6 +53,8 @@ public function renderPdfDocument(DocumentInterface $documentModel) $this->domPdf->loadHtml($this->getHtmlContentsForDocument($documentModel)); $this->domPdf->render(); + $this->injectPageCount(); + return $this->domPdf->output(); } @@ -106,4 +110,19 @@ private function getDompdfOptions() 'chroot' => $this->config->getChrootDir(), ); } + + /** + * @return void + */ + private function injectPageCount() + { + $canvas = $this->domPdf->getCanvas(); + $pdf = $canvas->get_cpdf(); + + foreach ($pdf->objects as &$o) { + if ($o['t'] === 'contents') { + $o['c'] = str_replace(self::TOTAL_PAGE_COUNT_PLACEHOLDER, $canvas->get_page_count(), $o['c']); + } + } + } }