Skip to content

Commit 70e83bf

Browse files
Jason-TohJason Toh
andauthored
Dont force portrait orientation during merge if not specified (#29)
* Dont force portrait orientation during merge if not specified * Support for php 5.5.9 Co-authored-by: Jason Toh <[email protected]>
1 parent f49563a commit 70e83bf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/PDFMerger/PDFMerger.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function addPDF($filePath, $pages = 'all', $orientation = null) {
195195
*
196196
* @throws \Exception if there are now PDFs to merge
197197
*/
198-
public function merge($orientation = 'P') {
198+
public function merge($orientation = null) {
199199
$this->doMerge($orientation, false);
200200
}
201201

@@ -228,18 +228,20 @@ protected function doMerge($orientation, $duplexSafe) {
228228
for ($i = 1; $i <= $count; $i++) {
229229
$template = $oFPDI->importPage($i);
230230
$size = $oFPDI->getTemplateSize($template);
231+
$autoOrientation = isset($file['orientation']) ? $file['orientation'] : $size['orientation'];
231232

232-
$oFPDI->AddPage($file['orientation'], [$size['width'], $size['height']]);
233+
$oFPDI->AddPage($autoOrientation, [$size['width'], $size['height']]);
233234
$oFPDI->useTemplate($template);
234235
}
235236
} else {
236237
foreach ($file['pages'] as $page) {
237238
if (!$template = $oFPDI->importPage($page)) {
238-
throw new \Exception("Could not load page '$page' in PDF '".$file['name']."'. Check that the page exists.");
239+
throw new \Exception("Could not load page '$page' in PDF '" . $file['name'] . "'. Check that the page exists.");
239240
}
240241
$size = $oFPDI->getTemplateSize($template);
242+
$autoOrientation = isset($file['orientation']) ? $file['orientation'] : $size['orientation'];
241243

242-
$oFPDI->AddPage($file['orientation'], [$size['width'], $size['height']]);
244+
$oFPDI->AddPage($autoOrientation, [$size['width'], $size['height']]);
243245
$oFPDI->useTemplate($template);
244246
}
245247
}

0 commit comments

Comments
 (0)