From 9ec1a036c9ac6969b8b093951d36cb9f3792ede8 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 23 Jan 2025 22:31:45 -0300 Subject: [PATCH] chore: use fallback to get page dimension Signed-off-by: Vitor Mattos --- lib/Service/PdfParserService.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/Service/PdfParserService.php b/lib/Service/PdfParserService.php index 9915172425..7a35f0b900 100644 --- a/lib/Service/PdfParserService.php +++ b/lib/Service/PdfParserService.php @@ -77,16 +77,32 @@ public function getPageDimensions(): array { if (!isset($details['MediaBox'])) { $pages = $document->getObjectsByType('Pages'); $details = reset($pages)->getHeader()->getDetails(); + if (!isset($details['MediaBox'])) { + $newPage = $page->createPageForFpdf(); + $details = $newPage->getDetails(); + if (isset($details['BBox'])) { + $output['d'][] = [ + 'w' => $details['BBox'][2], + 'h' => $details['BBox'][3] + ]; + break; + } + } + } + if (!isset($details['MediaBox']) || !is_numeric($details['MediaBox'][2]) || !is_numeric($details['MediaBox'][3])) { + $this->logger->error('Impossible get metadata from this file: Error to get page width and height. If possible, open an issue at github.com/libresign/libresign with the file that you used.'); + throw new LibresignException('Impossible get metadata from this file.'); } - $widthAndHeight = [ + $output['d'][] = [ 'w' => $details['MediaBox'][2], 'h' => $details['MediaBox'][3] ]; - if (!is_numeric($widthAndHeight['w']) || !is_numeric($widthAndHeight['h'])) { - $this->logger->error('Impossible get metadata from this file: Error to get page width and height. If possible, open an issue at github.com/libresign/libresign with the file that you used.'); - throw new LibresignException('Impossible get metadata from this file.'); + } + $pending = $output['p'] - count($output['d']); + if ($pending) { + for ($i = 0; $i < $pending; $i++) { + $output['d'][] = $output['d'][0]; } - $output['d'][] = $widthAndHeight; } return $output; }