From 589a3c73998514d23a9771a0f989d48c822e8f24 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 5 Apr 2024 15:12:03 -0300 Subject: [PATCH 1/3] 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 --- doc/Usage.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/Usage.md b/doc/Usage.md index 398c243c..0abbbf00 100644 --- a/doc/Usage.md +++ b/doc/Usage.md @@ -224,6 +224,10 @@ $pages = $pdf->getPages(); $mediaBox = []; foreach ($pages as $page) { $details = $page->getDetails(); + // The page could haven't the Mediabox, then we get this information from document + if (!isset($details['MediaBox'])) { + $details = reset($pdf->getObjectsByType('Pages'))->getHeader()->getDetails(); + } $mediaBox[] = [ 'width' => $details['MediaBox'][2], 'height' => $details['MediaBox'][3] From 6f7c88e50678f649f5dc183b9a55c75d84df155c Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 5 Apr 2024 17:41:49 -0300 Subject: [PATCH 2/3] 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 --- doc/Usage.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/Usage.md b/doc/Usage.md index 0abbbf00..a3fe7742 100644 --- a/doc/Usage.md +++ b/doc/Usage.md @@ -226,7 +226,8 @@ foreach ($pages as $page) { $details = $page->getDetails(); // The page could haven't the Mediabox, then we get this information from document if (!isset($details['MediaBox'])) { - $details = reset($pdf->getObjectsByType('Pages'))->getHeader()->getDetails(); + $pages = $pdf->getObjectsByType('Pages'); + $details = reset($pages)->getHeader()->getDetails(); } $mediaBox[] = [ 'width' => $details['MediaBox'][2], From 5e727d2547f6073007ea9df3ef2e4b26e803a7e8 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 9 Apr 2024 09:26:42 -0300 Subject: [PATCH 3/3] Update doc/Usage.md Co-authored-by: Konrad Abicht --- doc/Usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Usage.md b/doc/Usage.md index a3fe7742..787c79fe 100644 --- a/doc/Usage.md +++ b/doc/Usage.md @@ -224,7 +224,7 @@ $pages = $pdf->getPages(); $mediaBox = []; foreach ($pages as $page) { $details = $page->getDetails(); - // The page could haven't the Mediabox, then we get this information from document + // 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();