[英]How to find pdf is portrait or landscape using PDFBOX Library in Java
I am doing project in Java using PDFBOX-1.8.6 library (its compulsory to use).我正在使用PDFBOX-1.8.6库(必须使用)在Java 中进行项目。 My Question is我的问题是
Assuming that you have a PDPage object:假设您有一个 PDPage 对象:
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.这仅适用于 1.8.*。 In the 2.* versions, use getMediaBox()
and getRotation()
.在 2.* 版本中,使用getMediaBox()
和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.不要在 1.8.* 版本中使用get*
方法,因为如果在页面级别缺少信息,它们不会查找页面树。
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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.