Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the orientation of a PDF that has been read in through iText

I am reading in a PDF through iText. How can I check to see if the orientation of the first page is in landscape or portrait mode?

like image 910
Shino Avatar asked Jan 20 '23 07:01

Shino


2 Answers

I'm using this and it seems to work well.

Rectangle rectangle = pdfReader.getPageSizeWithRotation(pageNumber);

if(rectangle.getHeight() >= rectangle.getWidth())
    return PageFormat.PORTRAIT;
else
    return PageFormat.LANDSCAPE;
like image 193
Olivier Masseau Avatar answered Feb 07 '23 19:02

Olivier Masseau


Try getPageRotation() combined with getPageSize()

like image 36
Jasper Duizendstra Avatar answered Feb 07 '23 20:02

Jasper Duizendstra