@@ -110,15 +110,13 @@ private function _generate()
110
110
$ this ->dompdf ->loadHtml ($ this ->html );
111
111
$ this ->dompdf ->render ();
112
112
113
+ if (strpos ($ this ->html , "SUPER_PDF_TOTAL_PAGES " ) !== false ) {
114
+ $ this ->injectPageCount ();
115
+ }
116
+
113
117
if ($ this ->settings ['encrypt ' ])
114
118
{
115
- $ allow = [];
116
- if ($ this ->settings ['print ' ]) $ allow [] = 'print ' ;
117
- if ($ this ->settings ['modify ' ]) $ allow [] = 'modify ' ;
118
- if ($ this ->settings ['copy ' ]) $ allow [] = 'copy ' ;
119
- if ($ this ->settings ['add ' ]) $ allow [] = 'add ' ;
120
-
121
- $ this ->dompdf ->getCanvas ()->get_cpdf ()->setEncryption ($ this ->settings ['password ' ], $ this ->settings ['adminPassword ' ], $ allow );
119
+ $ this ->injectEncryption ();
122
120
}
123
121
124
122
if ($ this ->settings ['type ' ] == 'url ' )
@@ -150,6 +148,29 @@ private function _generate()
150
148
151
149
}
152
150
151
+ public function injectPageCount (): void
152
+ {
153
+ $ canvas = $ this ->dompdf ->getCanvas ();
154
+ $ pdf = $ canvas ->get_cpdf ();
155
+
156
+ foreach ($ pdf ->objects as &$ o ) {
157
+ if ($ o ['t ' ] === 'contents ' ) {
158
+ $ o ['c ' ] = str_replace ('SUPER_PDF_TOTAL_PAGES ' , $ canvas ->get_page_count (), $ o ['c ' ]);
159
+ }
160
+ }
161
+ }
162
+
163
+ public function injectEncryption (): void
164
+ {
165
+ $ allow = [];
166
+ if ($ this ->settings ['print ' ]) $ allow [] = 'print ' ;
167
+ if ($ this ->settings ['modify ' ]) $ allow [] = 'modify ' ;
168
+ if ($ this ->settings ['copy ' ]) $ allow [] = 'copy ' ;
169
+ if ($ this ->settings ['add ' ]) $ allow [] = 'add ' ;
170
+
171
+ $ this ->dompdf ->getCanvas ()->get_cpdf ()->setEncryption ($ this ->settings ['password ' ], $ this ->settings ['adminPassword ' ], $ allow );
172
+ }
173
+
153
174
public function renderFileFromStorage ($ filename = "" )
154
175
{
155
176
if ($ filename == "" )
0 commit comments