public class COSWriter extends Object implements ICOSVisitor, Closeable
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
COSWriter(OutputStream os)
COSWriter constructor comment.
|
COSWriter(OutputStream os,
InputStream is)
COSWriter constructor for incremental updates.
|
Modifier and Type | Method and Description |
---|---|
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<COSBase,COSObjectKey> |
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<COSWriterXRefEntry> |
getXRefEntries()
This will get the xref entries.
|
protected Integer[] |
getXRefRanges(List<COSWriterXRefEntry> xRefEntriesList)
check the xref entries and write out the ranges.
|
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.
|
public static final byte[] DICT_OPEN
public static final byte[] DICT_CLOSE
public static final byte[] SPACE
public static final byte[] COMMENT
public static final byte[] VERSION
public static final byte[] GARBAGE
public static final byte[] EOF
public static final byte[] REFERENCE
public static final byte[] XREF
public static final byte[] XREF_FREE
public static final byte[] XREF_USED
public static final byte[] TRAILER
public static final byte[] STARTXREF
public static final byte[] OBJ
public static final byte[] ENDOBJ
public static final byte[] ARRAY_OPEN
public static final byte[] ARRAY_CLOSE
public static final byte[] STREAM
public static final byte[] ENDSTREAM
public COSWriter(OutputStream os)
os
- The wrapped output stream.public COSWriter(OutputStream os, InputStream is)
os
- The wrapped output stream.is
- input streamprotected void addXRefEntry(COSWriterXRefEntry entry)
entry
- The new entry to add.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If the underlying stream throws an exception.protected long getNumber()
public Map<COSBase,COSObjectKey> getObjectKeys()
protected OutputStream getOutput()
protected COSStandardOutputStream getStandardOutput()
protected long getStartxref()
protected List<COSWriterXRefEntry> getXRefEntries()
protected void setNumber(long newNumber)
newNumber
- The new object number.protected void setStartxref(long newStartxref)
newStartxref
- The new start xref attribute.protected void doWriteBody(COSDocument doc) throws IOException, COSVisitorException
doc
- The document to write the body for.IOException
- If there is an error writing the data.COSVisitorException
- If there is an error generating the data.public void doWriteObject(COSBase obj) throws COSVisitorException
obj
- The object to write.COSVisitorException
- If there is an error visiting objects.protected void doWriteHeader(COSDocument doc) throws IOException
doc
- The document to get the data from.IOException
- If there is an error writing to the stream.protected void doWriteTrailer(COSDocument doc) throws IOException, COSVisitorException
doc
- The document to create the trailer for.IOException
- If there is an IOError while writing the document.COSVisitorException
- If there is an error while generating the data.protected void doWriteXRef(COSDocument doc) throws IOException
doc
- The document to write the xref from.IOException
- If there is an error writing the data to the stream.protected Integer[] getXRefRanges(List<COSWriterXRefEntry> xRefEntriesList)
example: 0 1 2 5 6 7 8 10
will create a array with follow ranges
0 3 5 4 10 1
this mean that the element 0 is followed by two other related numbers that represent a cluster of the size 3. 5 is follow by three other related numbers and create a cluster of size 4. etc.
xRefEntriesList
- list with the xRef entries that was writtenpublic Object visitFromArray(COSArray obj) throws COSVisitorException
visitFromArray
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromBoolean(COSBoolean obj) throws COSVisitorException
visitFromBoolean
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromDictionary(COSDictionary obj) throws COSVisitorException
visitFromDictionary
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromDocument(COSDocument doc) throws COSVisitorException
visitFromDocument
in interface ICOSVisitor
doc
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromFloat(COSFloat obj) throws COSVisitorException
visitFromFloat
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromInt(COSInteger obj) throws COSVisitorException
visitFromInt
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromName(COSName obj) throws COSVisitorException
visitFromName
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromNull(COSNull obj) throws COSVisitorException
visitFromNull
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public void writeReference(COSBase obj) throws COSVisitorException
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromStream(COSStream obj) throws COSVisitorException
visitFromStream
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public Object visitFromString(COSString obj) throws COSVisitorException
visitFromString
in interface ICOSVisitor
obj
- The object that is being visited.COSVisitorException
- If there is an exception while visiting this object.public void write(COSDocument doc) throws COSVisitorException
doc
- The document to write.COSVisitorException
- If an error occurs while generating the data.public void write(PDDocument doc) throws COSVisitorException
doc
- The document to write.COSVisitorException
- If an error occurs while generating the data.IllegalStateException
- If the document has an encryption dictionary but no protection
policy.Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.