Detect PDF Page Orientation Using Java

Import JAR Dependency

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>

Sample Code

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("E:\\Files\\test.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");
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store