Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.pdfview
Class PDFFile

    java.lang.Object
      com.sun.pdfview.PDFFile

    public class PDFFile

extends java.lang.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.

Field Summary
`static int` | `FF_CHAR`
`static int` | `NUL_CHAR`

Constructor Summary
`PDFFile(java.nio.ByteBuffer buf)` get a PDFFile from a .pdf file.
`PDFFile(java.nio.ByteBuffer buf, PDFPassword password)` get a PDFFile from a .pdf file.

Method Summary
`PDFObject` | `dereference(PDFXref ref, PDFDecrypter decrypter)` Used internally to track down PDFObject references.
`PDFDecrypter` | `getDefaultDecrypter()` Get the default decrypter for the document
`int` | `getMajorVersion()` return the major version of the PDF header.
`java.util.Iterator<java.lang.String>` | `getMetadataKeys()` Get the keys into the Info metadata, for use with `getStringMetadata(String)`
`int` | `getMinorVersion()` return the minor version of the PDF header.
`int` | `getNumPages()` return the number of pages in this PDFFile.
`OutlineNode` | `getOutline()` Gets the outline tree as a tree of OutlineNode, which is a subclass of DefaultMutableTreeNode.
`PDFPage` | `getPage(int pagenum)` Get the page commands for a given page in a separate thread.
`PDFPage` | `getPage(int pagenum, boolean wait)` Get the page commands for a given page.
`int` | `getPageNumber(PDFObject page)` Gets the page number (starting from 1) of the page represented by a particular PDFObject.
`PDFObject` | `getRoot()` get the root PDFObject of this PDFFile.
`java.lang.String` | `getStringMetadata(java.lang.String name)` Get metadata (e.g., Author, Title, Creator) from the Info dictionary as a string.
`java.lang.String` | `getVersionString()` return the version string from the PDF header.
`static boolean` | `isDelimiter(int c)` Is the argument a delimiter according to the PDF spec?
`boolean` | `isPrintable()` Gets whether the owner of the file has given permission to print the file.
`static boolean` | `isRegularCharacter(int c)` return true if the character is neither a whitespace or a delimiter.
`boolean` | `isSaveable()` Gets whether the owner of the file has given permission to save a copy of the file.
`static boolean` | `isWhiteSpace(int c)` Is the argument a white space character according to the PDF spec?.
`static java.awt.geom.Rectangle2D` | `parseNormalisedRectangle(PDFObject obj)`
`void` | `stop(int pageNum)` Stop the rendering of a particular image on this page

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### NUL_CHAR

    public static final int NUL_CHAR

See Also:
  Constant Field Values

### FF_CHAR

    public static final int FF_CHAR

See Also:
  Constant Field Values

Constructor Detail

### PDFFile

    public PDFFile(java.nio.ByteBuffer buf)
            throws java.io.IOException

  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.
  Throws:
    `java.io.IOException` - if there's a problem reading from the buffer
    `PDFParseException` - if the document appears to be malformed, or its features are unsupported. If the file is encrypted in a manner that the product or platform does not support then the exception's `cause` will be an instance of `UnsupportedEncryptionException`.
    `PDFAuthenticationFailureException` - if the file is password protected and requires a password

### PDFFile

    public PDFFile(java.nio.ByteBuffer buf,
                   PDFPassword password)
            throws java.io.IOException

  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.
    `password` - the user or owner password
  Throws:
    `java.io.IOException` - if there's a problem reading from the buffer
    `PDFParseException` - if the document appears to be malformed, or its features are unsupported. If the file is encrypted in a manner that the product or platform does not support then the exception's `cause` will be an instance of `UnsupportedEncryptionException`.
    `PDFAuthenticationFailureException` - if the file is password protected and the supplied password does not decrypt the document

Method Detail

### 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

### 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.

### getNumPages

    public int getNumPages()

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

### getStringMetadata

    public java.lang.String getStringMetadata(java.lang.String name)
                                       throws java.io.IOException

  Get metadata (e.g., Author, Title, Creator) from the Info dictionary as a string.

  Parameters:
    `name` - the name of the metadata key (e.g., Author)
  Returns:
    the info
  Throws:
    `java.io.IOException` - if the metadata cannot be read

### getMetadataKeys

    public java.util.Iterator<java.lang.String> getMetadataKeys()
                                                         throws java.io.IOException

  Get the keys into the Info metadata, for use with `getStringMetadata(String)`

  Returns:
    the keys present into the Info dictionary
  Throws:
    `java.io.IOException` - if the keys cannot be read

### dereference

    public PDFObject dereference(PDFXref ref,
                                 PDFDecrypter decrypter)
                          throws java.io.IOException

  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.

  Throws:
    `java.io.IOException`

### isWhiteSpace

    public static boolean isWhiteSpace(int c)

  Is the argument a white space character according to the PDF spec?. ISO Spec 32000-1:2008 - Table 1

### isDelimiter

    public static boolean isDelimiter(int c)

  Is the argument a delimiter according to the PDF spec?

  ISO 32000-1:2008 - Table 2

  Parameters:
    `c` - the character to test

### isRegularCharacter

    public static boolean isRegularCharacter(int c)

  return true if the character is neither a whitespace or a delimiter.

  Parameters:
    `c` - the character to test
  Returns:
    boolean

### getMajorVersion

    public int getMajorVersion()

  return the major version of the PDF header.

  Returns:
    int

### getMinorVersion

    public int getMinorVersion()

  return the minor version of the PDF header.

  Returns:
    int

### getVersionString

    public java.lang.String getVersionString()

  return the version string from the PDF header.

  Returns:
    String

### getOutline

    public OutlineNode getOutline()
                           throws java.io.IOException

  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.

  Throws:
    `java.io.IOException`

### getPageNumber

    public int getPageNumber(PDFObject page)
                      throws java.io.IOException

  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.
  Throws:
    `java.io.IOException`

### 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.

### stop

    public void stop(int pageNum)

  Stop the rendering of a particular image on this page

### parseNormalisedRectangle

    public static java.awt.geom.Rectangle2D parseNormalisedRectangle(PDFObject obj)
                                                              throws java.io.IOException

  Throws:
    `java.io.IOException`

### getDefaultDecrypter

    public PDFDecrypter getDefaultDecrypter()

  Get the default decrypter for the document

  Returns:
    the default decrypter; never null, even for documents that aren't encrypted

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD