How to Find Pdf Page Height And Width in java


In this core java tutorial we will learn How to Find Pdf Page Height And Width using iText library - core java tutorial with program and examples.



Steps to find Page Height And Width in pdf in java using Itext >
  • Open the document using document.open();
  • get pdf Page Width using document.getPageSize().getWidth();
  • get pdf Page height using document.getPageSize().getHeight();


How to Set the Font Name, Size, Style and Colour In Pdf using itext in java

Convert Html To Pdf in java using iText - iText java tutorial

How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial



Download jars required to execute program >

Or, you may download jars from here.

Program/Example How to Find Pdf Page Height And Width  - Using iText library - core java tutorial

import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
*  How to Find Pdf Page Height And Width
*  Example Using iText library - core java tutorial
*
*/
public class FindPdfPageHeightAndWidthExample {
public static void main(String[] args) {
     try {
         
          String pdfFilePath = "E:/Find Pdf Page Height And Width Example.pdf";
          Document document = new Document();
          PdfWriter.getInstance(document, new FileOutputStream(
                            pdfFilePath));
          document.open();
          document.add(new Paragraph("Find Pdf Page Height And Width "));
         
          //Get width and height of whole page
          float pdfPageWidth = document.getPageSize().getWidth();
          float pdfPageHeight = document.getPageSize().getHeight();
         
          document.add(new Paragraph("pdfPageWidth = "+pdfPageWidth));
          document.add(new Paragraph("pdfPageHeight = "+pdfPageHeight));
          document.close();
         
          System.out.println("PDF created in >> "+ pdfFilePath);
     } catch (Exception e) {
          e.printStackTrace();
     }
}
}
/* OUTPUT of above program/Example -
PDF created in >> E:/Find Pdf Page Height And Width Example.pdf
*/


PDF formed after executing above java program will look like this >

Summary -
In this core java tutorial we learned How to Find Pdf Page Height And Width using iText library - core java tutorial with program and examples.




Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

References >



RELATED LINKS>

iText library tutorial in java - How to Create and work with PDF files in java


Creating TABLES in pdf in java - iText tutorial >

How to Create the Table In Pdf in java - iText java tutorial

How to do the Cell Alignment In Pdf generated table in Java program

How to Set Cell Background Colour In Pdf Table in java example

How to Set Cell Background Colour In Pdf Table in java - iText java tutorial

How to Create Images In Pdf generated Table in java itext

How to Create Nested Tables in Pdf in java - iText java tutorial

How to Create the Table With Multiple Rows In Pdf in java program

Create ZapfDingbats List In pdf in java - iText java tutorial program

How to Create Ordered List In pdf in java using iText - iText java tutorial

Creating the UnOrdered List In pdf in java - iText java tutorial example

How to Create Lists And SubLists In Pdf in java - iText java tutorial



Creating PASSWORD PROTECTED PDF in java - iText tutorial >

How to Create Password Protected Pdf in java - iText Example




Set FONT NAME, SIZE, STYLE, COLOUR in pdf in java - iText tutorial >

How to Set the Font Name, Size, Style and Colour In Pdf using itext in java


Create ANCHOR (HYPERLINK), SUPERSCRIPT, SUBSCRIPT, UNDERLINE AND STRIKETHROUGH in pdf in java - iText tutorial >

How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial

How To Set SuperScript And SubScript In Pdf in java - iText java tutorial

UnderLine Text In Pdf in java - iText java tutorial example

Strikethrough Text In Pdf in java - iText java tutorial program


HTML to PDF in java - iText tutorial >

Convert Html To Pdf in java using iText - iText java tutorial


Create new page, set page height and width in java - iText tutorial >

How To Create New Pages In Pdf Using Itext - iText java tutorial example

How to Find Pdf Page Height And Width in java - iText java tutorial program


eEdit
Must read for you :