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

public Class COSWriterCompressionPool

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Collections, .HashSet, .Iterator, .List, .Set, org.apache.pdfbox.pdfparser.PDFXRefStream, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSDocument, .COSName, .COSObject, .COSObjectKey, .COSStream

An instance of this class compresses the contents of a given PDDocument.
Author
Christian Appl

Field Summary

Modifier and TypeField and Description
private final Set<COSBase>
private final PDDocument
public static final float
private final COSObjectPool
private final List<COSObjectKey>
private final CompressParameters
private final List<COSObjectKey>

Constructor Summary

AccessConstructor and Description
public
COSWriterCompressionPool(PDDocument
The document, that shall be compressed.
document
,
CompressParameters
The configuration of the compression operations, that shall be applied.
parameters
)

Constructs an object that can be used to compress the contents of a given PDDocument.

Method Summary

Modifier and TypeMethod and Description
private void
private COSBase
addObjectToPool(COSObjectKey
The COSObjectKey that shall be used as the COSBases ID, if possible.
key
,
COSBase
The COSBase, that shall be registered in this pool.
base
)

Adds the given COSBase to this pool, using the given COSObjectKey as it's referencable ID. This method shall determine an appropriate key, for yet unregistered objects, to register them.

private void
addStructure(COSBase
The object to be added for compressing.
current
)

Attempts to find yet unregistered streams and dictionaries in the given structure.

public boolean

Returns:

True, if the given COSBase is a registered object of this compression pool.
contains
(COSBase
The object, that shall be checked.
object
)

Returns true, if the given COSBase is a registered object of this compression pool.

public List<COSWriterObjectStream>

Returns:

The created COSWriterObjectStreams for all currently registered compressible objects.
createObjectStreams
()

Creates COSWriterObjectStreams for all currently registered objects of this pool, that have been marked as fit for being compressed in this manner.

public long

Returns:

The highest object number, that is registered in this compression pool.
getHighestXRefObjectNumber
()

Returns the highest object number, that is registered in this compression pool.

public COSObjectKey

Returns:

The COSObjectKey, that is registered for the given COSBase in this compression pool, if such an object is contained.
getKey
(COSBase
The COSBase a COSObjectKey is registered for in this compression pool.
object
)

Returns the COSObjectKey, that is registered for the given COSBase in this compression pool.

public COSBase

Returns:

The COSBase, that is registered for the given COSObjectKey in this compression pool, if such an object is contained.
getObject
(COSObjectKey
The COSObjectKey a COSBase is registered for in this compression pool.
key
)

Returns the COSBase, that is registered for the given COSObjectKey in this compression pool.

public List<COSObjectKey>

Returns:

A list of all COSBases, that can be added to an object stream.
getObjectStreamObjects
()

Returns all COSBases that can be appended to an object stream.

public List<COSObjectKey>

Returns:

A list of all top level COSBases.
getTopLevelObjects
()

Returns all COSBases, that must be added to the document's top level container.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allDirectObjectsback to summary
private final Set<COSBase> allDirectObjects
documentback to summary
private final PDDocument document
MINIMUM_SUPPORTED_VERSIONback to summary
public static final float MINIMUM_SUPPORTED_VERSION
objectPoolback to summary
private final COSObjectPool objectPool
objectStreamObjectsback to summary
private final List<COSObjectKey> objectStreamObjects
parametersback to summary
private final CompressParameters parameters
topLevelObjectsback to summary
private final List<COSObjectKey> topLevelObjects

Constructor Detail

COSWriterCompressionPoolback to summary
public COSWriterCompressionPool(PDDocument document, CompressParameters parameters) throws IOException

Constructs an object that can be used to compress the contents of a given PDDocument. It provides the means to:

Parameters
document:PDDocument

The document, that shall be compressed.

parameters:CompressParameters

The configuration of the compression operations, that shall be applied.

Exceptions
IOException:
Shall be thrown if a compression operation failed.

Method Detail

addElementsback to summary
private void addElements(Iterator<COSBase> elements) throws IOException
addObjectToPoolback to summary
private COSBase addObjectToPool(COSObjectKey key, COSBase base)

Adds the given COSBase to this pool, using the given COSObjectKey as it's referencable ID. This method shall determine an appropriate key, for yet unregistered objects, to register them. Depending on the type of object, it shall either be appended as-is or shall be appended to a compressed COSWriterObjectStream.

Parameters
key:COSObjectKey

The COSObjectKey that shall be used as the COSBases ID, if possible.

base:COSBase

The COSBase, that shall be registered in this pool.

addStructureback to summary
private void addStructure(COSBase current) throws IOException

Attempts to find yet unregistered streams and dictionaries in the given structure.

Parameters
current:COSBase

The object to be added for compressing.

Exceptions
IOException:
Shall be thrown, if compressing the object failed.
containsback to summary
public boolean contains(COSBase object)

Returns true, if the given COSBase is a registered object of this compression pool.

Parameters
object:COSBase

The object, that shall be checked.

Returns:boolean

True, if the given COSBase is a registered object of this compression pool.

createObjectStreamsback to summary
public List<COSWriterObjectStream> createObjectStreams()

Creates COSWriterObjectStreams for all currently registered objects of this pool, that have been marked as fit for being compressed in this manner. Such object streams may be added to a PDF document and shall be declared in a document's PDFXRefStream accordingly. The objects contained in such a stream must not be added to the document separately.

Returns:List<COSWriterObjectStream>

The created COSWriterObjectStreams for all currently registered compressible objects.

getHighestXRefObjectNumberback to summary
public long getHighestXRefObjectNumber()

Returns the highest object number, that is registered in this compression pool.

Returns:long

The highest object number, that is registered in this compression pool.

getKeyback to summary
public COSObjectKey getKey(COSBase object)

Returns the COSObjectKey, that is registered for the given COSBase in this compression pool.

Parameters
object:COSBase

The COSBase a COSObjectKey is registered for in this compression pool.

Returns:COSObjectKey

The COSObjectKey, that is registered for the given COSBase in this compression pool, if such an object is contained.

getObjectback to summary
public COSBase getObject(COSObjectKey key)

Returns the COSBase, that is registered for the given COSObjectKey in this compression pool.

Parameters
key:COSObjectKey

The COSObjectKey a COSBase is registered for in this compression pool.

Returns:COSBase

The COSBase, that is registered for the given COSObjectKey in this compression pool, if such an object is contained.

getObjectStreamObjectsback to summary
public List<COSObjectKey> getObjectStreamObjects()

Returns all COSBases that can be appended to an object stream. This list is only provided to enable reflections. Contained objects should indeed be added to a compressed document via an object stream, as can be created via calling: COSWriterCompressionPool#createObjectStreams()

Returns:List<COSObjectKey>

A list of all COSBases, that can be added to an object stream.

getTopLevelObjectsback to summary
public List<COSObjectKey> getTopLevelObjects()

Returns all COSBases, that must be added to the document's top level container. Those objects are not valid to be added to an object stream.

Returns:List<COSObjectKey>

A list of all top level COSBases.