Class PdfObject
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfObject
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
PdfArray
,PdfBoolean
,PdfDictionary
,PdfIndirectReference
,PdfLiteral
,PdfName
,PdfNull
,PdfNumber
,PdfString
public abstract class PdfObject extends java.lang.Object implements java.io.Serializable
PdfObject
is the abstract superclass of all PDF objects.PDF supports seven basic types of objects: Booleans, numbers, strings, names, arrays, dictionaries and streams. In addition, PDF provides a null object. Objects may be labeled so that they can be referred to by other objects.
All these basic PDF objects are described in the 'Portable Document Format Reference Manual version 1.3' Chapter 4 (pages 37-54).- See Also:
PdfNull
,PdfBoolean
,PdfNumber
,PdfString
,PdfName
,PdfArray
,PdfDictionary
,PdfStream
,PdfIndirectReference
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
ARRAY
A possible type ofPdfObject
static int
BOOLEAN
A possible type ofPdfObject
protected byte[]
bytes
The content of thisPdfObject
static int
DICTIONARY
A possible type ofPdfObject
static int
INDIRECT
A possible type ofPdfObject
protected PRIndirectReference
indRef
Holds the indirect reference.static int
NAME
A possible type ofPdfObject
static java.lang.String
NOTHING
An empty string used for thePdfNull
-object and for an emptyPdfString
-object.static int
NULL
A possible type ofPdfObject
static int
NUMBER
A possible type ofPdfObject
static int
STREAM
A possible type ofPdfObject
static int
STRING
A possible type ofPdfObject
static java.lang.String
TEXT_PDFDOCENCODING
This is the default encoding to be used for converting Strings into bytes and vice versa.static java.lang.String
TEXT_UNICODE
This is the encoding to be used to output text in Unicode.protected int
type
The type of thisPdfObject
-
Constructor Summary
Constructors Modifier Constructor Description protected
PdfObject(int type)
Constructs aPdfObject
of a certain type without any content.protected
PdfObject(int type, byte[] bytes)
Constructs aPdfObject
of a certain type with a certain content.protected
PdfObject(int type, java.lang.String content)
Constructs aPdfObject
of a certain type with a certain content.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBeInObjStm()
Whether this object can be contained in an object stream.byte[]
getBytes()
Gets the presentation of this object in a byte arrayPRIndirectReference
getIndRef()
Get the indirect referenceboolean
isArray()
Checks if thisPdfObject
is of the typePdfArray
.boolean
isBoolean()
Checks if thisPdfObject
is of the typePdfBoolean
.boolean
isDictionary()
Checks if thisPdfObject
is of the typePdfDictionary
.boolean
isIndirect()
Checks if thisPdfObject
is of the typePdfIndirectObject
.boolean
isName()
Checks if thisPdfObject
is of the typePdfName
.boolean
isNull()
Checks if thisPdfObject
is of the typePdfNull
.boolean
isNumber()
Checks if thisPdfObject
is of the typePdfNumber
.boolean
isStream()
Checks if thisPdfObject
is of the typePdfStream
.boolean
isString()
Checks if thisPdfObject
is of the typePdfString
.int
length()
Returns the length of the actual content of thePdfObject
.protected void
setContent(java.lang.String content)
Changes the content of thisPdfObject
.void
setIndRef(PRIndirectReference indRef)
Set the indirect referencevoid
toPdf(PdfWriter writer, java.io.OutputStream os)
Writes the PDF representation of thisPdfObject
as an array ofbyte
s to the writer.java.lang.String
toString()
Returns theString
-representation of thisPdfObject
.int
type()
Returns the type of thisPdfObject
.
-
-
-
Field Detail
-
BOOLEAN
public static final int BOOLEAN
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
NUMBER
public static final int NUMBER
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
STRING
public static final int STRING
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
NAME
public static final int NAME
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
ARRAY
public static final int ARRAY
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
DICTIONARY
public static final int DICTIONARY
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
STREAM
public static final int STREAM
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
NULL
public static final int NULL
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
INDIRECT
public static final int INDIRECT
A possible type ofPdfObject
- See Also:
- Constant Field Values
-
NOTHING
public static final java.lang.String NOTHING
An empty string used for thePdfNull
-object and for an emptyPdfString
-object.- See Also:
- Constant Field Values
-
TEXT_PDFDOCENCODING
public static final java.lang.String TEXT_PDFDOCENCODING
This is the default encoding to be used for converting Strings into bytes and vice versa. The default encoding is PdfDocEncoding.- See Also:
- Constant Field Values
-
TEXT_UNICODE
public static final java.lang.String TEXT_UNICODE
This is the encoding to be used to output text in Unicode.- See Also:
- Constant Field Values
-
bytes
protected byte[] bytes
The content of thisPdfObject
-
type
protected int type
The type of thisPdfObject
-
indRef
protected PRIndirectReference indRef
Holds the indirect reference.
-
-
Constructor Detail
-
PdfObject
protected PdfObject(int type)
Constructs aPdfObject
of a certain type without any content.- Parameters:
type
- type of the newPdfObject
-
PdfObject
protected PdfObject(int type, java.lang.String content)
Constructs aPdfObject
of a certain type with a certain content.- Parameters:
type
- type of the newPdfObject
content
- content of the newPdfObject
as aString
.
-
PdfObject
protected PdfObject(int type, byte[] bytes)
Constructs aPdfObject
of a certain type with a certain content.- Parameters:
type
- type of the newPdfObject
bytes
- content of the newPdfObject
as an array ofbyte
.
-
-
Method Detail
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Writes the PDF representation of thisPdfObject
as an array ofbyte
s to the writer.- Parameters:
writer
- for backwards compatibilityos
- TheOutputStream
to write the bytes to.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Returns theString
-representation of thisPdfObject
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a
String
-
getBytes
public byte[] getBytes()
Gets the presentation of this object in a byte array- Returns:
- a byte array
-
canBeInObjStm
public boolean canBeInObjStm()
Whether this object can be contained in an object stream. PdfObjects of type STREAM OR INDIRECT can not be contained in an object stream.- Returns:
true
if this object can be in an object stream. Otherwisefalse
-
length
public int length()
Returns the length of the actual content of thePdfObject
.In some cases, namely for
PdfString
andPdfStream
, this method differs from the methodpdfLength
becausepdfLength
returns the length of the PDF representation of the object, not of the actual content as does the methodlength
.Remark: the actual content of an object is in some cases identical to its representation. The following statement is always true: length() >= pdfLength().
- Returns:
- The length as
int
-
setContent
protected void setContent(java.lang.String content)
Changes the content of thisPdfObject
.- Parameters:
content
- the new content of thisPdfObject
-
type
public int type()
Returns the type of thisPdfObject
. May be either of: - NULL: APdfNull
- BOOLEAN: APdfBoolean
- NUMBER: APdfNumber
- STRING: APdfString
- NAME: APdfName
- ARRAY: APdfArray
- DICTIONARY: APdfDictionary
- STREAM: APdfStream
- INDIRECT: >PdfIndirectObject
- Returns:
- The type
-
isNull
public boolean isNull()
Checks if thisPdfObject
is of the typePdfNull
.- Returns:
true
orfalse
-
isBoolean
public boolean isBoolean()
Checks if thisPdfObject
is of the typePdfBoolean
.- Returns:
true
orfalse
-
isNumber
public boolean isNumber()
Checks if thisPdfObject
is of the typePdfNumber
.- Returns:
true
orfalse
-
isString
public boolean isString()
Checks if thisPdfObject
is of the typePdfString
.- Returns:
true
orfalse
-
isName
public boolean isName()
Checks if thisPdfObject
is of the typePdfName
.- Returns:
true
orfalse
-
isArray
public boolean isArray()
Checks if thisPdfObject
is of the typePdfArray
.- Returns:
true
orfalse
-
isDictionary
public boolean isDictionary()
Checks if thisPdfObject
is of the typePdfDictionary
.- Returns:
true
orfalse
-
isStream
public boolean isStream()
Checks if thisPdfObject
is of the typePdfStream
.- Returns:
true
orfalse
-
isIndirect
public boolean isIndirect()
Checks if thisPdfObject
is of the typePdfIndirectObject
.- Returns:
true
if this is an indirect object, otherwisefalse
-
getIndRef
public PRIndirectReference getIndRef()
Get the indirect reference- Returns:
- A
PdfIndirectReference
-
setIndRef
public void setIndRef(PRIndirectReference indRef)
Set the indirect reference- Parameters:
indRef
- New value as aPdfIndirectReference
-
-