Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to find PDF page size in Java

48 sec read

jpedal

PDF files are not directly supported by Java. This tutorial shows you how to extract PDF page size (height and width) from a PDF file in simple steps using JPedal PDF library.

Why use a third party library to handle PDF files?

PDF files are a very complex binary/text hybrid data structure which is a subset of the even more complicated Postscript format. In this example, we will use our JPedal PDF library to make this task simple.

How to find PDF page size in Java

Step 1 Create a File handle, InputStream or URL pointing to the PDF file

PdfUtilities extract=new PdfUtilities(path);

Step 2 Include a password if file password protected

extract.setPassword("password");

Step 3 Open the PDF file

if (extract.openPDFFile()) {

Step 4 Select the data type required

if (extract.openPDFFile()) {
      Map mapOfValuePairs=extract.getDocumentPropertyStringValuesAsMap();    
      String XMLStringData=extract.getDocumentPropertyFieldsInXML();
}
}

Step 5 Close the PDF file

 extract.closePDFfile();



Get started with your free JPedal trial

Download your free 14-day trial, no credit card required

Please fill out the form below and your trial JAR will be emailed to you

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2021. All rights reserved.