@@ -188,14 +188,30 @@ public function addPDF($filePath, $pages = 'all', $orientation = null) {
188
188
* @throws \Exception if there are now PDFs to merge
189
189
*/
190
190
public function merge ($ orientation = 'P ' ) {
191
+ $ this ->doMerge ($ orientation , false );
192
+ }
193
+
194
+ /**
195
+ * Merges your provided PDFs and adds blank pages between documents as needed to allow duplex printing
196
+ * @param string $orientation
197
+ *
198
+ * @return void
199
+ *
200
+ * @throws \Exception if there are now PDFs to merge
201
+ */
202
+ public function duplexMerge ($ orientation = 'P ' ) {
203
+ $ this ->doMerge ($ orientation , true );
204
+ }
205
+
206
+ protected function doMerge ($ orientation , $ duplexSafe ) {
191
207
192
208
if ($ this ->aFiles ->count () == 0 ) {
193
209
throw new \Exception ("No PDFs to merge. " );
194
210
}
195
211
196
212
$ oFPDI = $ this ->oFPDI ;
197
213
198
- $ this ->aFiles ->each (function ($ file ) use ($ oFPDI , $ orientation ){
214
+ $ this ->aFiles ->each (function ($ file ) use ($ oFPDI , $ orientation, $ duplexSafe ){
199
215
$ file ['orientation ' ] = is_null ($ file ['orientation ' ])?$ orientation :$ file ['orientation ' ];
200
216
$ count = $ oFPDI ->setSourceFile ($ file ['name ' ]);
201
217
if ($ file ['pages ' ] == 'all ' ) {
@@ -218,6 +234,10 @@ public function merge($orientation = 'P') {
218
234
$ oFPDI ->useTemplate ($ template );
219
235
}
220
236
}
237
+
238
+ if ($ duplexSafe && $ oFPDI ->page % 2 ) {
239
+ $ oFPDI ->AddPage ($ file ['orientation ' ], [$ size ['w ' ], $ size ['h ' ]]);
240
+ }
221
241
});
222
242
}
223
243
}
0 commit comments