Class PdfCopy

  • All Implemented Interfaces:
    DocListener, ElementListener, java.util.EventListener

    public class PdfCopy
    extends PdfWriter
    Make copies of PDF documents. Documents can be edited after reading and before writing them out.
    • Field Detail

      • indirects

        protected java.util.HashMap indirects
      • indirectMap

        protected java.util.HashMap indirectMap
      • currentObjectNum

        protected int currentObjectNum
      • pageNumbersToRefs

        protected java.util.ArrayList pageNumbersToRefs
      • fullFormFieldNames

        protected java.util.HashSet fullFormFieldNames
      • topFormFieldNames

        protected java.util.HashSet topFormFieldNames
      • topFormFieldReadersData

        protected java.util.HashMap topFormFieldReadersData
    • Method Detail

      • open

        public void open()
        Description copied from class: PdfWriter
        Signals that the Document has been opened and that Elements can be added.

        When this method is called, the PDF-document header is written to the outputstream.

        Specified by:
        open in interface DocListener
        Overrides:
        open in class PdfWriter
      • getImportedPage

        public PdfImportedPage getImportedPage​(PdfReader reader,
                                               int pageNumber)
                                        throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • copyIndirect

        public 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
      • setFromIPage

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

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

        public PdfIndirectReference getPageReference​(int page)
        Description copied from class: PdfWriter
        Gets a reference to a page existing or not. If the page does not exist yet the reference will be created in advance. If on closing the document, a page number greater than the total number of pages was requested, an exception is thrown.
        Overrides:
        getPageReference in class PdfWriter
        Parameters:
        page - the page number. The first page is 1
        Returns:
        the reference to the page
      • setOutlines

        public void setOutlines​(PdfIndirectReference outlines)
        Sets the bookmarks. The list structure is defined in SimpleBookmark#.
        Parameters:
        outlines - the bookmarks or null to remove any
      • 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 referencetable is composed and everything is written to the outputstream embedded in a Trailer.

        Specified by:
        close in interface DocListener
        Overrides:
        close in class PdfWriter
      • addAnnotation

        public void addAnnotation​(PdfAnnotation annot)
        Description copied from class: PdfWriter
        Adds a PdfAnnotation or a PdfFormField to the document. Only the top parent of a PdfFormField needs to be added.
        Overrides:
        addAnnotation in class PdfWriter
        Parameters:
        annot - the PdfAnnotation or the PdfFormField to add
      • 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