public abstract class PDFObject extends java.lang.Object implements PDFWritable
Modifier and Type | Field and Description |
---|---|
protected static org.apache.commons.logging.Log |
log
logger for all PDFObjects (and descendants)
|
Constructor and Description |
---|
PDFObject()
Default constructor.
|
PDFObject(PDFObject parent)
Constructor for direct objects.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
contentEquals(PDFObject o)
Check if the other PDFObject has the same content as the current object.
|
static byte[] |
encode(java.lang.String text)
Converts text to a byte array for writing to a PDF file.
|
protected void |
encodeBinaryToHexString(byte[] data,
java.io.OutputStream out)
Encodes binary data as hexadecimal string object.
|
protected byte[] |
encodeString(java.lang.String string)
Encodes a String (3.2.3 in PDF 1.4 specs)
|
protected byte[] |
encodeText(java.lang.String text)
Encodes a Text String (3.8.1 in PDF 1.4 specs)
|
protected void |
formatObject(java.lang.Object obj,
java.io.OutputStream out,
java.lang.StringBuilder textBuffer)
Formats an object for serialization to PDF.
|
void |
getChildren(java.util.Set<PDFObject> children) |
PDFDocument |
getDocument()
Returns the parent PDFDocument if assigned.
|
PDFDocument |
getDocumentSafely()
Returns the parent PDFDocument, but unlike
getDocument()
it throws an informative Exception if the parent document is unavailable
instead of having a NullPointerException somewhere without a message. |
int |
getGeneration()
Returns this object's generation.
|
java.lang.String |
getObjectID()
Returns the PDF representation of the Object ID.
|
PDFObjectNumber |
getObjectNumber()
Returns the object's number.
|
PDFObject |
getParent()
Returns this objects's parent.
|
boolean |
hasObjectNumber()
Indicates whether this PDFObject has already been assigned an
object number.
|
PDFReference |
makeReference()
Creates and returns a reference to this object.
|
int |
output(java.io.OutputStream stream)
Write the PDF represention of this object
|
void |
outputInline(java.io.OutputStream out,
java.lang.StringBuilder textBuffer)
Writes a "direct object" (inline object) representation to the stream.
|
java.lang.String |
referencePDF()
Returns the PDF representation of a reference to this object.
|
void |
setDocument(PDFDocument doc)
Sets the parent PDFDocument.
|
void |
setObjectNumber(int objectNumber) |
void |
setObjectNumber(PDFDocument document)
Sets the object number
|
void |
setObjectNumber(PDFObjectNumber objectNumber) |
void |
setParent(PDFObject parent)
Sets the direct parent object.
|
protected byte[] |
toPDF()
Encodes the object as a byte array for output to a PDF file.
|
protected java.lang.String |
toPDFString()
This method returns a String representation of the PDF object.
|
protected static final org.apache.commons.logging.Log log
public PDFObject()
public PDFObject(PDFObject parent)
parent
- the containing PDFObject instancepublic PDFObjectNumber getObjectNumber()
public boolean hasObjectNumber()
public void setObjectNumber(PDFDocument document)
public void setObjectNumber(PDFObjectNumber objectNumber)
public void setObjectNumber(int objectNumber)
public int getGeneration()
public final PDFDocument getDocument()
public final PDFDocument getDocumentSafely()
getDocument()
it throws an informative Exception if the parent document is unavailable
instead of having a NullPointerException somewhere without a message.public void setDocument(PDFDocument doc)
doc
- the PDFDocument.public PDFObject getParent()
public void setParent(PDFObject parent)
parent
- the direct parentpublic java.lang.String getObjectID()
public java.lang.String referencePDF()
public PDFReference makeReference()
public int output(java.io.OutputStream stream) throws java.io.IOException
stream
- the stream to write the PDF tojava.io.IOException
- if there is an error writing to the streampublic void outputInline(java.io.OutputStream out, java.lang.StringBuilder textBuffer) throws java.io.IOException
IMPORTANT: If you need to write out binary output, call
PDFDocument.flushTextBuffer(StringBuilder, OutputStream)
before writing any content
to the OutputStream
!
outputInline
in interface PDFWritable
out
- the OutputStream (for binary content)textBuffer
- the text buffer for text contentjava.io.IOException
- if an I/O error occursprotected byte[] toPDF()
protected java.lang.String toPDFString()
public static final byte[] encode(java.lang.String text)
text
- text to convert/encodeprotected byte[] encodeText(java.lang.String text)
text
- the text to encodeprotected byte[] encodeString(java.lang.String string)
string
- the string to encodeprotected void encodeBinaryToHexString(byte[] data, java.io.OutputStream out) throws java.io.IOException
data
- the binary dataout
- the OutputStream to write the encoded object tojava.io.IOException
- if an I/O error occursprotected void formatObject(java.lang.Object obj, java.io.OutputStream out, java.lang.StringBuilder textBuffer) throws java.io.IOException
IMPORTANT: If you need to write out binary output, call
PDFDocument.flushTextBuffer(StringBuilder, OutputStream)
before writing any content
to the OutputStream
!
obj
- the objectout
- the OutputStream to write totextBuffer
- a text buffer for text outputjava.io.IOException
- If an I/O error occursprotected boolean contentEquals(PDFObject o)
Note: This function has a contract which is less binding than
Object.equals(Object)
. Whereas equals would require all values to be
identical, this method is not required to check everything. In the case
of PDFObjects, this means that the overriding function does not have to
check for getObjectID()
.
o
- object to compare to.public void getChildren(java.util.Set<PDFObject> children)
Copyright 1999-2017 The Apache Software Foundation. All Rights Reserved.