Class COSWriterCompressionPool

java.lang.Object
org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool

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

  • 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:

      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.
  • Method Details

    • 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 List<COSBase> addStructure(List<COSBase> cosBaseList) throws IOException
      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

      private List<COSBase> addStructure(COSBase current) throws IOException
      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

      private List<COSBase> getElements(Collection<? extends COSBase> elements) throws IOException
      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

      private boolean filterElement(COSBase element) throws IOException
      Throws:
      IOException
    • getTopLevelObjects

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

      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: 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.
    • getKey

      public COSObjectKey getKey(COSBase object)
      Returns the COSObjectKey, that is registered for the given COSBase in this compression pool.
      Parameters:
      object - The COSBase a COSObjectKey is registered for in this compression pool.
      Returns:
      The COSObjectKey, that is registered for the given COSBase in this compression pool, if such an object is contained.
    • getObject

      public COSBase getObject(COSObjectKey key)
      Returns the COSBase, that is registered for the given COSObjectKey in this compression pool.
      Parameters:
      key - The COSObjectKey a COSBase is registered for in this compression pool.
      Returns:
      The COSBase, that is registered for the given COSObjectKey in 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

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