Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| GoToRAction | |
100.00% |
15 / 15 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getActionType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Action; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfBoolean; |
| 8 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 9 | use Phpdftk\Pdf\Core\PdfName; |
| 10 | use Phpdftk\Pdf\Core\PdfString; |
| 11 | |
| 12 | /** |
| 13 | * GoToR action (/S /GoToR). |
| 14 | * |
| 15 | * Navigates to a destination in a remote (different) PDF file. |
| 16 | * The destination (/D) and file (/F) are both required. |
| 17 | * |
| 18 | * Example: |
| 19 | * $action = new GoToRAction( |
| 20 | * new PdfString('/path/to/other.pdf'), |
| 21 | * new PdfName('Chapter1') |
| 22 | * ); |
| 23 | * $action->newWindow = true; |
| 24 | */ |
| 25 | class GoToRAction extends Action |
| 26 | { |
| 27 | public PdfString $f; // /F - file specification (path or URL) |
| 28 | public mixed $dest; // /D - destination (PdfName, PdfArray, or string page index) |
| 29 | public ?bool $newWindow = null; // /NewWindow - open in new window |
| 30 | |
| 31 | public function __construct(PdfString $f, mixed $dest) |
| 32 | { |
| 33 | $this->f = $f; |
| 34 | $this->dest = $dest; |
| 35 | } |
| 36 | |
| 37 | public function getActionType(): string |
| 38 | { |
| 39 | return 'GoToR'; |
| 40 | } |
| 41 | |
| 42 | public function toPdf(): string |
| 43 | { |
| 44 | $dict = new PdfDictionary(); |
| 45 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 46 | $dict->set('S', new PdfName($this->getActionType())); |
| 47 | $dict->set('F', $this->f); |
| 48 | |
| 49 | if ($this->dest instanceof \Phpdftk\Pdf\Core\Serializable) { |
| 50 | $dict->set('D', $this->dest); |
| 51 | } else { |
| 52 | $dict->set('D', new \Phpdftk\Pdf\Core\PdfString((string) $this->dest)); |
| 53 | } |
| 54 | |
| 55 | if ($this->newWindow !== null) { |
| 56 | $dict->set('NewWindow', new PdfBoolean($this->newWindow)); |
| 57 | } |
| 58 | if ($this->next !== null) { |
| 59 | $dict->set('Next', $this->next); |
| 60 | } |
| 61 | |
| 62 | return $dict->toPdf(); |
| 63 | } |
| 64 | } |