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