generic PDF object.
A PDF Document is essentially a collection of these objects. A PDF
Object has a number and a generation (although the generation will always
be 0 in new documents).
encode
public static final byte[] encode(String text)
Converts text to a byte array for writing to a PDF file.
text
- text to convert/encode
- byte[] the resulting byte array
encodeBinaryToHexString
protected void encodeBinaryToHexString(byte[] data,
OutputStream out)
throws IOException
Encodes binary data as hexadecimal string object.
data
- the binary dataout
- the OutputStream to write the encoded object to
encodeString
protected byte[] encodeString(String string)
Encodes a String (3.2.3 in PDF 1.4 specs)
string
- the string to encode
- byte[] the encoded string
encodeText
protected byte[] encodeText(String text)
Encodes a Text String (3.8.1 in PDF 1.4 specs)
text
- the text to encode
formatDateTime
protected String formatDateTime(Date time)
Formats a date/time according to the PDF specification.
(D:YYYYMMDDHHmmSSOHH'mm').
time
- date/time value to format
- the requested String representation
formatDateTime
protected String formatDateTime(Date time,
TimeZone tz)
Formats a date/time according to the PDF specification
(D:YYYYMMDDHHmmSSOHH'mm').
time
- date/time value to formattz
- the time zone
- the requested String representation
formatObject
protected void formatObject(Object obj,
OutputStream out,
Writer writer)
throws IOException
Formats an object for serialization to PDF.
obj
- the objectout
- the OutputStream to write towriter
- a Writer for text content (will always be a wrapper around the above
OutputStream. Make sure flush
is called when mixing calls)
getDocument
public final PDFDocument getDocument()
Returns the parent PDFDocument if assigned.
- the parent PDFDocument (May be null if the parent PDFDocument
has not been assigned)
getDocumentSafely
public final 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.
getGeneration
public int getGeneration()
Returns the object's generation.
- the PDF Object generation
getObjectID
public String getObjectID()
Returns the PDF representation of the Object ID.
getObjectNumber
public int getObjectNumber()
Returns the object's number.
getParent
public PDFObject getParent()
Returns this objects's parent. The parent is null if it is a "direct object".
- the parent or null if there's no parent (or it hasn't been set)
hasObjectNumber
public boolean hasObjectNumber()
Indicates whether this PDFObject has already been assigned an
object number.
- True if it has an object number
makeReference
public PDFReference makeReference()
Creates and returns a reference to this object.
output
protected int output(OutputStream stream)
throws IOException
Write the PDF represention of this object
stream
- the stream to write the PDF to
- the number of bytes written
outputInline
public void outputInline(OutputStream out,
Writer writer)
throws IOException
- outputInline in interface PDFWritable
referencePDF
public String referencePDF()
Returns the PDF representation of a reference to this object.
setDocument
public void setDocument(PDFDocument doc)
Sets the parent PDFDocument.
setObjectNumber
public void setObjectNumber(int objnum)
Sets the object number
objnum
- the object number
setParent
public void setParent(PDFObject parent)
Sets the direct parent object.
parent
- the direct parent
toPDF
protected byte[] toPDF()
Encodes the object as a byte array for output to a PDF file.
toPDFString
protected String toPDFString()
This method returns a String representation of the PDF object. The result
is normally converted/encoded to a byte array by toPDF(). Only use
this method to implement the serialization if the object can be fully
represented as text. If the PDF representation of the object contains
binary content use toPDF() or output(OutputStream) instead. This applies
to any object potentially containing a string object because string object
are encrypted and therefore need to be binary.
- String the String representation