Class PdfCopy

    • Field Detail

      • LOGGER

        private static final Logger LOGGER
      • COUNTER

        protected static Counter COUNTER
      • disableIndirects

        protected java.util.HashSet<PdfObject> disableIndirects
      • namePtr

        protected int[] namePtr
      • rotateContents

        private boolean rotateContents
        Holds value of property rotateContents.
      • fieldArray

        protected PdfArray fieldArray
      • fieldTemplates

        protected java.util.HashSet<PdfTemplate> fieldTemplates
      • currentStructArrayNumber

        private int currentStructArrayNumber
      • updateRootKids

        protected boolean updateRootKids
      • annotId

        private static final PdfName annotId
      • annotIdCnt

        private static int annotIdCnt
      • mergeFields

        protected boolean mergeFields
      • needAppearances

        private boolean needAppearances
      • hasSignature

        private boolean hasSignature
      • tabOrder

        private java.util.HashMap<PdfArray,​java.util.ArrayList<java.lang.Integer>> tabOrder
      • calculationOrderRefs

        private java.util.ArrayList<java.lang.Object> calculationOrderRefs
      • fields

        protected java.util.ArrayList<AcroFields> fields
      • calculationOrder

        private java.util.ArrayList<java.lang.String> calculationOrder
      • fieldTree

        private java.util.HashMap<java.lang.String,​java.lang.Object> fieldTree
      • unmergedMap

        private java.util.HashMap<java.lang.Integer,​PdfIndirectObject> unmergedMap
      • mergedMap

        private java.util.HashMap<java.lang.Integer,​PdfIndirectObject> mergedMap
      • mergeFieldsInternalCall

        private boolean mergeFieldsInternalCall
      • iTextTag

        private static final PdfName iTextTag
      • zero

        private static final java.lang.Integer zero
      • mergedRadioButtons

        private java.util.HashSet<java.lang.Object> mergedRadioButtons
      • mergedTextFields

        private java.util.HashMap<java.lang.Object,​PdfString> mergedTextFields
      • readersWithImportedStructureTreeRootKids

        private java.util.HashSet<PdfReader> readersWithImportedStructureTreeRootKids
      • widgetKeys

        protected static final java.util.HashSet<PdfName> widgetKeys
      • fieldKeys

        protected static final java.util.HashSet<PdfName> fieldKeys
    • Method Detail

      • isRotateContents

        public boolean isRotateContents()
        Getter for property rotateContents.
        Returns:
        Value of property rotateContents.
      • setRotateContents

        public void setRotateContents​(boolean rotateContents)
        Setter for property rotateContents.
        Parameters:
        rotateContents - New value of property rotateContents.
      • setMergeFields

        public void setMergeFields()
      • getImportedPage

        public PdfImportedPage getImportedPage​(PdfReader reader,
                                               int pageNumber)
        Grabs a page from the input document
        Overrides:
        getImportedPage in class PdfWriter
        Parameters:
        reader - the reader of the document
        pageNumber - which page to get
        Returns:
        the page
      • clearIndirects

        private void clearIndirects​(PdfReader reader)
      • checkStructureTreeRootKids

        private int checkStructureTreeRootKids​(PdfCopy.ImportedPage newPage)
      • structureTreeRootKidsForReaderImported

        protected void structureTreeRootKidsForReaderImported​(PdfReader reader)
      • fixStructureTreeRoot

        protected void fixStructureTreeRoot​(java.util.HashSet<RefKey> activeKeys,
                                            java.util.HashSet<PdfName> activeClassMaps)
      • copyIndirect

        protected PdfIndirectReference copyIndirect​(PRIndirectReference in,
                                                    boolean keepStructure,
                                                    boolean directRootKids)
                                             throws java.io.IOException,
                                                    BadPdfFormatException
        Translate a PRIndirectReference to a PdfIndirectReference In addition, translates the object numbers, and copies the referenced object to the output file. NB: PRIndirectReferences (and PRIndirectObjects) really need to know what file they came from, because each file has its own namespace. The translation we do from their namespace to ours is *at best* heuristic, and guaranteed to fail under some circumstances.
        Throws:
        java.io.IOException
        BadPdfFormatException
      • copyIndirect

        protected PdfIndirectReference copyIndirect​(PRIndirectReference in)
                                             throws java.io.IOException,
                                                    BadPdfFormatException
        Translate a PRIndirectReference to a PdfIndirectReference In addition, translates the object numbers, and copies the referenced object to the output file. NB: PRIndirectReferences (and PRIndirectObjects) really need to know what file they came from, because each file has its own namespace. The translation we do from their namespace to ours is *at best* heuristic, and guaranteed to fail under some circumstances.
        Throws:
        java.io.IOException
        BadPdfFormatException
      • copyArray

        protected PdfArray copyArray​(PdfArray in,
                                     boolean keepStruct,
                                     boolean directRootKids)
                              throws java.io.IOException,
                                     BadPdfFormatException
        Translate a PRArray to a PdfArray. Also translate all of the objects contained in it
        Throws:
        java.io.IOException
        BadPdfFormatException
      • setFromIPage

        protected int setFromIPage​(PdfImportedPage iPage)
        convenience method. Given an imported page, set our "globals"
      • setFromReader

        protected void setFromReader​(PdfReader reader)
        convenience method. Given a reader, set our "globals"
      • addPage

        public void addPage​(Rectangle rect,
                            int rotation)
                     throws DocumentException
        Adds a blank page.
        Parameters:
        rect - The page dimension
        rotation - The rotation angle in degrees
        Throws:
        DocumentException
        Since:
        2.1.5
      • copyDocumentFields

        public void copyDocumentFields​(PdfReader reader)
                                throws DocumentException,
                                       java.io.IOException
        Copy document fields to a destination document.
        Parameters:
        reader - a document where fields are copied from.
        Throws:
        DocumentException
        java.io.IOException
      • addToBody

        public PdfIndirectObject addToBody​(PdfObject object,
                                           PdfIndirectReference ref)
                                    throws java.io.IOException
        Description copied from class: PdfWriter
        Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
        Overrides:
        addToBody in class PdfWriter
        Returns:
        a PdfIndirectObject
        Throws:
        java.io.IOException
      • addToBody

        public PdfIndirectObject addToBody​(PdfObject object,
                                           PdfIndirectReference ref,
                                           boolean formBranching)
                                    throws java.io.IOException
        Description copied from class: PdfWriter
        Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!
        Overrides:
        addToBody in class PdfWriter
        Returns:
        a PdfIndirectObject
        Throws:
        java.io.IOException
      • flushTaggedObjects

        protected void flushTaggedObjects()
                                   throws java.io.IOException
        Description copied from class: PdfWriter
        Fix structure of tagged document: remove unused objects, remove unused items from class map, fix xref table due to removed objects.
        Overrides:
        flushTaggedObjects in class PdfWriter
        Throws:
        java.io.IOException
      • fixTaggedStructure

        protected void fixTaggedStructure()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • removeInactiveReferences

        private void removeInactiveReferences​(PdfArray array,
                                              java.util.HashSet<RefKey> activeKeys)
      • containsInactivePg

        private boolean containsInactivePg​(PdfDictionary dict,
                                           java.util.HashSet<RefKey> activeKeys)
      • findActiveParents

        private java.util.ArrayList<PdfIndirectReference> findActiveParents​(java.util.HashSet<RefKey> activeKeys)
      • findActives

        private void findActives​(java.util.ArrayList<PdfIndirectReference> actives,
                                 java.util.HashSet<RefKey> activeKeys,
                                 java.util.HashSet<PdfName> activeClassMaps)
      • findActivesFromArray

        private void findActivesFromArray​(PdfArray array,
                                          java.util.ArrayList<PdfIndirectReference> actives,
                                          java.util.HashSet<RefKey> activeKeys,
                                          java.util.HashSet<PdfName> activeClassMaps)
      • flushIndirectObjects

        protected void flushIndirectObjects()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeObjectToBody

        private void writeObjectToBody​(PdfIndirectObject object)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • updateAnnotationReferences

        private void updateAnnotationReferences​(PdfObject obj)
      • updateCalculationOrder

        private void updateCalculationOrder​(PdfReader reader)
      • mergeFields

        private void mergeFields()
      • addPageOffsetToField

        private void addPageOffsetToField​(java.util.Map<java.lang.String,​AcroFields.Item> fd,
                                          int pageOffset)
      • mergeWithMaster

        private void mergeWithMaster​(java.util.Map<java.lang.String,​AcroFields.Item> fd)
      • mergeField

        private void mergeField​(java.lang.String name,
                                AcroFields.Item item)
      • createWidgets

        private void createWidgets​(java.util.ArrayList<java.lang.Object> list,
                                   AcroFields.Item item)
      • propagate

        private PdfObject propagate​(PdfObject obj)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • updateReferences

        private void updateReferences​(PdfObject obj)
      • isStructTreeRootReference

        protected boolean isStructTreeRootReference​(PdfIndirectReference prRef)
      • addFieldResources

        private void addFieldResources​(PdfDictionary catalog)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
        Signals that the Document was closed and that no other Elements will be added.

        The pages-tree is built and written to the outputstream. A Catalog is constructed, as well as an Info-object, the reference table is composed and everything is written to the outputstream embedded in a Trailer.

        Specified by:
        close in interface DocListener
        Overrides:
        close in class PdfWriter
        See Also:
        DocWriter.close()
      • add

        PdfIndirectReference add​(PdfPage page,
                                 PdfContents contents)
                          throws PdfException
        Description copied from class: PdfWriter
        Adds some PdfContents to this Writer.

        The document has to be open before you can begin to add content to the body of the document.

        Overrides:
        add in class PdfWriter
        Parameters:
        page - the PdfPage to add
        contents - the PdfContents of the page
        Returns:
        a PdfIndirectReference
        Throws:
        PdfException - on error
      • freeReader

        public void freeReader​(PdfReader reader)
                        throws java.io.IOException
        Description copied from class: PdfWriter
        Use this method to writes the reader to the document and free the memory used by it. The main use is when concatenating multiple documents to keep the memory usage restricted to the current appending document.
        Overrides:
        freeReader in class PdfWriter
        Parameters:
        reader - the PdfReader to free
        Throws:
        java.io.IOException - on error
      • getFlags

        static java.lang.Integer getFlags​(PdfDictionary field)
      • isCheckButton

        static boolean isCheckButton​(PdfDictionary field)
      • isRadioButton

        static boolean isRadioButton​(PdfDictionary field)
      • isTextField

        static boolean isTextField​(PdfDictionary field)
      • createPageStamp

        public PdfCopy.PageStamp createPageStamp​(PdfImportedPage iPage)
        Create a page stamp. New content and annotations, including new fields, are allowed. The fields added cannot have parents in another pages. This method modifies the PdfReader instance.

        The general usage to stamp something in a page is:

         PdfImportedPage page = copy.getImportedPage(reader, 1);
         PdfCopy.PageStamp ps = copy.createPageStamp(page);
         ps.addAnnotation(PdfAnnotation.createText(copy, new Rectangle(50, 180, 70, 200), "Hello", "No Thanks", true, "Comment"));
         PdfContentByte under = ps.getUnderContent();
         under.addImage(img);
         PdfContentByte over = ps.getOverContent();
         over.beginText();
         over.setFontAndSize(bf, 18);
         over.setTextMatrix(30, 30);
         over.showText("total page " + totalPage);
         over.endText();
         ps.alterContents();
         copy.addPage(page);
         
        Parameters:
        iPage - an imported page
        Returns:
        the PageStamp