Class PDFCloneUtility


  • public class PDFCloneUtility
    extends java.lang.Object
    Utility class used to clone PDF objects. It keeps track of objects it has already cloned. Although this class is public, it is for PDFBox internal use and should not be used outside, except by very experienced users. The "public" modifier will be removed in 3.0. The class should not be used on documents that are being generated because these can contain unfinished parts, e.g. font subsetting information.
    • Constructor Summary

      Constructors 
      Constructor Description
      PDFCloneUtility​(PDDocument dest)
      Creates a new instance for the given target document.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      COSBase cloneForNewDocument​(java.lang.Object base)
      Deep-clones the given object for inclusion into a different PDF document identified by the destination parameter.
      void cloneMerge​(COSObjectable base, COSObjectable target)
      Merges two objects of the same type by deep-cloning its members.
      PDDocument getDestination()
      Returns the destination PDF document this cloner instance is set up for.
      private boolean hasSelfReference​(java.lang.Object parent, COSBase value)
      Check whether an element (of an array or a dictionary) points to its parent.
      • Methods inherited from class java.lang.Object

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

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • destination

        private final PDDocument destination
      • clonedVersion

        private final java.util.Map<java.lang.Object,​COSBase> clonedVersion
      • clonedValues

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

      • PDFCloneUtility

        public PDFCloneUtility​(PDDocument dest)
        Creates a new instance for the given target document.
        Parameters:
        dest - the destination PDF document that will receive the clones
    • Method Detail

      • getDestination

        public PDDocument getDestination()
        Returns the destination PDF document this cloner instance is set up for.
        Returns:
        the destination PDF document
      • cloneForNewDocument

        public COSBase cloneForNewDocument​(java.lang.Object base)
                                    throws java.io.IOException
        Deep-clones the given object for inclusion into a different PDF document identified by the destination parameter.
        Parameters:
        base - the initial object as the root of the deep-clone operation
        Returns:
        the cloned instance of the base object
        Throws:
        java.io.IOException - if an I/O error occurs
      • cloneMerge

        public void cloneMerge​(COSObjectable base,
                               COSObjectable target)
                        throws java.io.IOException
        Merges two objects of the same type by deep-cloning its members.
        Base and target must be instances of the same class.
        Parameters:
        base - the base object to be cloned
        target - the merge target
        Throws:
        java.io.IOException - if an I/O error occurs
      • hasSelfReference

        private boolean hasSelfReference​(java.lang.Object parent,
                                         COSBase value)
        Check whether an element (of an array or a dictionary) points to its parent.
        Parameters:
        parent - COSArray or COSDictionary
        value - an element