Skip to content

Commit

Permalink
chore: use fallback to get page dimension
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 24, 2025
1 parent ccf2ba3 commit 9ec1a03
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/Service/PdfParserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9ec1a03

Please sign in to comment.