[英]How to find pdf is portrait or landscape using PDFBOX Library in Java
我正在使用PDFBOX-1.8.6庫(必須使用)在Java 中進行項目。 我的問題是
假設您有一個 PDPage 對象:
PDRectangle mediaBox = page.findMediaBox();
boolean isLandscape = mediaBox.getWidth() > mediaBox.getHeight();
但是......頁面可以旋轉:
int rotation = page.findRotation();
if (rotation == 90 || rotation == 270)
isLandscape = !isLandscape;
這僅適用於 1.8.*。 在 2.* 版本中,使用getMediaBox()
和getRotation()
。 不要在 1.8.* 版本中使用get*
方法,因為如果在頁面級別缺少信息,它們不會查找頁面樹。
這會幫助你
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.