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

Parser::content()   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
7
class Parser extends BasePdf
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $path;
13
14
    /**
15
     * @var int
16
     */
17
    protected $page;
18
19
    /**
20
     * Parser constructor.
21
     *
22
     * @param string $path
23
     * @throws Exceptions\UnableToOpen
24
     */
25
    public function __construct(string $path)
26
    {
27
        parent::__construct();
28
29
        $this->path = $path;
30
        $this->setFileContent($this->path);
31
    }
32
33
    /**
34
     * Return pdf page count.
35
     *
36
     * @return int
37
     *
38
     * @throws \setasign\Fpdi\PdfParser\PdfParserException
39
     */
40
    public function count(): int
41
    {
42
        return $this->pdf->setSourceFile(StreamReader::createByString($this->content));
43
    }
44
45
    /**
46
     * Set page for save methods.
47
     *
48
     * @param int $page
49
     * @return Parser
50
     */
51
    public function setPage(int $page)
52
    {
53
        $this->page = $page;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Render given source.
60
     *
61
     * @return Parser
62
     */
63
    public function render()
64
    {
65
        $this->pdf->AddPage();
66
67
        $this->pdf->setSourceFile(StreamReader::createByString($this->content));
68
69
        $this->pdf->useTemplate($this->pdf->importPage($this->page));
70
71
        return $this;
72
    }
73
}
74