java.io.Closeable, java.lang.AutoCloseable, ICOSVisitorpublic class COSWriter extends java.lang.Object implements ICOSVisitor, java.io.Closeable
| Modifier and Type | Field | 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 | Description |
|---|---|
COSWriter(java.io.OutputStream outputStream) |
COSWriter constructor comment.
|
COSWriter(java.io.OutputStream outputStream,
RandomAccessRead inputData) |
COSWriter constructor for incremental updates.
|
| Modifier and Type | Method | 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.
|
java.io.InputStream |
getDataToSign() |
Return the stream of PDF data to be signed.
|
protected long |
getNumber() |
This will get the current object number.
|
java.util.Map<COSBase,COSObjectKey> |
getObjectKeys() |
This will get all available object keys.
|
protected java.io.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 java.util.List<COSWriterXRefEntry> |
getXRefEntries() |
This will get the xref entries.
|
protected java.lang.Long[] |
getXRefRanges(java.util.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.
|
java.lang.Object |
visitFromArray(COSArray obj) |
Notification of visit to Array object.
|
java.lang.Object |
visitFromBoolean(COSBoolean obj) |
Notification of visit to boolean object.
|
java.lang.Object |
visitFromDictionary(COSDictionary obj) |
Notification of visit to dictionary object.
|
java.lang.Object |
visitFromDocument(COSDocument doc) |
Notification of visit to document object.
|
java.lang.Object |
visitFromFloat(COSFloat obj) |
Notification of visit to float object.
|
java.lang.Object |
visitFromInt(COSInteger obj) |
Notification of visit to integer object.
|
java.lang.Object |
visitFromName(COSName obj) |
Notification of visit to name object.
|
java.lang.Object |
visitFromNull(COSNull obj) |
Notification of visit to null object.
|
java.lang.Object |
visitFromStream(COSStream obj) |
Notification of visit to stream object.
|
java.lang.Object |
visitFromString(COSString obj) |
Notification of visit to string object.
|
void |
write(COSDocument doc) |
This will write the pdf document.
|
void |
write(FDFDocument doc) |
This will write the fdf document.
|
void |
write(PDDocument doc) |
This will write the pdf document.
|
void |
write(PDDocument doc,
SignatureInterface signInterface) |
This will write the pdf document.
|
void |
writeExternalSignature(byte[] cmsSignature) |
Write externally created signature of PDF data obtained via
getDataToSign() method. |
void |
writeReference(COSBase obj) |
visitFromObjRef method comment.
|
static void |
writeString(byte[] bytes,
java.io.OutputStream output) |
This will output the given text/byte getString as a PDF object.
|
static void |
writeString(COSString string,
java.io.OutputStream output) |
This will output the given byte getString as a PDF object.
|
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(java.io.OutputStream outputStream)
outputStream - The wrapped output stream.public COSWriter(java.io.OutputStream outputStream,
RandomAccessRead inputData)
throws java.io.IOException
outputStream - output stream where the new PDF data will be writteninputData - random access read containing source PDF datajava.io.IOException - if something went wrongprotected void addXRefEntry(COSWriterXRefEntry entry)
entry - The new entry to add.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOException - If the underlying stream throws an exception.protected long getNumber()
public java.util.Map<COSBase,COSObjectKey> getObjectKeys()
protected java.io.OutputStream getOutput()
protected COSStandardOutputStream getStandardOutput()
protected long getStartxref()
protected java.util.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 java.io.IOException
doc - The document to write the body for.java.io.IOException - If there is an error writing the data.public void doWriteObject(COSBase obj) throws java.io.IOException
obj - The object to write.java.io.IOException - if the output cannot be writtenprotected void doWriteHeader(COSDocument doc) throws java.io.IOException
doc - The document to get the data from.java.io.IOException - If there is an error writing to the stream.protected void doWriteTrailer(COSDocument doc) throws java.io.IOException
doc - The document to create the trailer for.java.io.IOException - If there is an IOError while writing the document.public java.io.InputStream getDataToSign()
throws java.io.IOException
write(PDDocument) method should have been called prior.
The created signature should be set using writeExternalSignature(byte[]).
When SignatureInterface instance is used, COSWriter obtains and writes the signature itself.
java.lang.IllegalStateException - if PDF is not prepared for external signingjava.io.IOException - if input data is closedpublic void writeExternalSignature(byte[] cmsSignature)
throws java.io.IOException
getDataToSign() method.cmsSignature - CMS signature byte arrayjava.lang.IllegalStateException - if PDF is not prepared for external signingjava.io.IOException - if source data stream is closedprotected java.lang.Long[] getXRefRanges(java.util.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 java.lang.Object visitFromArray(COSArray obj) throws java.io.IOException
ICOSVisitorvisitFromArray in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromBoolean(COSBoolean obj) throws java.io.IOException
ICOSVisitorvisitFromBoolean in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromDictionary(COSDictionary obj) throws java.io.IOException
ICOSVisitorvisitFromDictionary in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromDocument(COSDocument doc) throws java.io.IOException
ICOSVisitorvisitFromDocument in interface ICOSVisitordoc - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromFloat(COSFloat obj) throws java.io.IOException
ICOSVisitorvisitFromFloat in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromInt(COSInteger obj) throws java.io.IOException
ICOSVisitorvisitFromInt in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromName(COSName obj) throws java.io.IOException
ICOSVisitorvisitFromName in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromNull(COSNull obj) throws java.io.IOException
ICOSVisitorvisitFromNull in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public void writeReference(COSBase obj) throws java.io.IOException
obj - The object that is being visited.java.io.IOException - If there is an exception while visiting this object.public java.lang.Object visitFromStream(COSStream obj) throws java.io.IOException
ICOSVisitorvisitFromStream in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public java.lang.Object visitFromString(COSString obj) throws java.io.IOException
ICOSVisitorvisitFromString in interface ICOSVisitorobj - The Object that is being visited.java.io.IOException - If there is an error while visiting this object.public void write(COSDocument doc) throws java.io.IOException
doc - The document to write.java.io.IOException - If an error occurs while generating the data.public void write(PDDocument doc) throws java.io.IOException
writeExternalSignature(byte[]) should be invoked to set signature after calling this
method.doc - The document to write.java.io.IOException - If an error occurs while generating the data.public void write(PDDocument doc, SignatureInterface signInterface) throws java.io.IOException
writeExternalSignature(byte[]) should be invoked to set signature after calling this
method.doc - The document to write.signInterface - class to be used for signing; null if external signing would be
performed or there will be no signing at alljava.io.IOException - If an error occurs while generating the data.java.lang.IllegalStateException - If the document has an encryption dictionary but no protection
policy.public void write(FDFDocument doc) throws java.io.IOException
doc - The document to write.java.io.IOException - If an error occurs while generating the data.public static void writeString(COSString string, java.io.OutputStream output) throws java.io.IOException
string - COSString to be writtenoutput - The stream to write to.java.io.IOException - If there is an error writing to the stream.public static void writeString(byte[] bytes,
java.io.OutputStream output)
throws java.io.IOException
bytes - byte array representation of a string to be writtenoutput - The stream to write to.java.io.IOException - If there is an error writing to the stream.Copyright © 2002–2018. All rights reserved.