Completed
Push — master ( 215219...ecb74e )
by Faruk
08:00
created

Merge::stream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TarfinLabs\EasyPdf;
4
5
use setasign\Fpdi\PdfParser\StreamReader;
6
use setasign\Fpdi\Tcpdf\Fpdi;
7
8
class Merge extends BasePdf
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $files;
14
15
    /**
16
     * Merge constructor.
17
     *
18
     * @param array $files
19
     */
20
    public function __construct(array $files)
21
    {
22
        parent::__construct();
23
24
        $this->files = $files;
25
    }
26
27
    /**
28
     * Merge pdf files into one pdf.
29
     *
30
     * @return $this
31
     *
32
     * @throws Exceptions\UnableToOpen
33
     */
34
    public function render()
35
    {
36
        foreach ($this->files as $file) {
37
            $this->setFileContent($file);
38
39
            $count = $this->pdf->setSourceFile(StreamReader::createByString($this->content));
40
41
            for ($page = 1; $page <= $count; $page++) {
42
                $this->pdf->AddPage();
43
                $importedPage = $this->pdf->ImportPage($page);
44
                $this->pdf->useTemplate($importedPage);
45
            }
46
        }
47
48
        return $this;
49
    }
50
}
51