Class PDFCloneUtility

java.lang.Object
org.apache.pdfbox.multipdf.PDFCloneUtility

public class PDFCloneUtility extends Object
Utility class used to clone PDF objects. It keeps track of objects it has already cloned.
  • Field Details

    • LOG

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

      private final PDDocument destination
    • clonedVersion

      private final Map<COSBase,COSBase> clonedVersion
    • clonedValues

      private final Set<COSBase> clonedValues
  • Constructor Details

    • PDFCloneUtility

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

    • getDestination

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

      public <TCOSBase extends COSBase> TCOSBase cloneForNewDocument(TCOSBase base) throws IOException
      Deep-clones the given object for inclusion into a different PDF document identified by the destination parameter. Expert use only, don’t use it if you don’t know exactly what you are doing.
      Type Parameters:
      TCOSBase - The type to be returned.
      Parameters:
      base - the initial object as the root of the deep-clone operation
      Returns:
      the cloned instance of the base object
      Throws:
      IOException - if an I/O error occurs
    • cloneCOSBaseForNewDocument

      private COSBase cloneCOSBaseForNewDocument(COSBase base) throws IOException
      Throws:
      IOException
    • cloneCOSArray

      private COSArray cloneCOSArray(COSArray array) throws IOException
      Throws:
      IOException
    • cloneCOSStream

      private COSStream cloneCOSStream(COSStream stream) throws IOException
      Throws:
      IOException
    • cloneCOSDictionary

      private COSDictionary cloneCOSDictionary(COSDictionary dictionary) throws IOException
      Throws:
      IOException
    • cloneMerge

      void cloneMerge(COSObjectable base, COSObjectable target) throws 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:
      IOException - if an I/O error occurs
    • cloneMergeCOSBase

      private void cloneMergeCOSBase(COSBase source, COSBase target) throws IOException
      Throws:
      IOException
    • hasSelfReference

      private boolean hasSelfReference(COSBase 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