org.apache.pdfbox.pdfwriter
Class COSWriter

java.lang.Object
  extended by org.apache.pdfbox.pdfwriter.COSWriter
All Implemented Interfaces:
ICOSVisitor

public class COSWriter
extends Object
implements ICOSVisitor

this class acts on a in-memory representation of a pdf document. todo no support for incremental updates todo single xref section only todo no linearization

Version:
$Revision: 1.36 $
Author:
Michael Traut, Ben Litchfield

Field Summary
static byte[] ARRAY_CLOSE
          The array close token.
static byte[] ARRAY_OPEN
          The array open token.
static byte[] COMMENT
          The start to a PDF comment.
static byte[] DICT_CLOSE
          The dictionary close token.
static byte[] DICT_OPEN
          The dictionary open token.
static byte[] ENDOBJ
          The end object token.
static byte[] ENDSTREAM
          The close stream token.
static byte[] EOF
          The EOF constant.
static byte[] GARBAGE
          Garbage bytes used to create the PDF header.
static byte[] OBJ
          The starting object token.
static byte[] REFERENCE
          The reference token.
static byte[] SPACE
          space character.
static byte[] STARTXREF
          The start xref token.
static byte[] STREAM
          The open stream token.
static byte[] TRAILER
          The trailer token.
static byte[] VERSION
          The output version of the PDF.
static byte[] XREF
          The XREF token.
static byte[] XREF_FREE
          The xref free token.
static byte[] XREF_USED
          The xref used token.
 
Constructor Summary
COSWriter(OutputStream os)
          COSWriter constructor comment.
 
Method Summary
protected  void addXRefEntry(COSWriterXRefEntry entry)
          add an entry in the x ref table for later dump.
 void close()
          This will close the stream.
protected  void doWriteBody(COSDocument doc)
          This will write the body of the document.
protected  void doWriteHeader(COSDocument doc)
          This will write the header to the PDF document.
 void doWriteObject(COSBase obj)
          This will write a COS object.
protected  void doWriteTrailer(COSDocument doc)
          This will write the trailer to the PDF document.
protected  void doWriteXRef(COSDocument doc)
          write the x ref section for the pdf file currently, the pdf is reconstructed from the scratch, so we write a single section todo support for incremental writing?
protected  long getNumber()
          This will get the current object number.
 Map getObjectKeys()
          This will get all available object keys.
protected  OutputStream getOutput()
          This will get the output stream.
protected  COSStandardOutputStream getStandardOutput()
          This will get the standard output stream.
protected  long getStartxref()
          This will get the current start xref.
protected  List getXRefEntries()
          This will get the xref entries.
protected  void setNumber(long newNumber)
          This will set the current object number.
protected  void setStartxref(long newStartxref)
          This will set the start xref.
 Object visitFromArray(COSArray obj)
          visitFromArray method comment.
 Object visitFromBoolean(COSBoolean obj)
          visitFromBoolean method comment.
 Object visitFromDictionary(COSDictionary obj)
          visitFromDictionary method comment.
 Object visitFromDocument(COSDocument doc)
          The visit from document method.
 Object visitFromFloat(COSFloat obj)
          visitFromFloat method comment.
 Object visitFromInt(COSInteger obj)
          visitFromFloat method comment.
 Object visitFromName(COSName obj)
          visitFromName method comment.
 Object visitFromNull(COSNull obj)
          visitFromNull method comment.
 Object visitFromStream(COSStream obj)
          visitFromStream method comment.
 Object visitFromString(COSString obj)
          visitFromString method comment.
 void write(COSDocument doc)
          This will write the pdf document.
 void write(PDDocument doc)
          This will write the pdf document.
 void writeReference(COSBase obj)
          visitFromObjRef method comment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DICT_OPEN

public static final byte[] DICT_OPEN
The dictionary open token.


DICT_CLOSE

public static final byte[] DICT_CLOSE
The dictionary close token.


SPACE

public static final byte[] SPACE
space character.


COMMENT

public static final byte[] COMMENT
The start to a PDF comment.


VERSION

public static final byte[] VERSION
The output version of the PDF.


GARBAGE

public static final byte[] GARBAGE
Garbage bytes used to create the PDF header.


EOF

public static final byte[] EOF
The EOF constant.


REFERENCE

public static final byte[] REFERENCE
The reference token.


XREF

public static final byte[] XREF
The XREF token.


XREF_FREE

public static final byte[] XREF_FREE
The xref free token.


XREF_USED

public static final byte[] XREF_USED
The xref used token.


TRAILER

public static final byte[] TRAILER
The trailer token.


STARTXREF

public static final byte[] STARTXREF
The start xref token.


OBJ

public static final byte[] OBJ
The starting object token.


ENDOBJ

public static final byte[] ENDOBJ
The end object token.


ARRAY_OPEN

public static final byte[] ARRAY_OPEN
The array open token.


ARRAY_CLOSE

public static final byte[] ARRAY_CLOSE
The array close token.


STREAM

public static final byte[] STREAM
The open stream token.


ENDSTREAM

public static final byte[] ENDSTREAM
The close stream token.

Constructor Detail

COSWriter

public COSWriter(OutputStream os)
COSWriter constructor comment.

Parameters:
os - The wrapped output stream.
Method Detail

addXRefEntry

protected void addXRefEntry(COSWriterXRefEntry entry)
add an entry in the x ref table for later dump.

Parameters:
entry - The new entry to add.

close

public void close()
           throws IOException
This will close the stream.

Throws:
IOException - If the underlying stream throws an exception.

getNumber

protected long getNumber()
This will get the current object number.

Returns:
The current object number.

getObjectKeys

public Map getObjectKeys()
This will get all available object keys.

Returns:
A map of all object keys.

getOutput

protected OutputStream getOutput()
This will get the output stream.

Returns:
The output stream.

getStandardOutput

protected COSStandardOutputStream getStandardOutput()
This will get the standard output stream.

Returns:
The standard output stream.

getStartxref

protected long getStartxref()
This will get the current start xref.

Returns:
The current start xref.

getXRefEntries

protected List getXRefEntries()
This will get the xref entries.

Returns:
All available xref entries.

setNumber

protected void setNumber(long newNumber)
This will set the current object number.

Parameters:
newNumber - The new object number.

setStartxref

protected void setStartxref(long newStartxref)
This will set the start xref.

Parameters:
newStartxref - The new start xref attribute.

doWriteBody

protected void doWriteBody(COSDocument doc)
                    throws IOException,
                           COSVisitorException
This will write the body of the document.

Parameters:
doc - The document to write the body for.
Throws:
IOException - If there is an error writing the data.
COSVisitorException - If there is an error generating the data.

doWriteObject

public void doWriteObject(COSBase obj)
                   throws COSVisitorException
This will write a COS object.

Parameters:
obj - The object to write.
Throws:
COSVisitorException - If there is an error visiting objects.

doWriteHeader

protected void doWriteHeader(COSDocument doc)
                      throws IOException
This will write the header to the PDF document.

Parameters:
doc - The document to get the data from.
Throws:
IOException - If there is an error writing to the stream.

doWriteTrailer

protected void doWriteTrailer(COSDocument doc)
                       throws IOException,
                              COSVisitorException
This will write the trailer to the PDF document.

Parameters:
doc - The document to create the trailer for.
Throws:
IOException - If there is an IOError while writing the document.
COSVisitorException - If there is an error while generating the data.

doWriteXRef

protected void doWriteXRef(COSDocument doc)
                    throws IOException
write the x ref section for the pdf file currently, the pdf is reconstructed from the scratch, so we write a single section todo support for incremental writing?

Parameters:
doc - The document to write the xref from.
Throws:
IOException - If there is an error writing the data to the stream.

visitFromArray

public Object visitFromArray(COSArray obj)
                      throws COSVisitorException
visitFromArray method comment.

Specified by:
visitFromArray in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromBoolean

public Object visitFromBoolean(COSBoolean obj)
                        throws COSVisitorException
visitFromBoolean method comment.

Specified by:
visitFromBoolean in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromDictionary

public Object visitFromDictionary(COSDictionary obj)
                           throws COSVisitorException
visitFromDictionary method comment.

Specified by:
visitFromDictionary in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromDocument

public Object visitFromDocument(COSDocument doc)
                         throws COSVisitorException
The visit from document method.

Specified by:
visitFromDocument in interface ICOSVisitor
Parameters:
doc - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromFloat

public Object visitFromFloat(COSFloat obj)
                      throws COSVisitorException
visitFromFloat method comment.

Specified by:
visitFromFloat in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromInt

public Object visitFromInt(COSInteger obj)
                    throws COSVisitorException
visitFromFloat method comment.

Specified by:
visitFromInt in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromName

public Object visitFromName(COSName obj)
                     throws COSVisitorException
visitFromName method comment.

Specified by:
visitFromName in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromNull

public Object visitFromNull(COSNull obj)
                     throws COSVisitorException
visitFromNull method comment.

Specified by:
visitFromNull in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

writeReference

public void writeReference(COSBase obj)
                    throws COSVisitorException
visitFromObjRef method comment.

Parameters:
obj - The object that is being visited.
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromStream

public Object visitFromStream(COSStream obj)
                       throws COSVisitorException
visitFromStream method comment.

Specified by:
visitFromStream in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

visitFromString

public Object visitFromString(COSString obj)
                       throws COSVisitorException
visitFromString method comment.

Specified by:
visitFromString in interface ICOSVisitor
Parameters:
obj - The object that is being visited.
Returns:
null
Throws:
COSVisitorException - If there is an exception while visiting this object.

write

public void write(COSDocument doc)
           throws COSVisitorException
This will write the pdf document.

Parameters:
doc - The document to write.
Throws:
COSVisitorException - If an error occurs while generating the data.

write

public void write(PDDocument doc)
           throws COSVisitorException
This will write the pdf document.

Parameters:
doc - The document to write.
Throws:
COSVisitorException - If an error occurs while generating the data.


Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.