com.sun.pdfview

Class PDFFile

public class PDFFile extends Object

An encapsulation of a .pdf file. The methods of this class can parse the contents of a PDF file, but those methods are hidden. Instead, the public methods of this class allow access to the pages in the PDF file. Typically, you create a new PDFFile, ask it for the number of pages, and then request one or more PDFPages.
Constructor Summary
PDFFile(ByteBuffer buf)
get a PDFFile from a .pdf file.
Method Summary
PDFObjectdereference(PDFXref ref)
Used internally to track down PDFObject references.
intgetMajorVersion()
return the major version of the PDF
intgetMinorVersion()
return the minor version of the PDF
intgetNumPages()
return the number of pages in this PDFFile.
OutlineNodegetOutline()
Gets the outline tree as a tree of OutlineNode, which is a subclass of DefaultMutableTreeNode.
PDFPagegetPage(int pagenum)
Get the page commands for a given page in a separate thread.
PDFPagegetPage(int pagenum, boolean wait)
Get the page commands for a given page.
intgetPageNumber(PDFObject page)
Gets the page number (starting from 1) of the page represented by a particular PDFObject.
PDFObjectgetRoot()
get the root PDFObject of this PDFFile.
StringgetVersionString()
return the version string from the PDF
static booleanisDelimiter(int c)
Is the argument a delimiter according to the PDF spec?
booleanisPrintable()
Gets whether the owner of the file has given permission to print the file.
booleanisSaveable()
Gets whether the owner of the file has given permission to save a copy of the file.
static booleanisWhiteSpace(int c)
Is the argument a white space character according to the PDF spec?
FloatparseRect(PDFObject obj)
get a Rectangle2D.Float representation for a PDFObject that is an array of four Numbers.
voidstop(int pageNum)
Stop the rendering of a particular image on this page

Constructor Detail

PDFFile

public PDFFile(ByteBuffer buf)
get a PDFFile from a .pdf file. The file must me a random access file at the moment. It should really be a file mapping from the nio package.

Use the getPage(...) methods to get a page from the PDF file.

Parameters: buf the RandomAccessFile containing the PDF.

Method Detail

dereference

public PDFObject dereference(PDFXref ref)
Used internally to track down PDFObject references. You should never need to call this.

Since this is the only public method for tracking down PDF objects, it is synchronized. This means that the PDFFile can only hunt down one object at a time, preventing the file's location from getting messed around.

This call stores the current buffer position before any changes are made and restores it afterwards, so callers need not know that the position has changed.

getMajorVersion

public int getMajorVersion()
return the major version of the PDF

Returns:

getMinorVersion

public int getMinorVersion()
return the minor version of the PDF

Returns:

getNumPages

public int getNumPages()
return the number of pages in this PDFFile. The pages will be numbered from 1 to getNumPages(), inclusive.

getOutline

public OutlineNode getOutline()
Gets the outline tree as a tree of OutlineNode, which is a subclass of DefaultMutableTreeNode. If there is no outline tree, this method returns null.

getPage

public PDFPage getPage(int pagenum)
Get the page commands for a given page in a separate thread.

Parameters: pagenum the number of the page to get commands for

getPage

public PDFPage getPage(int pagenum, boolean wait)
Get the page commands for a given page.

Parameters: pagenum the number of the page to get commands for wait if true, do not exit until the page is complete.

getPageNumber

public int getPageNumber(PDFObject page)
Gets the page number (starting from 1) of the page represented by a particular PDFObject. The PDFObject must be a Page dictionary or a destination description (or an action).

Returns: a number between 1 and the number of pages indicating the page number, or 0 if the PDFObject is not in the page tree.

getRoot

public PDFObject getRoot()
get the root PDFObject of this PDFFile. You generally shouldn't need this, but we've left it open in case you want to go spelunking.

getVersionString

public String getVersionString()
return the version string from the PDF

Returns:

isDelimiter

public static boolean isDelimiter(int c)
Is the argument a delimiter according to the PDF spec?

isPrintable

public boolean isPrintable()
Gets whether the owner of the file has given permission to print the file.

Returns: true if it is okay to print the file

isSaveable

public boolean isSaveable()
Gets whether the owner of the file has given permission to save a copy of the file.

Returns: true if it is okay to save the file

isWhiteSpace

public static boolean isWhiteSpace(int c)
Is the argument a white space character according to the PDF spec?

parseRect

public Float parseRect(PDFObject obj)
get a Rectangle2D.Float representation for a PDFObject that is an array of four Numbers.

Parameters: obj a PDFObject that represents an Array of exactly four Numbers.

stop

public void stop(int pageNum)
Stop the rendering of a particular image on this page