public class PDFObject
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY
an array of PDFObjects
|
static int |
BOOLEAN
a Boolean
|
static int |
DICTIONARY
a Hashmap that maps String names to PDFObjects
|
static int |
INDIRECT
an indirect reference
|
static int |
KEYWORD
a special PDF bare word, like R, obj, true, false, etc
|
static int |
NAME
a special string, seen in PDF files as /Name
|
static int |
NULL
the NULL object (there is only one)
|
static PDFObject |
nullObj
the NULL PDFObject
|
static int |
NUMBER
a Number, represented as a double
|
static int |
OBJ_NUM_EMBEDDED
|
static int |
OBJ_NUM_TRAILER
|
static int |
STREAM
a Stream: a Hashmap with a byte array
|
static int |
STRING
a String
|
Constructor and Description |
---|
PDFObject(java.lang.Object obj)
create a new PDFObject that is the closest match to a
given Java object.
|
PDFObject(PDFFile owner,
int type,
java.lang.Object value)
create a new simple PDFObject with a type and a value
|
PDFObject(PDFFile owner,
PDFXref xref)
create a new PDFObject based on a PDFXref
|
Modifier and Type | Method and Description |
---|---|
PDFObject |
dereference()
Make sure that this object is dereferenced.
|
boolean |
equals(java.lang.Object o)
Test whether two PDFObject are equal.
|
PDFObject[] |
getArray()
get the value as a PDFObject[].
|
PDFObject |
getAt(int idx)
if this object is an ARRAY, get the PDFObject at some
position in the array.
|
boolean |
getBooleanValue()
get the value as a boolean.
|
java.lang.Object |
getCache()
get the value in the cache.
|
PDFDecrypter |
getDecrypter() |
java.util.HashMap<java.lang.String,PDFObject> |
getDictionary()
get the dictionary as a HashMap.
|
java.util.Iterator |
getDictKeys()
get an Iterator over all the keys in the dictionary.
|
PDFObject |
getDictRef(java.lang.String key)
get the value associated with a particular key in the
dictionary.
|
double |
getDoubleValue()
get the value as a double.
|
float |
getFloatValue()
get the value as a float.
|
int |
getIntValue()
get the value as an int.
|
int |
getObjGen()
Get the object generation number of this object; a negative value
indicates that the object is not numbered, as it's not a top-level
object: if the value is
OBJ_NUM_EMBEDDED , it is because it's
embedded within another object. |
int |
getObjNum()
Get the object number of this object; a negative value indicates that
the object is not numbered, as it's not a top-level object: if the value
is
OBJ_NUM_EMBEDDED , it is because it's embedded within
another object. |
byte[] |
getStream()
get the stream from this object.
|
byte[] |
getStream(java.util.Set<java.lang.String> filterLimits) |
java.nio.ByteBuffer |
getStreamBuffer()
get the stream from this object as a byte buffer.
|
java.nio.ByteBuffer |
getStreamBuffer(java.util.Set<java.lang.String> filterLimits)
get the stream from this object as a byte buffer.
|
java.lang.String |
getStringValue()
get the value as a String.
|
java.lang.String |
getTextStringValue()
Get the value as a text string; i.e., a string encoded in UTF-16BE
or PDFDocEncoding.
|
int |
getType()
get the type of this object.
|
boolean |
isDictType(java.lang.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.
|
boolean |
isIndirect()
Identify whether the object is currently an indirect/cross-reference
|
void |
setCache(java.lang.Object obj)
set the cached value.
|
void |
setObjectId(int objNum,
int objGen)
Set the object identifiers
|
void |
setStream(java.nio.ByteBuffer data)
set the stream of this object.
|
java.lang.String |
toString()
return a representation of this PDFObject as a String.
|
public static final int INDIRECT
public static final int BOOLEAN
public static final int NUMBER
public static final int STRING
public static final int NAME
public static final int ARRAY
public static final int DICTIONARY
public static final int STREAM
public static final int NULL
public static final int KEYWORD
public static final int OBJ_NUM_EMBEDDED
objNum
or objGen
,
indicates that the object is not top-level, and is embedded in another
objectpublic static final int OBJ_NUM_TRAILER
objNum
or objGen
,
indicates that the object is not top-level, and is embedded directly
in the trailer.public static final PDFObject nullObj
public PDFObject(PDFFile owner, int type, java.lang.Object value)
owner
- the PDFFile in which this object resides, used
for dereferencing. This may be null.type
- the type of objectvalue
- 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.public PDFObject(java.lang.Object obj) throws PDFParseException
obj
- the sample Java object to convert to a PDFObject.PDFParseException
- if the object isn't one of the
above examples, and can't be turned into a PDFObject.public int getType() throws java.io.IOException
java.io.IOException
public void setStream(java.nio.ByteBuffer data)
data
- the data, as a ByteBuffer.public java.lang.Object getCache() throws java.io.IOException
java.io.IOException
public void setCache(java.lang.Object obj) throws java.io.IOException
obj
- the object to be cachedjava.io.IOException
public byte[] getStream(java.util.Set<java.lang.String> filterLimits) throws java.io.IOException
java.io.IOException
public byte[] getStream() throws java.io.IOException
java.io.IOException
public java.nio.ByteBuffer getStreamBuffer() throws java.io.IOException
java.io.IOException
public java.nio.ByteBuffer getStreamBuffer(java.util.Set<java.lang.String> filterLimits) throws java.io.IOException
java.io.IOException
public int getIntValue() throws java.io.IOException
java.io.IOException
public float getFloatValue() throws java.io.IOException
java.io.IOException
public double getDoubleValue() throws java.io.IOException
java.io.IOException
public java.lang.String getStringValue() throws java.io.IOException
getTextStringValue()
or use one
of the PDFStringUtil
methods on the result from this
method. The string value represents exactly the sequence of 8 bit
characters present in the file, decrypted and decoded as appropriate,
into a string containing only 8 bit character values - that is, each
char will be between 0 and 255.java.io.IOException
public java.lang.String getTextStringValue() throws java.io.IOException
java.io.IOException
public PDFObject[] getArray() throws java.io.IOException
java.io.IOException
public boolean getBooleanValue() throws java.io.IOException
java.io.IOException
public PDFObject getAt(int idx) throws java.io.IOException
java.io.IOException
public java.util.Iterator getDictKeys() throws java.io.IOException
java.io.IOException
public java.util.HashMap<java.lang.String,PDFObject> getDictionary() throws java.io.IOException
java.io.IOException
public PDFObject getDictRef(java.lang.String key) throws java.io.IOException
java.io.IOException
public boolean isDictType(java.lang.String match) throws java.io.IOException
match
- the expected value for the "Type" key in the
dictionaryjava.io.IOException
public PDFDecrypter getDecrypter()
public void setObjectId(int objNum, int objGen)
objNum
- the object numberobjGen
- the object generation numberpublic int getObjNum()
OBJ_NUM_EMBEDDED
, it is because it's embedded within
another object. If the value is OBJ_NUM_TRAILER
, it's because
it's an object from the trailer.public int getObjGen()
OBJ_NUM_EMBEDDED
, it is because it's
embedded within another object. If the value is OBJ_NUM_TRAILER
, it's because it's an object from the trailer.public java.lang.String toString()
toString
in class java.lang.Object
public PDFObject dereference() throws java.io.IOException
java.io.IOException
public boolean isIndirect()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object