public class EvilCOSWriter extends Object implements org.apache.pdfbox.cos.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 |
---|
EvilCOSWriter(OutputStream outputStream,
PDFTransformerConfig config)
COSWriter constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addXRefEntry(org.apache.pdfbox.pdfwriter.COSWriterXRefEntry entry)
add an entry in the x ref table for later dump.
|
void |
close()
This will close the stream.
|
protected void |
doWriteBody(org.apache.pdfbox.cos.COSDocument doc)
This will write the body of the document.
|
protected void |
doWriteHeader(org.apache.pdfbox.cos.COSDocument doc)
This will write the header to the PDF document.
|
void |
doWriteObject(org.apache.pdfbox.cos.COSBase obj)
This will write a COS object.
|
protected void |
doWriteTrailer(org.apache.pdfbox.cos.COSDocument doc)
This will write the trailer to the PDF document.
|
InputStream |
getDataToSign()
Return the stream of PDF data to be signed.
|
protected long |
getNumber()
This will get the current object number.
|
Map<org.apache.pdfbox.cos.COSBase,org.apache.pdfbox.cos.COSObjectKey> |
getObjectKeys()
This will get all available object keys.
|
protected OutputStream |
getOutput()
This will get the output stream.
|
protected org.apache.pdfbox.pdfwriter.COSStandardOutputStream |
getStandardOutput()
This will get the standard output stream.
|
protected long |
getStartxref()
This will get the current start xref.
|
protected List<org.apache.pdfbox.pdfwriter.COSWriterXRefEntry> |
getXRefEntries()
This will get the xref entries.
|
protected Long[] |
getXRefRanges(List<org.apache.pdfbox.pdfwriter.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(org.apache.pdfbox.cos.COSArray obj) |
Object |
visitFromBoolean(org.apache.pdfbox.cos.COSBoolean obj) |
Object |
visitFromDictionary(org.apache.pdfbox.cos.COSDictionary obj) |
Object |
visitFromDocument(org.apache.pdfbox.cos.COSDocument doc) |
Object |
visitFromFloat(org.apache.pdfbox.cos.COSFloat obj) |
Object |
visitFromInt(org.apache.pdfbox.cos.COSInteger obj) |
Object |
visitFromName(org.apache.pdfbox.cos.COSName obj) |
Object |
visitFromNull(org.apache.pdfbox.cos.COSNull obj) |
Object |
visitFromStream(org.apache.pdfbox.cos.COSStream obj) |
Object |
visitFromString(org.apache.pdfbox.cos.COSString obj) |
void |
write(org.apache.pdfbox.cos.COSDocument doc)
This will write the pdf document.
|
void |
write(org.apache.pdfbox.pdmodel.fdf.FDFDocument doc)
This will write the fdf document.
|
void |
write(org.apache.pdfbox.pdmodel.PDDocument doc)
This will write the pdf document.
|
void |
write(org.apache.pdfbox.pdmodel.PDDocument doc,
org.apache.pdfbox.pdmodel.interactive.digitalsignature.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(org.apache.pdfbox.cos.COSBase obj)
visitFromObjRef method comment.
|
static void |
writeString(byte[] bytes,
OutputStream output)
This will output the given text/byte getString as a PDF object.
|
static void |
writeString(org.apache.pdfbox.cos.COSString string,
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 EvilCOSWriter(OutputStream outputStream, PDFTransformerConfig config)
outputStream
- The output stream to write the PDF. It will be closed when this object is
closed.protected void addXRefEntry(org.apache.pdfbox.pdfwriter.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<org.apache.pdfbox.cos.COSBase,org.apache.pdfbox.cos.COSObjectKey> getObjectKeys()
protected OutputStream getOutput()
protected org.apache.pdfbox.pdfwriter.COSStandardOutputStream getStandardOutput()
protected long getStartxref()
protected List<org.apache.pdfbox.pdfwriter.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(org.apache.pdfbox.cos.COSDocument doc) throws IOException
doc
- The document to write the body for.IOException
- If there is an error writing the data.public void doWriteObject(org.apache.pdfbox.cos.COSBase obj) throws IOException
obj
- The object to write.IOException
- if the output cannot be writtenprotected void doWriteHeader(org.apache.pdfbox.cos.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(org.apache.pdfbox.cos.COSDocument doc) throws IOException
doc
- The document to create the trailer for.IOException
- If there is an IOError while writing the document.public InputStream getDataToSign() throws 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.
IllegalStateException
- if PDF is not prepared for external signingIOException
- if input data is closedpublic void writeExternalSignature(byte[] cmsSignature) throws IOException
getDataToSign()
method.cmsSignature
- CMS signature byte arrayIllegalStateException
- if PDF is not prepared for external signingIOException
- if source data stream is closedprotected Long[] getXRefRanges(List<org.apache.pdfbox.pdfwriter.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(org.apache.pdfbox.cos.COSArray obj) throws IOException
visitFromArray
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromBoolean(org.apache.pdfbox.cos.COSBoolean obj) throws IOException
visitFromBoolean
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromDictionary(org.apache.pdfbox.cos.COSDictionary obj) throws IOException
visitFromDictionary
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromDocument(org.apache.pdfbox.cos.COSDocument doc) throws IOException
visitFromDocument
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromFloat(org.apache.pdfbox.cos.COSFloat obj) throws IOException
visitFromFloat
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromInt(org.apache.pdfbox.cos.COSInteger obj) throws IOException
visitFromInt
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromName(org.apache.pdfbox.cos.COSName obj) throws IOException
visitFromName
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromNull(org.apache.pdfbox.cos.COSNull obj) throws IOException
visitFromNull
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public void writeReference(org.apache.pdfbox.cos.COSBase obj) throws IOException
obj
- The object that is being visited.IOException
- If there is an exception while visiting this object.public Object visitFromStream(org.apache.pdfbox.cos.COSStream obj) throws IOException
visitFromStream
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public Object visitFromString(org.apache.pdfbox.cos.COSString obj) throws IOException
visitFromString
in interface org.apache.pdfbox.cos.ICOSVisitor
IOException
public void write(org.apache.pdfbox.cos.COSDocument doc) throws IOException
doc
- The document to write.IOException
- If an error occurs while generating the data.public void write(org.apache.pdfbox.pdmodel.PDDocument doc) throws IOException
writeExternalSignature(byte[])
should be invoked to set signature after calling this method.doc
- The document to write.IOException
- If an error occurs while generating the data.public void write(org.apache.pdfbox.pdmodel.PDDocument doc, org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface signInterface) throws 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 allIOException
- If an error occurs while generating the data.IllegalStateException
- If the document has an encryption dictionary but no protection
policy.public void write(org.apache.pdfbox.pdmodel.fdf.FDFDocument doc) throws IOException
doc
- The document to write.IOException
- If an error occurs while generating the data.public static void writeString(org.apache.pdfbox.cos.COSString string, OutputStream output) throws IOException
string
- COSString to be writtenoutput
- The stream to write to.IOException
- If there is an error writing to the stream.public static void writeString(byte[] bytes, OutputStream output) throws IOException
bytes
- byte array representation of a string to be writtenoutput
- The stream to write to.IOException
- If there is an error writing to the stream.Copyright © 2007–2022 The Apache Software Foundation. All rights reserved.