| ImageGear Java PDF > How to... > Get PDF Page Size |
To get the page size of a PDF page in a document:
The following is an illustration of how to get the page size of the previously loaded PDF document:
|
Copy Code | |
|---|---|
import com.accusoft.imagegearpdf.*;
class PdfDemo
{
private PDF pdf;
private Document document;
// Obtain size of the PDF page.
public PageSize GetPageSize(long pageNumber)
{
Page page = null;
try
{
// Retrieve specific page.
page = document.getPage(pageNumber);
PageSize size = new PageSize();
size.Width = page.getWidth();
size.Height = page.getHeight();
return size;
}
catch (Throwable ex)
{
// Failed to get page size.
System.err.println("Exception: " + ex.toString());
return null;
}
finally
{
if (page != null)
{
// Close PDF page as it is not needed anymore.
page.close();
}
}
}
// Class to store page size.
public class PageSize
{
// Page width.
public double Width;
// Page height.
public double Height;
}
} | |
Open a PDF Document for details about how to open and close a PDF document