Top Description Fields Constructors Methods
org.apache.pdfbox.pdfwriter

public Class COSWriter

extends Object
implements ICOSVisitor
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.cos.ICOSVisitor
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, .SequenceInputStream, java.nio.charset.StandardCharsets, java.security.MessageDigest, .NoSuchAlgorithmException, java.text.DecimalFormat, .DecimalFormatSymbols, .NumberFormat, java.util.ArrayDeque, .ArrayList, .Collections, .Deque, .HashMap, .HashSet, .Hashtable, .Iterator, .List, .Locale, .Map, .Set, java.util.stream.Collectors, org.apache.pdfbox.cos.COSArray, .COSBase, .COSBoolean, .COSDictionary, .COSDocument, .COSFloat, .COSInteger, .COSName, .COSNull, .COSNumber, .COSObject, .COSObjectKey, .COSStream, .COSString, .COSUpdateInfo, .ICOSVisitor, org.apache.pdfbox.io.IOUtils, .RandomAccessInputStream, .RandomAccessRead, org.apache.pdfbox.pdfparser.PDFXRefStream, org.apache.pdfbox.pdfparser.xref.FreeXReference, .NormalXReference, .ObjectStreamXReference, .XReferenceEntry, org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool, .COSWriterObjectStream, .CompressParameters, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy, .SecurityHandler, org.apache.pdfbox.pdmodel.fdf.FDFDocument, org.apache.pdfbox.pdmodel.interactive.digitalsignature.COSFilterInputStream, .SignatureInterface, org.apache.pdfbox.util.Hex

This class acts on a in-memory representation of a PDF document.
Authors
Michael Traut, Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final Set<COSBase>
public static final byte[]
ARRAY_CLOSE

The array close token.

public static final byte[]
ARRAY_OPEN

The array open token.

private boolean
private COSArray
private long
private long
public static final byte[]
COMMENT

The start to a PDF comment.

private final CompressParameters
private COSObjectKey
public static final byte[]
DICT_CLOSE

The dictionary close token.

public static final byte[]
DICT_OPEN

The dictionary open token.

public static final byte[]
ENDOBJ

The end object token.

public static final byte[]
ENDSTREAM

The close stream token.

public static final byte[]
EOF

The EOF constant.

private FDFDocument
private static final NumberFormat
private static final NumberFormat
public static final byte[]
GARBAGE

Garbage bytes used to create the PDF header.

private RandomAccessRead
private OutputStream
private boolean
private byte[]
private final Map<COSObjectKey, COSBase>
private long
public static final byte[]
OBJ

The starting object token.

private final Map<COSBase, COSObjectKey>
private final Deque<COSBase>
private OutputStream
private PDDocument
private boolean
public static final byte[]
REFERENCE

The reference token.

private SignatureInterface
private long
private long
public static final byte[]
SPACE

space character.

private COSStandardOutputStream
public static final byte[]
STARTXREF

The start xref token.

private long
public static final byte[]
STREAM

The open stream token.

public static final byte[]
TRAILER

The trailer token.

public static final byte[]
VERSION

The output version of the PDF.

private boolean
private final Set<COSBase>
public static final byte[]
XREF

The XREF token.

public static final byte[]
XREF_FREE

The xref free token.

public static final byte[]
XREF_USED

The xref used token.

private final List<XReferenceEntry>

Constructor Summary

AccessConstructor and Description
public
COSWriter(OutputStream
The output stream to write the PDF. It will be closed when this object is closed.
outputStream
)

COSWriter constructor.

public
COSWriter(OutputStream
The output stream to write the PDF. It will be closed when this object is closed.
outputStream
,
CompressParameters
The configuration for the document's compression.
compressParameters
)

COSWriter constructor.

public
COSWriter(OutputStream
output stream where the new PDF data will be written. It will be closed when this object is closed.
outputStream
,
RandomAccessRead
random access read containing source PDF data
inputData
)

COSWriter constructor for incremental updates.

public
COSWriter(OutputStream
output stream where the new PDF data will be written. It will be closed when this object is closed.
outputStream
,
RandomAccessRead
random access read containing source PDF data.
inputData
,
Set<COSDictionary>
objects that must be part of the incremental saving.
objectsToWrite
)

Constructor for incremental updates with a list of objects to write.

Method Summary

Modifier and TypeMethod and Description
private void
protected void
addXRefEntry(XReferenceEntry
The new entry to add.
entry
)

add an entry in the x ref table for later dump.

private void
protected void
doWriteBody(COSDocument
The document to write the body for.
doc
)

This will write the body of the document.

private void
doWriteBodyCompressed(COSDocument
The document to write the body for.
document
)

This will write the compressed body of the document.

protected void
doWriteHeader(COSDocument
The document to get the data from.
doc
)

This will write the header to the PDF document.

private void
doWriteIncrement()

Write an incremental update for a non signature case.

public void
doWriteObject(COSObjectKey
The key of the object to write.
key
,
COSBase
The object to write.
obj
)

This will write a COS object for a predefined key.

public void
doWriteObject(COSBase
The object to write.
obj
)

This will write a COS object.

private void
private void
protected void
doWriteTrailer(COSDocument
The document to create the trailer for.
doc
)

This will write the trailer to the PDF document.

private void
private void
private void
public InputStream

Returns:

data stream to be signed
getDataToSign
()

Return the stream of PDF data to be signed.

private COSObjectKey

Returns:

The object key for the object.
getObjectKey
(COSBase
The object to get the key for.
obj
)

This will get the object key for the object.

protected OutputStream

Returns:

The output stream.
getOutput
()

This will get the output stream.

protected COSStandardOutputStream

Returns:

The standard output stream.
getStandardOutput
()

This will get the standard output stream.

protected long

Returns:

The current start xref.
getStartxref
()

This will get the current start xref.

protected List<XReferenceEntry>

Returns:

All available xref entries.
getXRefEntries
()

This will get the xref entries.

protected Long[]

Returns:

a integer array with the ranges
getXRefRanges
(List<XReferenceEntry>
list with the xRef entries that was written
xRefEntriesList
)

check the xref entries and write out the ranges.

public boolean

Returns:

True, if the resulting document shall be compressed.
isCompress
()

Returns true, if the resulting document shall be compressed.

private boolean
isNeedToBeUpdated(COSBase base)

Convenience method, so that we get false for types that can't be updated.

private void
private void
setOutput(OutputStream
The new output stream.
newOutput
)

This will set the output stream.

private void
setStandardOutput(COSStandardOutputStream
The new standard output stream.
newStandardOutput
)

This will set the standard output stream.

protected void
setStartxref(long
The new start xref attribute.
newStartxref
)

This will set the start xref.

public void
visitFromArray(COSArray
The Object that is being visited.
array
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromArray.

Notification of visit to Array object.

public void
visitFromBoolean(COSBoolean
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromBoolean.

Notification of visit to boolean object.

public void
visitFromDictionary(COSDictionary
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromDictionary.

Notification of visit to dictionary object.

public void
visitFromDocument(COSDocument
The Object that is being visited.
doc
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromDocument.

Notification of visit to document object.

public void
visitFromFloat(COSFloat
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromFloat.

Notification of visit to float object.

public void
visitFromInt(COSInteger
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromInt.

Notification of visit to integer object.

public void
visitFromName(COSName
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromName.

Notification of visit to name object.

public void
visitFromNull(COSNull
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromNull.

Notification of visit to null object.

public void
visitFromStream(COSStream
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromStream.

Notification of visit to stream object.

public void
visitFromString(COSString
The Object that is being visited.
obj
)

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromString.

Notification of visit to string object.

public void
write(COSDocument
The document to write.
doc
)

This will write the pdf document.

public void
write(PDDocument
The document to write.
doc
)

This will write the pdf document.

public void
write(PDDocument
The document to write.
doc
,
SignatureInterface
class to be used for signing; null if external signing would be performed or there will be no signing at all
signInterface
)

This will write the pdf document.

public void
write(FDFDocument
The document to write.
doc
)

This will write the fdf document.

private void
private void
public void
writeExternalSignature(byte[]
CMS signature byte array
cmsSignature
)

Write externally created signature of PDF data obtained via getDataToSign() method.

public void
writeReference(COSBase
The object that is being visited.
obj
)

visitFromObjRef method comment.

public static void
writeString(COSString
COSString to be written
string
,
OutputStream
The stream to write to.
output
)

This will output the given byte getString as a PDF object.

public static void
writeString(byte[]
byte array representation of a string to be written
bytes
,
OutputStream
The stream to write to.
output
)

This will output the given text/byte getString as a PDF object.

private static void
writeString(byte[] bytes, boolean forceHex, OutputStream
The stream to write to.
output
)

This will output the given text/byte string as a PDF object.

private void
private void
writeXrefRange(long x, long y)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualsAddedback to summary
private final Set<COSBase> actualsAdded
ARRAY_CLOSEback to summary
public static final byte[] ARRAY_CLOSE

The array close token.

ARRAY_OPENback to summary
public static final byte[] ARRAY_OPEN

The array open token.

blockAddingObjectback to summary
private boolean blockAddingObject
byteRangeArrayback to summary
private COSArray byteRangeArray
byteRangeLengthback to summary
private long byteRangeLength
byteRangeOffsetback to summary
private long byteRangeOffset
COMMENTback to summary
public static final byte[] COMMENT

The start to a PDF comment.

compressParametersback to summary
private final CompressParameters compressParameters
currentObjectKeyback to summary
private COSObjectKey currentObjectKey
DICT_CLOSEback to summary
public static final byte[] DICT_CLOSE

The dictionary close token.

DICT_OPENback to summary
public static final byte[] DICT_OPEN

The dictionary open token.

ENDOBJback to summary
public static final byte[] ENDOBJ

The end object token.

ENDSTREAMback to summary
public static final byte[] ENDSTREAM

The close stream token.

EOFback to summary
public static final byte[] EOF

The EOF constant.

fdfDocumentback to summary
private FDFDocument fdfDocument
formatXrefGenerationback to summary
private static final NumberFormat formatXrefGeneration
formatXrefOffsetback to summary
private static final NumberFormat formatXrefOffset
GARBAGEback to summary
public static final byte[] GARBAGE

Garbage bytes used to create the PDF header.

incrementalInputback to summary
private RandomAccessRead incrementalInput
incrementalOutputback to summary
private OutputStream incrementalOutput
incrementalUpdateback to summary
private boolean incrementalUpdate
incrementPartback to summary
private byte[] incrementPart
keyObjectback to summary
private final Map<COSObjectKey, COSBase> keyObject
numberback to summary
private long number
OBJback to summary
public static final byte[] OBJ

The starting object token.

objectKeysback to summary
private final Map<COSBase, COSObjectKey> objectKeys
Annotations
@SuppressWarnings:squid:S1149
objectsToWriteback to summary
private final Deque<COSBase> objectsToWrite
outputback to summary
private OutputStream output
pdDocumentback to summary
private PDDocument pdDocument
reachedSignatureback to summary
private boolean reachedSignature
REFERENCEback to summary
public static final byte[] REFERENCE

The reference token.

signatureInterfaceback to summary
private SignatureInterface signatureInterface
signatureLengthback to summary
private long signatureLength
signatureOffsetback to summary
private long signatureOffset
SPACEback to summary
public static final byte[] SPACE

space character.

standardOutputback to summary
private COSStandardOutputStream standardOutput
STARTXREFback to summary
public static final byte[] STARTXREF

The start xref token.

startxrefback to summary
private long startxref
STREAMback to summary
public static final byte[] STREAM

The open stream token.

TRAILERback to summary
public static final byte[] TRAILER

The trailer token.

VERSIONback to summary
public static final byte[] VERSION

The output version of the PDF.

willEncryptback to summary
private boolean willEncrypt
writtenObjectsback to summary
private final Set<COSBase> writtenObjects
XREFback to summary
public static final byte[] XREF

The XREF token.

XREF_FREEback to summary
public static final byte[] XREF_FREE

The xref free token.

XREF_USEDback to summary
public static final byte[] XREF_USED

The xref used token.

xRefEntriesback to summary
private final List<XReferenceEntry> xRefEntries

Constructor Detail

COSWriterback to summary
public COSWriter(OutputStream outputStream)

COSWriter constructor.

Parameters
outputStream:OutputStream

The output stream to write the PDF. It will be closed when this object is closed.

COSWriterback to summary
public COSWriter(OutputStream outputStream, CompressParameters compressParameters)

COSWriter constructor.

Parameters
outputStream:OutputStream

The output stream to write the PDF. It will be closed when this object is closed.

compressParameters:CompressParameters

The configuration for the document's compression.

COSWriterback to summary
public COSWriter(OutputStream outputStream, RandomAccessRead inputData) throws IOException

COSWriter constructor for incremental updates. There must be a path of objects that have COSUpdateInfo#isNeedToBeUpdated() set, starting from the document catalog. For signatures this is taken care by PDFBox itself.

Parameters
outputStream:OutputStream

output stream where the new PDF data will be written. It will be closed when this object is closed.

inputData:RandomAccessRead

random access read containing source PDF data

Exceptions
IOException:
if something went wrong
COSWriterback to summary
public COSWriter(OutputStream outputStream, RandomAccessRead inputData, Set<COSDictionary> objectsToWrite) throws IOException

Constructor for incremental updates with a list of objects to write. This allows to include objects even if there is no path of objects that have COSUpdateInfo#isNeedToBeUpdated() set so the incremental update gets smaller. Only dictionaries are supported; if you need to update other objects classes, then add their parent dictionary.

Parameters
outputStream:OutputStream

output stream where the new PDF data will be written. It will be closed when this object is closed.

inputData:RandomAccessRead

random access read containing source PDF data.

objectsToWrite:Set<COSDictionary>

objects that must be part of the incremental saving.

Exceptions
IOException:
if something went wrong

Method Detail

addObjectToWriteback to summary
private void addObjectToWrite(COSBase object)
addXRefEntryback to summary
protected void addXRefEntry(XReferenceEntry entry)

add an entry in the x ref table for later dump.

Parameters
entry:XReferenceEntry

The new entry to add.

detectPossibleSignatureback to summary
private void detectPossibleSignature(COSDictionary obj) throws IOException
doWriteBodyback to summary
protected void doWriteBody(COSDocument doc) throws IOException

This will write the body of the document.

Parameters
doc:COSDocument

The document to write the body for.

Exceptions
IOException:
If there is an error writing the data.
doWriteBodyCompressedback to summary
private void doWriteBodyCompressed(COSDocument document) throws IOException

This will write the compressed body of the document.

Parameters
document:COSDocument

The document to write the body for.

Exceptions
IOException:
If there is an error writing the data.
doWriteHeaderback to summary
protected void doWriteHeader(COSDocument doc) throws IOException

This will write the header to the PDF document.

Parameters
doc:COSDocument

The document to get the data from.

Exceptions
IOException:
If there is an error writing to the stream.
doWriteIncrementback to summary
private void doWriteIncrement() throws IOException

Write an incremental update for a non signature case. This can be used for e.g. augmenting signatures.

doWriteObjectback to summary
public void doWriteObject(COSObjectKey key, COSBase obj) throws IOException

This will write a COS object for a predefined key.

Parameters
key:COSObjectKey

The key of the object to write.

obj:COSBase

The object to write.

Exceptions
IOException:
if the output cannot be written
doWriteObjectback to summary
public void doWriteObject(COSBase obj) throws IOException

This will write a COS object.

Parameters
obj:COSBase

The object to write.

Exceptions
IOException:
if the output cannot be written
doWriteObjectsback to summary
private void doWriteObjects() throws IOException
doWriteSignatureback to summary
private void doWriteSignature() throws IOException
doWriteTrailerback to summary
protected void doWriteTrailer(COSDocument doc) throws IOException

This will write the trailer to the PDF document.

Parameters
doc:COSDocument

The document to create the trailer for.

Exceptions
IOException:
If there is an IOError while writing the document.
doWriteXRefIncback to summary
private void doWriteXRefInc(COSDocument doc) throws IOException
doWriteXRefTableback to summary
private void doWriteXRefTable() throws IOException
fillGapsWithFreeEntriesback to summary
private void fillGapsWithFreeEntries()
getDataToSignback to summary
public InputStream getDataToSign() throws IOException

Return the stream of PDF data to be signed. Clients should use this method only to create signatures externally. 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.

Returns:InputStream

data stream to be signed

Exceptions
IOException:
if input data is closed
IllegalStateException:
if PDF is not prepared for external signing
getObjectKeyback to summary
private COSObjectKey getObjectKey(COSBase obj)

This will get the object key for the object.

Parameters
obj:COSBase

The object to get the key for.

Returns:COSObjectKey

The object key for the object.

getOutputback to summary
protected OutputStream getOutput()

This will get the output stream.

Returns:OutputStream

The output stream.

getStandardOutputback to summary
protected COSStandardOutputStream getStandardOutput()

This will get the standard output stream.

Returns:COSStandardOutputStream

The standard output stream.

getStartxrefback to summary
protected long getStartxref()

This will get the current start xref.

Returns:long

The current start xref.

getXRefEntriesback to summary
protected List<XReferenceEntry> getXRefEntries()

This will get the xref entries.

Returns:List<XReferenceEntry>

All available xref entries.

getXRefRangesback to summary
protected Long[] getXRefRanges(List<XReferenceEntry> xRefEntriesList)

check the xref entries and write out the ranges. The format of the returned array is exactly the same as the pdf specification. See section 7.5.4 of ISO32000-1:2008, example 1 (page 40) for reference.

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.

Parameters
xRefEntriesList:List<XReferenceEntry>

list with the xRef entries that was written

Returns:Long[]

a integer array with the ranges

isCompressback to summary
public boolean isCompress()

Returns true, if the resulting document shall be compressed.

Returns:boolean

True, if the resulting document shall be compressed.

isNeedToBeUpdatedback to summary
private boolean isNeedToBeUpdated(COSBase base)

Convenience method, so that we get false for types that can't be updated.

prepareIncrementback to summary
private void prepareIncrement()
setOutputback to summary
private void setOutput(OutputStream newOutput)

This will set the output stream.

Parameters
newOutput:OutputStream

The new output stream.

setStandardOutputback to summary
private void setStandardOutput(COSStandardOutputStream newStandardOutput)

This will set the standard output stream.

Parameters
newStandardOutput:COSStandardOutputStream

The new standard output stream.

setStartxrefback to summary
protected void setStartxref(long newStartxref)

This will set the start xref.

Parameters
newStartxref:long

The new start xref attribute.

visitFromArrayback to summary
public void visitFromArray(COSArray array) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromArray.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromArray.

Notification of visit to Array object.

Parameters
array:COSArray

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromBooleanback to summary
public void visitFromBoolean(COSBoolean obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromBoolean.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromBoolean.

Notification of visit to boolean object.

Parameters
obj:COSBoolean

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromDictionaryback to summary
public void visitFromDictionary(COSDictionary obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromDictionary.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromDictionary.

Notification of visit to dictionary object.

Parameters
obj:COSDictionary

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromDocumentback to summary
public void visitFromDocument(COSDocument doc) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromDocument.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromDocument.

Notification of visit to document object.

Parameters
doc:COSDocument

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromFloatback to summary
public void visitFromFloat(COSFloat obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromFloat.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromFloat.

Notification of visit to float object.

Parameters
obj:COSFloat

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromIntback to summary
public void visitFromInt(COSInteger obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromInt.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromInt.

Notification of visit to integer object.

Parameters
obj:COSInteger

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromNameback to summary
public void visitFromName(COSName obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromName.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromName.

Notification of visit to name object.

Parameters
obj:COSName

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromNullback to summary
public void visitFromNull(COSNull obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromNull.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromNull.

Notification of visit to null object.

Parameters
obj:COSNull

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromStreamback to summary
public void visitFromStream(COSStream obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromStream.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromStream.

Notification of visit to stream object.

Parameters
obj:COSStream

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
visitFromStringback to summary
public void visitFromString(COSString obj) throws IOException

Implements org.apache.pdfbox.cos.ICOSVisitor.visitFromString.

Doc from org.apache.pdfbox.cos.ICOSVisitor.visitFromString.

Notification of visit to string object.

Parameters
obj:COSString

The Object that is being visited.

Annotations
@Override
Exceptions
IOException:
If there is an error while visiting this object.
writeback to summary
public void write(COSDocument doc) throws IOException

This will write the pdf document.

Parameters
doc:COSDocument

The document to write.

Exceptions
IOException:
If an error occurs while generating the data.
writeback to summary
public void write(PDDocument doc) throws IOException

This will write the pdf document. If signature should be created externally, writeExternalSignature(byte[]) should be invoked to set signature after calling this method.

Parameters
doc:PDDocument

The document to write.

Exceptions
IOException:
If an error occurs while generating the data.
writeback to summary
public void write(PDDocument doc, SignatureInterface signInterface) throws IOException

This will write the pdf document. If signature should be created externally, writeExternalSignature(byte[]) should be invoked to set signature after calling this method.

Parameters
doc:PDDocument

The document to write.

signInterface:SignatureInterface

class to be used for signing; null if external signing would be performed or there will be no signing at all

Exceptions
IOException:
If an error occurs while generating the data.
IllegalStateException:
If the document has an encryption dictionary but no protection policy.
writeback to summary
public void write(FDFDocument doc) throws IOException

This will write the fdf document.

Parameters
doc:FDFDocument

The document to write.

Exceptions
IOException:
If an error occurs while generating the data.
writeArrayback to summary
private void writeArray(COSArray array) throws IOException
writeDictionaryback to summary
private void writeDictionary(COSDictionary dictionary) throws IOException
writeExternalSignatureback to summary
public void writeExternalSignature(byte[] cmsSignature) throws IOException

Write externally created signature of PDF data obtained via getDataToSign() method.

Parameters
cmsSignature:byte[]

CMS signature byte array

Exceptions
IOException:
if source data stream is closed
IllegalStateException:
if PDF is not prepared for external signing
writeReferenceback to summary
public void writeReference(COSBase obj) throws IOException

visitFromObjRef method comment.

Parameters
obj:COSBase

The object that is being visited.

Exceptions
IOException:
If there is an exception while visiting this object.
writeStringback to summary
public static void writeString(COSString string, OutputStream output) throws IOException

This will output the given byte getString as a PDF object.

Parameters
string:COSString

COSString to be written

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the stream.
writeStringback to summary
public static void writeString(byte[] bytes, OutputStream output) throws IOException

This will output the given text/byte getString as a PDF object.

Parameters
bytes:byte[]

byte array representation of a string to be written

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the stream.
writeStringback to summary
private static void writeString(byte[] bytes, boolean forceHex, OutputStream output) throws IOException

This will output the given text/byte string as a PDF object.

Parameters
output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the stream.
writeXrefEntryback to summary
private void writeXrefEntry(XReferenceEntry entry) throws IOException
writeXrefRangeback to summary
private void writeXrefRange(long x, long y) throws IOException