From e13c4951241ca52597543be6f2a7d99e3bc44299 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 9 Apr 2024 09:39:06 -0300 Subject: [PATCH] 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 * 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 * Update doc/Usage.md Co-authored-by: Konrad Abicht --------- Signed-off-by: Vitor Mattos Co-authored-by: Konrad Abicht --- doc/Usage.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/Usage.md b/doc/Usage.md index 398c243c..787c79fe 100644 --- a/doc/Usage.md +++ b/doc/Usage.md @@ -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]