Reputation:
I am doing project in Java using PDFBOX-1.8.6 library (its compulsory to use). My Question is
Upvotes: 8
Views: 9275
Reputation: 18851
Assuming that you have a PDPage object:
PDRectangle mediaBox = page.findMediaBox();
boolean isLandscape = mediaBox.getWidth() > mediaBox.getHeight();
however... the page could be rotated:
int rotation = page.findRotation();
if (rotation == 90 || rotation == 270)
isLandscape = !isLandscape;
This is for 1.8.* only. In the 2.* versions, use getMediaBox()
and getRotation()
. Don't use the get*
methods in the 1.8.* versions because they don't look up the page tree if the info is missing at the page level.
Upvotes: 18
Reputation: 131
This will help you
if(document !=null){
int pageCount = document.getNumberOfPages();
for(int i = 0; i <pageCount ; i++){
PDRectangle pageSize=document.getPage(i).getMediaBox();
int degree=document.getPage(i).getRotation();
if(( pageSize.getWidth() > pageSize.getHeight()) ||(degree==90)||(degree==270)){
document.close();
return true; //document is landscape
}
}
}
Upvotes: 2