Class COSWriterCompressionPool


  • public class COSWriterCompressionPool
    extends java.lang.Object
    An instance of this class compresses the contents of a given PDDocument.
    • Field Detail

      • MINIMUM_SUPPORTED_VERSION

        public static final float MINIMUM_SUPPORTED_VERSION
        See Also:
        Constant Field Values
      • topLevelObjects

        private final java.util.List<COSObjectKey> topLevelObjects
      • objectStreamObjects

        private final java.util.List<COSObjectKey> objectStreamObjects
      • allDirectObjects

        private final java.util.Set<COSBase> allDirectObjects
    • Constructor Detail

      • COSWriterCompressionPool

        public COSWriterCompressionPool​(PDDocument document,
                                        CompressParameters parameters)
                                 throws java.io.IOException

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

        Parameters:
        document - The document, that shall be compressed.
        parameters - The configuration of the compression operations, that shall be applied.
        Throws:
        java.io.IOException - Shall be thrown if a compression operation failed.
    • Method Detail

      • addObjectToPool

        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 - The COSObjectKey that shall be used as the COSBases ID, if possible.
        base - The COSBase, that shall be registered in this pool.
      • addStructure

        private void addStructure​(COSBase current)
                           throws java.io.IOException
        Attempts to find yet unregistered streams and dictionaries in the given structure.
        Parameters:
        current - The object to be added for compressing.
        Throws:
        java.io.IOException - Shall be thrown, if compressing the object failed.
      • addElements

        private void addElements​(java.util.Iterator<COSBase> elements)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getTopLevelObjects

        public java.util.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:
        A list of all top level COSBases.
      • getObjectStreamObjects

        public java.util.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: createObjectStreams()
        Returns:
        A list of all COSBases, that can be added to an object stream.
      • contains

        public boolean contains​(COSBase object)
        Returns true, if the given COSBase is a registered object of this compression pool.
        Parameters:
        object - The object, that shall be checked.
        Returns:
        True, if the given COSBase is a registered object of this compression pool.
      • 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

        public java.util.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:
        The created COSWriterObjectStreams for all currently registered compressible objects.