Skip to content

Commit 11b46c0

Browse files
authored
auto orientation (#11)
Get the orientation of the page automatically
1 parent 55ad017 commit 11b46c0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PDFMerger/PDFMerger.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ protected function doMerge($orientation, $duplexSafe) {
219219
for ($i = 1; $i <= $count; $i++) {
220220
$template = $oFPDI->importPage($i);
221221
$size = $oFPDI->getTemplateSize($template);
222+
$autoOrientation = ($size['h'] > $size['w']) ? 'P' : 'L';
222223

223-
$oFPDI->AddPage($file['orientation'], [$size['w'], $size['h']]);
224+
$oFPDI->AddPage($autoOrientation, [$size['w'], $size['h']]);
224225
$oFPDI->useTemplate($template);
225226
}
226227
} else {
@@ -229,8 +230,9 @@ protected function doMerge($orientation, $duplexSafe) {
229230
throw new \Exception("Could not load page '$page' in PDF '".$file['name']."'. Check that the page exists.");
230231
}
231232
$size = $oFPDI->getTemplateSize($template);
233+
$autoOrientation = ($size['h'] > $size['w']) ? 'P' : 'L';
232234

233-
$oFPDI->AddPage($file['orientation'], [$size['w'], $size['h']]);
235+
$oFPDI->AddPage($autoOrientation, [$size['w'], $size['h']]);
234236
$oFPDI->useTemplate($template);
235237
}
236238
}

0 commit comments

Comments
 (0)