fop 0.94

org.apache.fop.pdf
Class PDFObject

java.lang.Object
  extended by org.apache.fop.pdf.PDFObject
All Implemented Interfaces:
PDFWritable
Direct Known Subclasses:
AbstractPDFStream, PDFAction, PDFAnnotList, PDFArray, PDFCharProcs, PDFCIDFont, PDFCIDSystemInfo, PDFDestination, PDFDictionary, PDFEncoding, PDFEncryptionJCE, PDFFileSpec, PDFFont, PDFFontDescriptor, PDFFunction, PDFGState, PDFICCBasedColorSpace, PDFInfo, PDFLink, PDFNumber, PDFOutline, PDFOutputIntent, PDFPages, PDFPathPaint, PDFResourceContext, PDFResources, PDFRoot, PDFShading, PDFText, TransitionDictionary

public abstract class PDFObject
extends java.lang.Object
implements PDFWritable

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).


Field Summary
protected static java.text.SimpleDateFormat DATE_FORMAT
          Formatting pattern for PDF date
protected static org.apache.commons.logging.Log log
          logger for all PDFObjects (and descendants)
 
Constructor Summary
PDFObject()
           
 
Method Summary
static byte[] encode(java.lang.String text)
          Converts text to a byte array for writing to a PDF file.
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  java.lang.String formatDateTime(java.util.Date time)
          Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm').
protected  void formatObject(java.lang.Object obj, java.lang.StringBuffer sb)
          Formats an object for serialization to PDF.
 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 the object's generation.
 java.lang.String getObjectID()
          Returns the PDF representation of the Object ID.
 int getObjectNumber()
          Returns the object's number.
 boolean hasObjectNumber()
          Indicates whether this PDFObject has already been assigned an object number.
 PDFReference makeReference()
          Creates and returns a reference to this object.
protected  int output(java.io.OutputStream stream)
          Write the PDF represention of this object
 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 objnum)
          Sets the object number
 java.lang.String toInlinePDFString()
          Returns a representation of this object for in-object placement, i.e.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
logger for all PDFObjects (and descendants)


DATE_FORMAT

protected static final java.text.SimpleDateFormat DATE_FORMAT
Formatting pattern for PDF date

Constructor Detail

PDFObject

public PDFObject()
Method Detail

getObjectNumber

public int getObjectNumber()
Returns the object's number.

Returns:
the PDF Object number

hasObjectNumber

public boolean hasObjectNumber()
Indicates whether this PDFObject has already been assigned an object number.

Returns:
True if it has an object number

setObjectNumber

public void setObjectNumber(int objnum)
Sets the object number

Parameters:
objnum - the object number

getGeneration

public int getGeneration()
Returns the object's generation.

Returns:
the PDF Object generation

getDocument

public final PDFDocument getDocument()
Returns the parent PDFDocument if assigned.

Returns:
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.

Returns:
the parent PDFDocument

setDocument

public void setDocument(PDFDocument doc)
Sets the parent PDFDocument.

Parameters:
doc - the PDFDocument.

getObjectID

public java.lang.String getObjectID()
Returns the PDF representation of the Object ID.

Returns:
the Object ID

referencePDF

public java.lang.String referencePDF()
Returns the PDF representation of a reference to this object.

Returns:
the reference string

makeReference

public PDFReference makeReference()
Creates and returns a reference to this object.

Returns:
the object reference

output

protected int output(java.io.OutputStream stream)
              throws java.io.IOException
Write the PDF represention of this object

Parameters:
stream - the stream to write the PDF to
Returns:
the number of bytes written
Throws:
java.io.IOException - if there is an error writing to the stream

toPDF

protected byte[] toPDF()
Encodes the object as a byte array for output to a PDF file.

Returns:
PDF string

toPDFString

protected java.lang.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.

Returns:
String the String representation

toInlinePDFString

public java.lang.String toInlinePDFString()
Returns a representation of this object for in-object placement, i.e. if the object has an object number its reference is returned. Otherwise, its PDF representation is returned.

Specified by:
toInlinePDFString in interface PDFWritable
Returns:
the String representation

encode

public static final byte[] encode(java.lang.String text)
Converts text to a byte array for writing to a PDF file.

Parameters:
text - text to convert/encode
Returns:
byte[] the resulting byte array

encodeText

protected byte[] encodeText(java.lang.String text)
Encodes a Text String (3.8.1 in PDF 1.4 specs)

Parameters:
text - the text to encode
Returns:
byte[] the encoded text

encodeString

protected byte[] encodeString(java.lang.String string)
Encodes a String (3.2.3 in PDF 1.4 specs)

Parameters:
string - the string to encode
Returns:
byte[] the encoded string

formatObject

protected void formatObject(java.lang.Object obj,
                            java.lang.StringBuffer sb)
Formats an object for serialization to PDF.

Parameters:
obj - the object
sb - the StringBuffer to write to

formatDateTime

protected java.lang.String formatDateTime(java.util.Date time)
Formats a date/time according to the PDF specification (D:YYYYMMDDHHmmSSOHH'mm').

Parameters:
time - date/time value to format
Returns:
the requested String representation

fop 0.94

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.