org.foray.pdf.object
Class PDFObject

java.lang.Object
  extended by org.foray.pdf.object.PDFObject
Direct Known Subclasses:
PDFAction, PDFAnnotation, PDFAnnotList, PDFArray, PDFBorderStyle, PDFCharProcs, PDFCIDFont, PDFCIDSystemInfo, PDFDate, PDFDestination, PDFEncoding, PDFEncryption, PDFFileSpec, PDFFont, PDFFontDescriptor, PDFFunction, PDFInfo, PDFNameTree, PDFNumberTree, PDFOutlineParent, PDFPage, PDFPageLabel, PDFPages, PDFPathPaint, PDFResources, PDFRoot, PDFShading, PDFStream, PDFString, PDFTextString

public abstract class PDFObject
extends Object

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
static String EOL
          The String that should be used to end a line in the PDF document.
static String MSG_EOL
          The String that should be used to end a line in log messages.
static String XREF_EOL
          The String that should be used to end a cross-reference line in the PDF document.
 
Constructor Summary
PDFObject()
          No-parameter constructor, useful for objects that are not tied to a specific PDF document.
PDFObject(PDFDocument doc)
          Create an empty object.
 
Method Summary
protected static byte[] bufferToByteArray(StringBuilder buffer)
          Converts a StringBuilder buffer to an array of bytes.
protected  void byteArrayToStream(byte[] bytes, OutputStream stream)
          Writes the content of a byte array to an output stream.
 int getCharsPerLine()
          Return the number of characters per line that should be written into the PDF.
 int getGeneration()
          Returns this object's generation number.
 org.apache.commons.logging.Log getLogger()
          Returns the logger to be used for user messages.
 int getNumber()
          Returns this object's number.
 PDFDocument getPDFDocument()
          Returns the parent PDF document.
protected  int output(OutputStream stream)
          Write the PDF represention of this object to a given output stream.
protected  String pdfID()
          The String used to identify this object as it is written in the PDF.
 String pdfReference()
          The String used to reference this object within the PDF.
protected  void setNumber(int number)
          Sets this object's number if it has not already been set.
protected static byte[] stringToByteArray(String string)
          Converts a String to an array of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOL

public static final String EOL
The String that should be used to end a line in the PDF document. Note that this always uses the Unix-style line ending, as it is more compact, and as the PDF generated should be identical, regardless of the platform from which it is generated.

See Also:
Constant Field Values

XREF_EOL

public static final String XREF_EOL
The String that should be used to end a cross-reference line in the PDF document. According to the PDF Reference, 3rd Edition, Section 3.4.3, each cross-reference entry must be exactly 20 bytes long, including the end-of-line character(s). If a 1-character eol is used (such as a newline), then an extra character must be padded. According to the Reference, that character must be a space. However, a space at the end of a line is often removed by editors, so we use a hyphen instead.

See Also:
Constant Field Values

MSG_EOL

public static final String MSG_EOL
The String that should be used to end a line in log messages.

Constructor Detail

PDFObject

public PDFObject(PDFDocument doc)
Create an empty object.

Parameters:
doc - The PDFDocument to which this object is attached.

PDFObject

public PDFObject()
No-parameter constructor, useful for objects that are not tied to a specific PDF document.

Method Detail

setNumber

protected void setNumber(int number)
Sets this object's number if it has not already been set.

Parameters:
number - The new object number.

getNumber

public int getNumber()
Returns this object's number.

Returns:
The PDF Object number.

getGeneration

public int getGeneration()
Returns this object's generation number.

Returns:
The PDF generation number.

output

protected int output(OutputStream stream)
              throws org.axsl.pdf.PdfException
Write the PDF represention of this object to a given output stream.

Parameters:
stream - The stream to which the PDF content is being written.
Returns:
The number of bytes written.
Throws:
org.axsl.pdf.PdfException - For I/O errors during output.

pdfReference

public String pdfReference()
The String used to reference this object within the PDF.

Returns:
The String used to reference this object within the PDF.

pdfID

protected String pdfID()
The String used to identify this object as it is written in the PDF.

Returns:
The String used to identify this object as it is written in the PDF.

bufferToByteArray

protected static byte[] bufferToByteArray(StringBuilder buffer)
Converts a StringBuilder buffer to an array of bytes.

Parameters:
buffer - The input StringBuilder.
Returns:
A properly-encoded array of bytes.

stringToByteArray

protected static byte[] stringToByteArray(String string)
Converts a String to an array of bytes.

Parameters:
string - The input String.
Returns:
A properly-encoded array of bytes.

byteArrayToStream

protected void byteArrayToStream(byte[] bytes,
                                 OutputStream stream)
                          throws org.axsl.pdf.PdfException
Writes the content of a byte array to an output stream.

Parameters:
stream - The stream to which the array should be written.
bytes - The array to be written.
Throws:
org.axsl.pdf.PdfException - For IO errors during output.

getLogger

public org.apache.commons.logging.Log getLogger()
Returns the logger to be used for user messages.

Returns:
The logger.

getPDFDocument

public PDFDocument getPDFDocument()
Returns the parent PDF document.

Returns:
The parent PDF document.

getCharsPerLine

public int getCharsPerLine()
Return the number of characters per line that should be written into the PDF.

Returns:
The number of characters per line that should be written into the PDF.


Copyright © 2017. All rights reserved.