Spire.PDF for Java supports detecting the orientation of a PDF page by comparing the value of page width and page height. This article shows how to use Spire.PDF for Java to accomplish this function.
import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; public class DetectPageOrientation { public static void main(String[] args){ //Load PDF file PdfDocument pdf = new PdfDocument(); pdf.loadFromFile("Fields.pdf"); //Get the first page PdfPageBase page = pdf.getPages().get(0); //Compare the value of page width and height if (page.getSize().getWidth()> page.getSize().getHeight()){ System.out.println("The page orientation is Landscape"); } else{ System.out.println("The page orientation is Portrait"); } } }
Output