Class PdfResourceCounter


  • public class PdfResourceCounter
    extends java.lang.Object
    This class can be used to count the number of bytes needed when copying pages from an existing PDF into a newly created PDF.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.Integer,​PdfObject> resources
      A map of the resources that are already taken into account
    • Constructor Summary

      Constructors 
      Constructor Description
      PdfResourceCounter​(PdfObject object)
      Creates a PdfResourceCounter instance to be used to count the resources needed for either a page (in this case pass a page dictionary) or the trailer (root and info dictionary) of a PDF file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getLength​(java.util.Map<java.lang.Integer,​PdfObject> res)
      Returns the resources needed for the object that was used to create this PdfResourceCounter.
      java.util.Map<java.lang.Integer,​PdfObject> getResources()
      Returns a map with the resources.
      protected void loopOver​(PdfObject object)
      In case an object is an array, a dictionary or a stream, we need to loop over the entries and process them one by one.
      protected void process​(PdfObject object)
      Processes an object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • resources

        protected java.util.Map<java.lang.Integer,​PdfObject> resources
        A map of the resources that are already taken into account
    • Constructor Detail

      • PdfResourceCounter

        public PdfResourceCounter​(PdfObject object)
        Creates a PdfResourceCounter instance to be used to count the resources needed for either a page (in this case pass a page dictionary) or the trailer (root and info dictionary) of a PDF file.
        Parameters:
        object - the object we want to examine
    • Method Detail

      • process

        protected final void process​(PdfObject object)
        Processes an object. If the object is indirect, it is added to the list of resources. If not, it is just processed.
        Parameters:
        object - the object to process
      • loopOver

        protected final void loopOver​(PdfObject object)
        In case an object is an array, a dictionary or a stream, we need to loop over the entries and process them one by one.
        Parameters:
        object - the object to examine
      • getResources

        public java.util.Map<java.lang.Integer,​PdfObject> getResources()
        Returns a map with the resources.
        Returns:
        the resources
      • getLength

        public long getLength​(java.util.Map<java.lang.Integer,​PdfObject> res)
                       throws java.io.IOException
        Returns the resources needed for the object that was used to create this PdfResourceCounter. If you pass a Map with resources that were already used by other objects, these objects will not be taken into account.
        Parameters:
        res - the resources that can be excluded when counting the bytes
        Returns:
        the number of bytes needed for an object
        Throws:
        java.io.IOException