Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
28 / 28 |
|
100.00% |
19 / 19 |
CRAP | |
100.00% |
1 / 1 |
| AbstractPage | |
100.00% |
28 / 28 |
|
100.00% |
19 / 19 |
19 | |
100.00% |
1 / 1 |
| setWidth | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setHeight | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setIndex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getWidth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getImages | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTextStreams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAnnotations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPaths | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasImages | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasTextStreams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasAnnotations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasPaths | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasFields | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| clearContent | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addImage | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addText | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addTextStream | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addAnnotation | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addUrl | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addLink | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addPath | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| addField | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | /** |
| 3 | * Pop PHP Framework (https://www.popphp.org/) |
| 4 | * |
| 5 | * @link https://github.com/popphp/popphp-framework |
| 6 | * @author Nick Sagona, III <dev@noladev.com> |
| 7 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 8 | * @license https://www.popphp.org/license New BSD License |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * @namespace |
| 13 | */ |
| 14 | namespace Pop\Pdf\Document; |
| 15 | |
| 16 | use Pop\Pdf\Document\Page\Annotation; |
| 17 | |
| 18 | /** |
| 19 | * Abstract Page class |
| 20 | * |
| 21 | * @category Pop |
| 22 | * @package Pop\Pdf |
| 23 | * @author Nick Sagona, III <dev@noladev.com> |
| 24 | * @copyright Copyright (c) 2009-2026 NOLA Interactive, LLC. |
| 25 | * @license https://www.popphp.org/license New BSD License |
| 26 | * @version 5.2.7 |
| 27 | */ |
| 28 | abstract class AbstractPage implements PageInterface |
| 29 | { |
| 30 | |
| 31 | /** |
| 32 | * Page size constants |
| 33 | */ |
| 34 | const ENVELOPE_10 = 'ENVELOPE_10'; |
| 35 | const ENVELOPE_C5 = 'ENVELOPE_C5'; |
| 36 | const ENVELOPE_DL = 'ENVELOPE_DL'; |
| 37 | const FOLIO = 'FOLIO'; |
| 38 | const EXECUTIVE = 'EXECUTIVE'; |
| 39 | const LETTER = 'LETTER'; |
| 40 | const LEGAL = 'LEGAL'; |
| 41 | const LEDGER = 'LEDGER'; |
| 42 | const TABLOID = 'TABLOID'; |
| 43 | const A0 = 'A0'; |
| 44 | const A1 = 'A1'; |
| 45 | const A2 = 'A2'; |
| 46 | const A3 = 'A3'; |
| 47 | const A4 = 'A4'; |
| 48 | const A5 = 'A5'; |
| 49 | const A6 = 'A6'; |
| 50 | const A7 = 'A7'; |
| 51 | const A8 = 'A8'; |
| 52 | const A9 = 'A9'; |
| 53 | const B0 = 'B0'; |
| 54 | const B1 = 'B1'; |
| 55 | const B2 = 'B2'; |
| 56 | const B3 = 'B3'; |
| 57 | const B4 = 'B4'; |
| 58 | const B5 = 'B5'; |
| 59 | const B6 = 'B6'; |
| 60 | const B7 = 'B7'; |
| 61 | const B8 = 'B8'; |
| 62 | const B9 = 'B9'; |
| 63 | const B10 = 'B10'; |
| 64 | |
| 65 | /** |
| 66 | * Array of page sizes |
| 67 | * @var array |
| 68 | */ |
| 69 | protected array $sizes = [ |
| 70 | 'ENVELOPE_10' => ['width' => 297, 'height' => 684], |
| 71 | 'ENVELOPE_C5' => ['width' => 461, 'height' => 648], |
| 72 | 'ENVELOPE_DL' => ['width' => 312, 'height' => 624], |
| 73 | 'FOLIO' => ['width' => 595, 'height' => 935], |
| 74 | 'EXECUTIVE' => ['width' => 522, 'height' => 756], |
| 75 | 'LETTER' => ['width' => 612, 'height' => 792], |
| 76 | 'LEGAL' => ['width' => 612, 'height' => 1008], |
| 77 | 'LEDGER' => ['width' => 1224, 'height' => 792], |
| 78 | 'TABLOID' => ['width' => 792, 'height' => 1224], |
| 79 | 'A0' => ['width' => 2384, 'height' => 3370], |
| 80 | 'A1' => ['width' => 1684, 'height' => 2384], |
| 81 | 'A2' => ['width' => 1191, 'height' => 1684], |
| 82 | 'A3' => ['width' => 842, 'height' => 1191], |
| 83 | 'A4' => ['width' => 595, 'height' => 842], |
| 84 | 'A5' => ['width' => 420, 'height' => 595], |
| 85 | 'A6' => ['width' => 297, 'height' => 420], |
| 86 | 'A7' => ['width' => 210, 'height' => 297], |
| 87 | 'A8' => ['width' => 148, 'height' => 210], |
| 88 | 'A9' => ['width' => 105, 'height' => 148], |
| 89 | 'B0' => ['width' => 2920, 'height' => 4127], |
| 90 | 'B1' => ['width' => 2064, 'height' => 2920], |
| 91 | 'B2' => ['width' => 1460, 'height' => 2064], |
| 92 | 'B3' => ['width' => 1032, 'height' => 1460], |
| 93 | 'B4' => ['width' => 729, 'height' => 1032], |
| 94 | 'B5' => ['width' => 516, 'height' => 729], |
| 95 | 'B6' => ['width' => 363, 'height' => 516], |
| 96 | 'B7' => ['width' => 258, 'height' => 363], |
| 97 | 'B8' => ['width' => 181, 'height' => 258], |
| 98 | 'B9' => ['width' => 127, 'height' => 181], |
| 99 | 'B10' => ['width' => 91, 'height' => 127] |
| 100 | ]; |
| 101 | |
| 102 | /** |
| 103 | * Page index if page object represents an imported page |
| 104 | * @var ?int |
| 105 | */ |
| 106 | protected ?int $index = null; |
| 107 | |
| 108 | /** |
| 109 | * Page width |
| 110 | * @var ?int |
| 111 | */ |
| 112 | protected ?int $width = null; |
| 113 | |
| 114 | /** |
| 115 | * Page height |
| 116 | * @var int |
| 117 | */ |
| 118 | protected ?int $height = null; |
| 119 | |
| 120 | /** |
| 121 | * Images array |
| 122 | * @var array |
| 123 | */ |
| 124 | protected array $images = []; |
| 125 | |
| 126 | /** |
| 127 | * Text array |
| 128 | * @var array |
| 129 | */ |
| 130 | protected array $text = []; |
| 131 | |
| 132 | /** |
| 133 | * Text streams array |
| 134 | * @var array |
| 135 | */ |
| 136 | protected array $textStreams = []; |
| 137 | |
| 138 | /** |
| 139 | * Annotations array |
| 140 | * @var array |
| 141 | */ |
| 142 | protected array $annotations = []; |
| 143 | |
| 144 | /** |
| 145 | * Paths array |
| 146 | * @var array |
| 147 | */ |
| 148 | protected array $paths = []; |
| 149 | |
| 150 | /** |
| 151 | * Fields array |
| 152 | * @var array |
| 153 | */ |
| 154 | protected array $fields = []; |
| 155 | |
| 156 | /** |
| 157 | * Set the page width |
| 158 | * |
| 159 | * @param mixed $width |
| 160 | * @return AbstractPage |
| 161 | */ |
| 162 | public function setWidth(mixed $width): AbstractPage |
| 163 | { |
| 164 | $this->width = (float)$width; |
| 165 | return $this; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Set the page height |
| 170 | * |
| 171 | * @param mixed $height |
| 172 | * @return AbstractPage |
| 173 | */ |
| 174 | public function setHeight(mixed $height): AbstractPage |
| 175 | { |
| 176 | $this->height = (float)$height; |
| 177 | return $this; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Set the page index |
| 182 | * |
| 183 | * @param int $i |
| 184 | * @return AbstractPage |
| 185 | */ |
| 186 | public function setIndex(int $i): AbstractPage |
| 187 | { |
| 188 | $this->index = $i; |
| 189 | return $this; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Get the page width |
| 194 | * |
| 195 | * @return int |
| 196 | */ |
| 197 | public function getWidth(): int |
| 198 | { |
| 199 | return $this->width; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Get the page height |
| 204 | * |
| 205 | * @return int |
| 206 | */ |
| 207 | public function getHeight(): int |
| 208 | { |
| 209 | return $this->height; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Get the page index |
| 214 | * |
| 215 | * @return ?int |
| 216 | */ |
| 217 | public function getIndex(): ?int |
| 218 | { |
| 219 | return $this->index; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Get image objects |
| 224 | * |
| 225 | * @return array |
| 226 | */ |
| 227 | public function getImages(): array |
| 228 | { |
| 229 | return $this->images; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Get text objects |
| 234 | * |
| 235 | * @return array |
| 236 | */ |
| 237 | public function getText(): array |
| 238 | { |
| 239 | return $this->text; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Get text stream objects |
| 244 | * |
| 245 | * @return array |
| 246 | */ |
| 247 | public function getTextStreams(): array |
| 248 | { |
| 249 | return $this->textStreams; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Get annotation objects |
| 254 | * |
| 255 | * @return array |
| 256 | */ |
| 257 | public function getAnnotations(): array |
| 258 | { |
| 259 | return $this->annotations; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Get path objects |
| 264 | * |
| 265 | * @return array |
| 266 | */ |
| 267 | public function getPaths(): array |
| 268 | { |
| 269 | return $this->paths; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Get field objects |
| 274 | * |
| 275 | * @return array |
| 276 | */ |
| 277 | public function getFields(): array |
| 278 | { |
| 279 | return $this->fields; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Determine if the page has image objects |
| 284 | * |
| 285 | * @return bool |
| 286 | */ |
| 287 | public function hasImages(): bool |
| 288 | { |
| 289 | return (count($this->images) > 0); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Determine if the page has text objects |
| 294 | * |
| 295 | * @return bool |
| 296 | */ |
| 297 | public function hasText(): bool |
| 298 | { |
| 299 | return (count($this->text) > 0); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Determine if the page has text stream objects |
| 304 | * |
| 305 | * @return bool |
| 306 | */ |
| 307 | public function hasTextStreams(): bool |
| 308 | { |
| 309 | return (count($this->textStreams) > 0); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Determine if the page has annotation objects |
| 314 | * |
| 315 | * @return bool |
| 316 | */ |
| 317 | public function hasAnnotations(): bool |
| 318 | { |
| 319 | return (count($this->annotations) > 0); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Determine if the page has path objects |
| 324 | * |
| 325 | * @return bool |
| 326 | */ |
| 327 | public function hasPaths(): bool |
| 328 | { |
| 329 | return (count($this->paths) > 0); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Determine if the page has field objects |
| 334 | * |
| 335 | * @return bool |
| 336 | */ |
| 337 | public function hasFields(): bool |
| 338 | { |
| 339 | return (count($this->fields) > 0); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Clear page content |
| 344 | * |
| 345 | * @return AbstractPage |
| 346 | */ |
| 347 | public function clearContent(): AbstractPage |
| 348 | { |
| 349 | $this->images = []; |
| 350 | $this->text = []; |
| 351 | $this->textStreams = []; |
| 352 | $this->annotations = []; |
| 353 | $this->paths = []; |
| 354 | $this->fields = []; |
| 355 | |
| 356 | return $this; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Constructor |
| 361 | * |
| 362 | * Instantiate a PDF page. |
| 363 | * |
| 364 | * @throws Exception |
| 365 | * @return AbstractPage |
| 366 | */ |
| 367 | abstract public function __construct(); |
| 368 | |
| 369 | /** |
| 370 | * Add an image to the PDF page |
| 371 | * |
| 372 | * @param Page\Image $image |
| 373 | * @param int $x |
| 374 | * @param int $y |
| 375 | * @return Page |
| 376 | */ |
| 377 | abstract public function addImage(Page\Image $image, int $x = 0, int $y = 0): AbstractPage; |
| 378 | |
| 379 | /** |
| 380 | * Add text to the PDF page |
| 381 | * |
| 382 | * @param Page\Text $text |
| 383 | * @param string $fontStyle (can be either a reference to a font or a style) |
| 384 | * @param int $x |
| 385 | * @param int $y |
| 386 | * @return Page |
| 387 | */ |
| 388 | abstract public function addText(Page\Text $text, string $fontStyle, int $x = 0, int $y = 0): AbstractPage; |
| 389 | |
| 390 | /** |
| 391 | * Add text stream to the PDF page |
| 392 | * |
| 393 | * @param Page\Text\Stream $textStream |
| 394 | * @return Page |
| 395 | */ |
| 396 | abstract public function addTextStream(Page\Text\Stream $textStream): Page; |
| 397 | |
| 398 | /** |
| 399 | * Add an annotation to the PDF page |
| 400 | * |
| 401 | * @param Annotation\AbstractAnnotation $annotation |
| 402 | * @param int $x |
| 403 | * @param int $y |
| 404 | * @return Page |
| 405 | */ |
| 406 | abstract public function addAnnotation(Annotation\AbstractAnnotation $annotation, int $x = 0, int $y = 0): AbstractPage; |
| 407 | |
| 408 | /** |
| 409 | * Add a URL annotation to the PDF page |
| 410 | * |
| 411 | * @param Annotation\Url $url |
| 412 | * @param int $x |
| 413 | * @param int $y |
| 414 | * @return Page |
| 415 | */ |
| 416 | abstract public function addUrl(Annotation\Url $url, int $x = 0, int $y = 0): AbstractPage; |
| 417 | |
| 418 | /** |
| 419 | * Add a link annotation to the PDF page |
| 420 | * |
| 421 | * @param Annotation\Link $link |
| 422 | * @param int $x |
| 423 | * @param int $y |
| 424 | * @return Page |
| 425 | */ |
| 426 | abstract public function addLink(Annotation\Link $link, int $x = 0, int $y = 0): AbstractPage; |
| 427 | |
| 428 | /** |
| 429 | * Add a path to the Pdf page |
| 430 | * |
| 431 | * @param Page\Path $path |
| 432 | * @return Page |
| 433 | */ |
| 434 | abstract public function addPath(Page\Path $path): AbstractPage; |
| 435 | |
| 436 | /** |
| 437 | * Add a form to the Pdf page |
| 438 | * |
| 439 | * @param Page\Field\AbstractField $field |
| 440 | * @param string $form |
| 441 | * @param int $x |
| 442 | * @param int $y |
| 443 | * @return Page |
| 444 | */ |
| 445 | abstract public function addField(Page\Field\AbstractField $field, string $form, int $x = 0, int $y = 0): Page; |
| 446 | |
| 447 | } |