public class PDFObject extends 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(Object obj)
create a new PDFObject that is the closest match to a
given Java object.
|
PDFObject(PDFFile owner,
int type,
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(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.
|
Object |
getCache()
get the value in the cache.
|
PDFDecrypter |
getDecrypter() |
HashMap<String,PDFObject> |
getDictionary()
get the dictionary as a HashMap.
|
Iterator |
getDictKeys()
get an Iterator over all the keys in the dictionary.
|
PDFObject |
getDictRef(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.
|
ByteBuffer |
getStreamBuffer()
get the stream from this object as a byte buffer.
|
String |
getStringValue()
get the value as a String.
|
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(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(Object obj)
set the cached value.
|
void |
setObjectId(int objNum,
int objGen)
Set the object identifiers
|
void |
setStream(ByteBuffer data)
set the stream of this object.
|
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, 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(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 IOException
IOExceptionpublic void setStream(ByteBuffer data)
data - the data, as a ByteBuffer.public Object getCache() throws IOException
IOExceptionpublic void setCache(Object obj) throws IOException
obj - the object to be cachedIOExceptionpublic byte[] getStream()
throws IOException
IOExceptionpublic ByteBuffer getStreamBuffer() throws IOException
IOExceptionpublic int getIntValue()
throws IOException
IOExceptionpublic float getFloatValue()
throws IOException
IOExceptionpublic double getDoubleValue()
throws IOException
IOExceptionpublic String getStringValue() throws 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.IOExceptionpublic String getTextStringValue() throws IOException
IOExceptionpublic PDFObject[] getArray() throws IOException
IOExceptionpublic boolean getBooleanValue()
throws IOException
IOExceptionpublic PDFObject getAt(int idx) throws IOException
IOExceptionpublic Iterator getDictKeys() throws IOException
IOExceptionpublic HashMap<String,PDFObject> getDictionary() throws IOException
IOExceptionpublic PDFObject getDictRef(String key) throws IOException
IOExceptionpublic boolean isDictType(String match) throws IOException
match - the expected value for the "Type" key in the
dictionaryIOExceptionpublic 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 String toString()
public PDFObject dereference() throws IOException
IOExceptionpublic boolean isIndirect()
Copyright © 2024. All rights reserved.