com.sun.pdfview

Class PDFObject

public class PDFObject extends Object

a class encapsulating all the possibilities of content for an object in a PDF file.

A PDF object can be a simple type, like a Boolean, a Number, a String, or the Null value. It can also be a NAME, which looks like a string, but is a special type in PDF files, like "/Name".

A PDF object can also be complex types, including Array; Dictionary; Stream, which is a Dictionary plus an array of bytes; or Indirect, which is a reference to some other PDF object. Indirect references will always be dereferenced by the time any data is returned from one of the methods in this class.

Field Summary
static intARRAY
an array of PDFObjects
static intBOOLEAN
a Boolean
static intDICTIONARY
a Hashmap that maps String names to PDFObjects
static intINDIRECT
an indirect reference
static intKEYWORD
a special PDF bare word, like R, obj, true, false, etc
static PDFObjectnullObj
the NULL PDFObject
static intNAME
a special string, seen in PDF files as /Name
static intNULL
the NULL object (there is only one)
static intNUMBER
a Number, represented as a double
static intSTREAM
a Stream: a Hashmap with a byte array
static intSTRING
a String
Constructor Summary
PDFObject(PDFFile owner, int type, Object value)
create a new simple PDFObject with a type and a value
PDFObject(Object obj)
create a new PDFObject that is the closest match to a given Java object.
PDFObject(PDFFile owner, PDFXref xref)
create a new PDFObject based on a PDFXref
Method Summary
PDFObjectdereference()
Make sure that this object is dereferenced.
PDFObject[]getArray()
get the value as a PDFObject[].
PDFObjectgetAt(int idx)
if this object is an ARRAY, get the PDFObject at some position in the array.
booleangetBooleanValue()
get the value as a boolean.
ObjectgetCache()
get the value in the cache.
HashMapgetDictionary()
get the dictionary as a HashMap.
IteratorgetDictKeys()
get an Iterator over all the keys in the dictionary.
PDFObjectgetDictRef(String key)
get the value associated with a particular key in the dictionary.
doublegetDoubleValue()
get the value as a double.
floatgetFloatValue()
get the value as a float.
intgetIntValue()
get the value as an int.
byte[]getStream()
get the stream from this object.
ByteBuffergetStreamBuffer()
get the stream from this object as a byte buffer.
StringgetStringValue()
get the value as a String.
intgetType()
get the type of this object.
booleanisDictType(String match)
returns true only if this object is a DICTIONARY or a STREAM, and the "Type" entry in the dictionary matches a given value.
voidsetCache(Object obj)
set the cached value.
voidsetStream(ByteBuffer data)
set the stream of this object.

Field Detail

ARRAY

public static final int ARRAY
an array of PDFObjects

BOOLEAN

public static final int BOOLEAN
a Boolean

DICTIONARY

public static final int DICTIONARY
a Hashmap that maps String names to PDFObjects

INDIRECT

public static final int INDIRECT
an indirect reference

KEYWORD

public static final int KEYWORD
a special PDF bare word, like R, obj, true, false, etc

nullObj

public static final PDFObject nullObj
the NULL PDFObject

NAME

public static final int NAME
a special string, seen in PDF files as /Name

NULL

public static final int NULL
the NULL object (there is only one)

NUMBER

public static final int NUMBER
a Number, represented as a double

STREAM

public static final int STREAM
a Stream: a Hashmap with a byte array

STRING

public static final int STRING
a String

Constructor Detail

PDFObject

public PDFObject(PDFFile owner, int type, Object value)
create a new simple PDFObject with a type and a value

Parameters: owner the PDFFile in which this object resides, used for dereferencing. This may be null. type the type of object value the value. For DICTIONARY, this is a HashMap. for ARRAY it's an ArrayList. For NUMBER, it's a Double. for BOOLEAN, it's Boolean.TRUE or Boolean.FALSE. For everything else, it's a String.

PDFObject

public PDFObject(Object obj)
create a new PDFObject that is the closest match to a given Java object. Possibilities include Double, String, PDFObject[], HashMap, Boolean, or PDFParser.Tok, which should be "true" or "false" to turn into a BOOLEAN.

Parameters: obj the sample Java object to convert to a PDFObject.

Throws: PDFParseException if the object isn't one of the above examples, and can't be turned into a PDFObject.

PDFObject

public PDFObject(PDFFile owner, PDFXref xref)
create a new PDFObject based on a PDFXref

Parameters: owner the PDFFile from which the PDFXref was drawn xref the PDFXref to turn into a PDFObject

Method Detail

dereference

public PDFObject dereference()
Make sure that this object is dereferenced. Use the cache of an indirect object to cache the dereferenced value, if possible.

getArray

public PDFObject[] getArray()
get the value as a PDFObject[]. If this object is an ARRAY, will return the array. Otherwise, will return an array of one element with this object as the element.

getAt

public PDFObject getAt(int idx)
if this object is an ARRAY, get the PDFObject at some position in the array. If this is not an ARRAY, returns null.

getBooleanValue

public boolean getBooleanValue()
get the value as a boolean. Will return false if this object is not a BOOLEAN

getCache

public Object getCache()
get the value in the cache. May become null at any time.

Returns: the cached value, or null if the value has been garbage collected.

getDictionary

public HashMap getDictionary()
get the dictionary as a HashMap. If this isn't a DICTIONARY or a STREAM, returns null

getDictKeys

public Iterator getDictKeys()
get an Iterator over all the keys in the dictionary. If this object is not a DICTIONARY or a STREAM, returns an Iterator over the empty list.

getDictRef

public PDFObject getDictRef(String key)
get the value associated with a particular key in the dictionary. If this isn't a DICTIONARY or a STREAM, or there is no such key, returns null.

getDoubleValue

public double getDoubleValue()
get the value as a double. Will return 0 if this object isn't a NUMBER.

getFloatValue

public float getFloatValue()
get the value as a float. Will return 0 if this object isn't a NUMBER

getIntValue

public int getIntValue()
get the value as an int. Will return 0 if this object isn't a NUMBER.

getStream

public byte[] getStream()
get the stream from this object. Will return null if this object isn't a STREAM.

Returns: the stream, or null, if this isn't a STREAM.

getStreamBuffer

public ByteBuffer getStreamBuffer()
get the stream from this object as a byte buffer. Will return null if this object isn't a STREAM.

Returns: the buffer, or null, if this isn't a STREAM.

getStringValue

public String getStringValue()
get the value as a String. Will return null if the object isn't a STRING, NAME, or KEYWORD. This method will NOT convert a NUMBER to a String.

getType

public int getType()
get the type of this object. The object will be dereferenced, so INDIRECT will never be returned.

Returns: the type of the object

isDictType

public boolean isDictType(String match)
returns true only if this object is a DICTIONARY or a STREAM, and the "Type" entry in the dictionary matches a given value.

Parameters: match the expected value for the "Type" key in the dictionary

Returns: whether the dictionary is of the expected type

setCache

public void setCache(Object obj)
set the cached value. The object may be garbage collected if no other reference exists to it.

Parameters: obj the object to be cached

setStream

public void setStream(ByteBuffer data)
set the stream of this object. It should have been a DICTIONARY before the call.

Parameters: data the data, as a ByteBuffer.