| @@ 32-59 (lines=28) @@ | ||
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| 32 | public function merge(SourceInterface ...$sources): string |
|
| 33 | { |
|
| 34 | $sourceName = ''; |
|
| 35 | ||
| 36 | try { |
|
| 37 | $fpdi = clone $this->fpdi; |
|
| 38 | ||
| 39 | foreach ($sources as $source) { |
|
| 40 | $sourceName = $source->getName(); |
|
| 41 | $pageCount = $fpdi->setSourceFile(StreamReader::createByString($source->getContents())); |
|
| 42 | $pageNumbers = $source->getPages()->getPageNumbers() ?: range(1, $pageCount); |
|
| 43 | ||
| 44 | foreach ($pageNumbers as $pageNr) { |
|
| 45 | $template = $fpdi->importPage($pageNr); |
|
| 46 | $size = $fpdi->getTemplateSize($template); |
|
| 47 | $fpdi->AddPage( |
|
| 48 | $size['width'] > $size['height'] ? 'L' : 'P', |
|
| 49 | [$size['width'], $size['height']] |
|
| 50 | ); |
|
| 51 | $fpdi->useTemplate($template); |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | return $fpdi->Output('', 'S'); |
|
| 56 | } catch (\Exception $e) { |
|
| 57 | throw new Exception("'{$e->getMessage()}' in '$sourceName'", 0, $e); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 25-52 (lines=28) @@ | ||
| 22 | $this->tcpdi = $tcpdi ?: new \TCPDI; |
|
| 23 | } |
|
| 24 | ||
| 25 | public function merge(SourceInterface ...$sources): string |
|
| 26 | { |
|
| 27 | $sourceName = ''; |
|
| 28 | ||
| 29 | try { |
|
| 30 | $tcpdi = clone $this->tcpdi; |
|
| 31 | ||
| 32 | foreach ($sources as $source) { |
|
| 33 | $sourceName = $source->getName(); |
|
| 34 | $pageCount = $tcpdi->setSourceData($source->getContents()); |
|
| 35 | $pageNumbers = $source->getPages()->getPageNumbers() ?: range(1, $pageCount); |
|
| 36 | ||
| 37 | foreach ($pageNumbers as $pageNr) { |
|
| 38 | $template = $tcpdi->importPage($pageNr); |
|
| 39 | $size = $tcpdi->getTemplateSize($template); |
|
| 40 | $tcpdi->AddPage( |
|
| 41 | $size['w'] > $size['h'] ? 'L' : 'P', |
|
| 42 | [$size['w'], $size['h']] |
|
| 43 | ); |
|
| 44 | $tcpdi->useTemplate($template); |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||
| 48 | return $tcpdi->Output('', 'S'); |
|
| 49 | } catch (\Exception $e) { |
|
| 50 | throw new Exception("'{$e->getMessage()}' in '$sourceName'", 0, $e); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||