Class COSWriterCompressionPool
java.lang.Object
org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool
An instance of this class compresses the contents of a given
PDDocument.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PDDocumentstatic final floatprivate final COSObjectPoolprivate final List<COSObjectKey> private final CompressParametersprivate final List<COSObjectKey> -
Constructor Summary
ConstructorsConstructorDescriptionCOSWriterCompressionPool(PDDocument document, CompressParameters parameters) Constructs an object that can be used to compress the contents of a givenPDDocument. -
Method Summary
Modifier and TypeMethodDescriptionprivate COSBaseaddObjectToPool(COSObjectKey key, COSBase base) Adds the givenCOSBaseto this pool, using the givenCOSObjectKeyas it's referencable ID.addStructure(List<COSBase> cosBaseList) Attempts to find yet unregistered streams and dictionaries in the given structure.addStructure(COSBase current) Attempts to find yet unregistered streams and dictionaries in the given structure.booleanReturns true, if the givenCOSBaseis a registered object of this compression pool.CreatesCOSWriterObjectStreams for all currently registered objects of this pool, that have been marked as fit for being compressed in this manner.private booleanfilterElement(COSBase element) getElements(Collection<? extends COSBase> elements) Collect all relevant objects from a COSDictionary/COSArray.longReturns the highest object number, that is registered in this compression pool.Returns theCOSObjectKey, that is registered for the givenCOSBasein this compression pool.getObject(COSObjectKey key) Returns theCOSBase, that is registered for the givenCOSObjectKeyin this compression pool.Returns allCOSBases that can be appended to an object stream.Returns allCOSBases, that must be added to the document's top level container.
-
Field Details
-
MINIMUM_SUPPORTED_VERSION
public static final float MINIMUM_SUPPORTED_VERSION- See Also:
-
document
-
parameters
-
objectPool
-
topLevelObjects
-
objectStreamObjects
-
allDirectObjects
-
-
Constructor Details
-
COSWriterCompressionPool
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:- Compress the COSStructure of the document, by streaming
COSBases to compressedCOSWriterObjectStreams
- Parameters:
document- The document, that shall be compressed.parameters- The configuration of the compression operations, that shall be applied.- Throws:
IOException- Shall be thrown if a compression operation failed.
- Compress the COSStructure of the document, by streaming
-
-
Method Details
-
addObjectToPool
Adds the givenCOSBaseto this pool, using the givenCOSObjectKeyas 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 compressedCOSWriterObjectStream.- Parameters:
key- TheCOSObjectKeythat shall be used as theCOSBases ID, if possible.base- TheCOSBase, that shall be registered in this pool.
-
addStructure
Attempts to find yet unregistered streams and dictionaries in the given structure.- Parameters:
cosBaseList- A list of objects to be added for compressing.- Throws:
IOException- Shall be thrown, if adding failed.
-
addStructure
Attempts to find yet unregistered streams and dictionaries in the given structure.- Parameters:
current- The object to be added for compressing.- Throws:
IOException- Shall be thrown, if compressing the object failed.
-
getElements
Collect all relevant objects from a COSDictionary/COSArray.- Parameters:
elements- collection of all elements of a COSDictionary/COSArray.- Returns:
- a collection containing the relevant objects within the given Collection.
- Throws:
IOException- if something went wrong.
-
filterElement
- Throws:
IOException
-
getTopLevelObjects
Returns allCOSBases, that must be added to the document's top level container. Those objects are not valid to be added to an object stream.- Returns:
- A list of all top level
COSBases.
-
getObjectStreamObjects
Returns allCOSBases 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:createObjectStreams()- Returns:
- A list of all
COSBases, that can be added to an object stream.
-
contains
Returns true, if the givenCOSBaseis a registered object of this compression pool.- Parameters:
object- The object, that shall be checked.- Returns:
- True, if the given
COSBaseis a registered object of this compression pool.
-
getKey
Returns theCOSObjectKey, that is registered for the givenCOSBasein this compression pool.- Parameters:
object- TheCOSBaseaCOSObjectKeyis registered for in this compression pool.- Returns:
- The
COSObjectKey, that is registered for the givenCOSBasein this compression pool, if such an object is contained.
-
getObject
Returns theCOSBase, that is registered for the givenCOSObjectKeyin this compression pool.- Parameters:
key- TheCOSObjectKeyaCOSBaseis registered for in this compression pool.- Returns:
- The
COSBase, that is registered for the givenCOSObjectKeyin this compression pool, if such an object is contained.
-
getHighestXRefObjectNumber
public long getHighestXRefObjectNumber()Returns the highest object number, that is registered in this compression pool.- Returns:
- The highest object number, that is registered in this compression pool.
-
createObjectStreams
CreatesCOSWriterObjectStreams 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'sPDFXRefStreamaccordingly. The objects contained in such a stream must not be added to the document separately.- Returns:
- The created
COSWriterObjectStreams for all currently registered compressible objects.
-