Skip to content

Commit 71723e5

Browse files
committed
Merge branch 'release/2.1.0'
2 parents 2251827 + e084244 commit 71723e5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [2.1.0] - 2020-12-19
8+
### Added
9+
- Total page count is now available via placeholder `__PDF_TPC__`
10+
711
## [2.0.0] - 2020-11-05
812
### Changed
913
- Upgraded DomPPDF dependency to 0.8.6 and added chroot setting

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)