Class PdfCopy

    • Field Detail

      • COUNTER

        protected static Counter COUNTER
      • indirects

        protected java.util.HashMap<RefKey,​com.itextpdf.text.pdf.PdfCopy.IndirectReferences> indirects
      • indirectMap

        protected java.util.HashMap<PdfReader,​java.util.HashMap<RefKey,​com.itextpdf.text.pdf.PdfCopy.IndirectReferences>> indirectMap
      • disableIndirects

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

        protected int[] namePtr
      • fieldArray

        protected PdfArray fieldArray
      • fieldTemplates

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

        protected boolean updateRootKids
      • mergeFields

        protected boolean mergeFields
      • fields

        protected java.util.ArrayList<AcroFields> fields
      • 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
      • 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
      • flushIndirectObjects

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

        protected boolean isStructTreeRootReference​(PdfIndirectReference prRef)
      • 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()
      • 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
      • 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