Skip to content

Commit 26cce38

Browse files
committed
page count is now injected via placeholder as described in dompdf/dompdf#1636
Signed-off-by: Christoph Massmann <[email protected]>
1 parent 28831fd commit 26cce38

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Model/Generator/Dompdf.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
final class Dompdf extends AbstractGenerator
3333
{
34+
const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__';
35+
3436
/**
3537
* @var \Dompdf\Dompdf
3638
*/
@@ -51,6 +53,8 @@ public function renderPdfDocument(DocumentInterface $documentModel)
5153
$this->domPdf->loadHtml($this->getHtmlContentsForDocument($documentModel));
5254
$this->domPdf->render();
5355

56+
$this->injectPageCount();
57+
5458
return $this->domPdf->output();
5559
}
5660

@@ -106,4 +110,19 @@ private function getDompdfOptions()
106110
'chroot' => $this->config->getChrootDir(),
107111
);
108112
}
113+
114+
/**
115+
* @return void
116+
*/
117+
private function injectPageCount()
118+
{
119+
$canvas = $this->domPdf->getCanvas();
120+
$pdf = $canvas->get_cpdf();
121+
122+
foreach ($pdf->objects as &$o) {
123+
if ($o['t'] === 'contents') {
124+
$o['c'] = str_replace(self::TOTAL_PAGE_COUNT_PLACEHOLDER, $canvas->get_page_count(), $o['c']);
125+
}
126+
}
127+
}
109128
}

0 commit comments

Comments
 (0)