Skip to content

Commit e13c495

Browse files
vitormattosk00ni
andauthored
fix: Return page width and height from document (#700)
* 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>
1 parent fb77eab commit e13c495

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

doc/Usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ $pages = $pdf->getPages();
224224
$mediaBox = [];
225225
foreach ($pages as $page) {
226226
$details = $page->getDetails();
227+
// If Mediabox is not set in details of current $page instance, get details from the header instead
228+
if (!isset($details['MediaBox'])) {
229+
$pages = $pdf->getObjectsByType('Pages');
230+
$details = reset($pages)->getHeader()->getDetails();
231+
}
227232
$mediaBox[] = [
228233
'width' => $details['MediaBox'][2],
229234
'height' => $details['MediaBox'][3]

0 commit comments

Comments
 (0)