Skip to content

Commit 448f5ee

Browse files
authored
Merge pull request #2 from maddhatter/duplex
Duplex-Safe Merging
2 parents cc87a04 + 2c3e8b4 commit 448f5ee

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ All notable changes to `webklex/laravel-pdfmerger` will be documented in this fi
44

55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

7-
## [UNRELEASED]
7+
## [Unreleased]
8+
9+
### Added
10+
- Added `duplexMerge` to support duplex-safe merging
11+
12+
## [1.0.0] (2017-02-17)
813

914
### Added
1015
- new laravel-pdfmerger package
16+
17+
18+
[Unreleased]: https://github.com/Webklex/laravel-pdfmerger
19+
[1.0.0]: https://github.com/Webklex/laravel-pdfmerger/releases/tag/1.0.0

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ $oMerger->addPDF($file, [1, 3]); //Add page one and three only
6363

6464
```
6565

66+
...merge files together but add blank pages to support duplex printing
67+
```php
68+
$oMerger->duplexMerge();
69+
```
70+
6671
...stream the merged content:
6772

6873
``` php

src/PDFMerger/PDFMerger.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,30 @@ public function addPDF($filePath, $pages = 'all', $orientation = null) {
188188
* @throws \Exception if there are now PDFs to merge
189189
*/
190190
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) {
191207

192208
if ($this->aFiles->count() == 0) {
193209
throw new \Exception("No PDFs to merge.");
194210
}
195211

196212
$oFPDI = $this->oFPDI;
197213

198-
$this->aFiles->each(function($file) use($oFPDI, $orientation){
214+
$this->aFiles->each(function($file) use($oFPDI, $orientation, $duplexSafe){
199215
$file['orientation'] = is_null($file['orientation'])?$orientation:$file['orientation'];
200216
$count = $oFPDI->setSourceFile($file['name']);
201217
if ($file['pages'] == 'all') {
@@ -218,6 +234,10 @@ public function merge($orientation = 'P') {
218234
$oFPDI->useTemplate($template);
219235
}
220236
}
237+
238+
if ($duplexSafe && $oFPDI->page % 2) {
239+
$oFPDI->AddPage($file['orientation'], [$size['w'], $size['h']]);
240+
}
221241
});
222242
}
223243
}

0 commit comments

Comments
 (0)