Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| JavaScriptAction | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getActionType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toPdf | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Core\Action; |
| 6 | |
| 7 | use Phpdftk\Pdf\Core\PdfDictionary; |
| 8 | use Phpdftk\Pdf\Core\PdfName; |
| 9 | use Phpdftk\Pdf\Core\PdfString; |
| 10 | use Phpdftk\Pdf\Core\PdfVersion; |
| 11 | use Phpdftk\Pdf\Core\RequiresPdfVersion; |
| 12 | |
| 13 | /** |
| 14 | * JavaScript action (/S /JavaScript). |
| 15 | * Executes a JavaScript script. |
| 16 | */ |
| 17 | #[RequiresPdfVersion(PdfVersion::V1_3)] |
| 18 | class JavaScriptAction extends Action |
| 19 | { |
| 20 | public PdfString $js; // /JS - required |
| 21 | |
| 22 | public function __construct(PdfString $js) |
| 23 | { |
| 24 | $this->js = $js; |
| 25 | } |
| 26 | |
| 27 | public function getActionType(): string |
| 28 | { |
| 29 | return 'JavaScript'; |
| 30 | } |
| 31 | |
| 32 | public function toPdf(): string |
| 33 | { |
| 34 | $dict = new PdfDictionary(); |
| 35 | $dict->set('Type', new PdfName(self::PDF_TYPE)); |
| 36 | $dict->set('S', new PdfName($this->getActionType())); |
| 37 | $dict->set('JS', $this->js); |
| 38 | |
| 39 | if ($this->next !== null) { |
| 40 | $dict->set('Next', $this->next); |
| 41 | } |
| 42 | |
| 43 | return $dict->toPdf(); |
| 44 | } |
| 45 | } |