File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
5
5
and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
6
6
7
+ ## [ 2.1.0] - 2020-12-19
8
+ ### Added
9
+ - Total page count is now available via placeholder ` __PDF_TPC__ `
10
+
7
11
## [ 2.0.0] - 2020-11-05
8
12
### Changed
9
13
- Upgraded DomPPDF dependency to 0.8.6 and added chroot setting
Original file line number Diff line number Diff line change 31
31
*/
32
32
final class Dompdf extends AbstractGenerator
33
33
{
34
+ const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__ ' ;
35
+
34
36
/**
35
37
* @var \Dompdf\Dompdf
36
38
*/
@@ -51,6 +53,8 @@ public function renderPdfDocument(DocumentInterface $documentModel)
51
53
$ this ->domPdf ->loadHtml ($ this ->getHtmlContentsForDocument ($ documentModel ));
52
54
$ this ->domPdf ->render ();
53
55
56
+ $ this ->injectPageCount ();
57
+
54
58
return $ this ->domPdf ->output ();
55
59
}
56
60
@@ -106,4 +110,19 @@ private function getDompdfOptions()
106
110
'chroot ' => $ this ->config ->getChrootDir (),
107
111
);
108
112
}
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
+ }
109
128
}
You can’t perform that action at this time.
0 commit comments