Skip to content

Commit

Permalink
fix: Return page width and height from document (#700)
Browse files Browse the repository at this point in the history
* fix: Return page width and height from document

Some documents could have pages without MediaBox, at this case we need
to get the MediaBox from document and not from a specific page.

Signed-off-by: Vitor Mattos <vitor@php.rio>

* fix: prevent psalm error

Prevent the follow error:

```
ERROR: InvalidPassByReference - Parameter 1 of reset expects a variable (see https://psalm.dev/102)
				$details = reset($pdf->getObjectsByType('Pages'))->getHeader()->getDetails();
```

Signed-off-by: Vitor Mattos <vitor@php.rio>

* Update doc/Usage.md

Co-authored-by: Konrad Abicht <hi@inspirito.de>

---------

Signed-off-by: Vitor Mattos <vitor@php.rio>
Co-authored-by: Konrad Abicht <hi@inspirito.de>
  • Loading branch information
vitormattos and k00ni authored Apr 9, 2024
1 parent fb77eab commit e13c495
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ $pages = $pdf->getPages();
$mediaBox = [];
foreach ($pages as $page) {
$details = $page->getDetails();
// If Mediabox is not set in details of current $page instance, get details from the header instead
if (!isset($details['MediaBox'])) {
$pages = $pdf->getObjectsByType('Pages');
$details = reset($pages)->getHeader()->getDetails();
}
$mediaBox[] = [
'width' => $details['MediaBox'][2],
'height' => $details['MediaBox'][3]
Expand Down

0 comments on commit e13c495

Please sign in to comment.