Skip to content

Commit

Permalink
Add instructions to get page width and height (#593)
Browse files Browse the repository at this point in the history
* Add instructions to get page width and height

Based on #427 (comment)

* Update doc/Usage.md

* Replaced tabs with whitespaces

---------

Co-authored-by: Konrad Abicht <hi@inspirito.de>
  • Loading branch information
vitormattos and k00ni authored Apr 17, 2023
1 parent 78cd9d4 commit ced49b8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,22 @@ $font = reset($pdf->getFonts());
// get width
$width = $font->calculateTextWidth('Some text', $missing);
```

## Get pages width and height

Ref: [#472](https://github.com/smalot/pdfparser/issues/427#issuecomment-973416786)

```php
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('document.pdf');
$pages = $pdf->getPages();
// this variable will contain the height and width of each page of the given PDF
$mediaBox = [];
foreach ($pages as $page) {
$details = $page->getDetails();
$mediaBox[] = [
'width' => $details['MediaBox'][2],
'height' => $details['MediaBox'][3]
];
}
```

0 comments on commit ced49b8

Please sign in to comment.