com.lowagie.text.pdf

Class PdfCopy

public class PdfCopy extends PdfWriter

Make copies of PDF documents. Documents can be edited after reading and before writing them out.

Author: Mark Thompson

Nested Class Summary
static classPdfCopy.IndirectReferences
This class holds information about indirect references, since they are renumbered by iText.
protected static classPdfCopy.RefKey
A key to allow us to hash indirect references
Field Summary
protected PdfIndirectReferenceacroForm
protected intcurrentObjectNum
protected HashMapindirectMap
protected HashMapindirects
protected ListnewBookmarks
protected PdfReaderreader
Constructor Summary
PdfCopy(Document document, OutputStream os)
Constructor
Method Summary
PdfIndirectReferenceadd(PdfImage pdfImage, PdfIndirectReference fixedRef)
PdfIndirectReferenceadd(PdfOutline outline)
PdfIndirectReferenceadd(PdfPage page, PdfContents contents)
voidaddAnnotation(PdfAnnotation annot)
voidaddPage(PdfImportedPage iPage)
Add an imported page to our output
voidclose()
Signals that the Document was closed and that no other Elements will be added.
voidcopyAcroForm(PdfReader reader)
Copy the acroform for an input document.
protected PdfArraycopyArray(PdfArray in)
Translate a PRArray to a PdfArray.
protected PdfDictionarycopyDictionary(PdfDictionary in)
Translate a PRDictionary to a PdfDictionary.
protected PdfIndirectReferencecopyIndirect(PRIndirectReference in)
Translate a PRIndirectReference to a PdfIndirectReference In addition, translates the object numbers, and copies the referenced object to the output file.
protected PdfObjectcopyObject(PdfObject in)
Translate a PR-object to a Pdf-object
protected PdfStreamcopyStream(PRStream in)
Translate a PRStream to a PdfStream.
voidfreeReader(PdfReader reader)
protected PdfDictionarygetCatalog(PdfIndirectReference rootObj)
PdfImportedPagegetImportedPage(PdfReader reader, int pageNumber)
Grabs a page from the input document
voidopen()
protected intsetFromIPage(PdfImportedPage iPage)
convenience method.
protected voidsetFromReader(PdfReader reader)
convenience method.
voidsetOutlines(List outlines)
Sets the bookmarks.

Field Detail

acroForm

protected PdfIndirectReference acroForm

currentObjectNum

protected int currentObjectNum

indirectMap

protected HashMap indirectMap

indirects

protected HashMap indirects

newBookmarks

protected List newBookmarks

reader

protected PdfReader reader

Constructor Detail

PdfCopy

public PdfCopy(Document document, OutputStream os)
Constructor

Parameters: document os outputstream

Method Detail

add

PdfIndirectReference add(PdfImage pdfImage, PdfIndirectReference fixedRef)

add

public PdfIndirectReference add(PdfOutline outline)

add

PdfIndirectReference add(PdfPage page, PdfContents contents)

addAnnotation

public void addAnnotation(PdfAnnotation annot)

addPage

public void addPage(PdfImportedPage iPage)
Add an imported page to our output

Parameters: iPage an imported page

Throws: IOException, BadPdfFormatException

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.

copyAcroForm

public void copyAcroForm(PdfReader reader)
Copy the acroform for an input document. Note that you can only have one, we make no effort to merge them.

Parameters: reader The reader of the input file that is being copied

Throws: IOException, BadPdfFormatException

copyArray

protected PdfArray copyArray(PdfArray in)
Translate a PRArray to a PdfArray. Also translate all of the objects contained in it

copyDictionary

protected PdfDictionary copyDictionary(PdfDictionary in)
Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.

copyIndirect

protected PdfIndirectReference copyIndirect(PRIndirectReference in)
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.

copyObject

protected PdfObject copyObject(PdfObject in)
Translate a PR-object to a Pdf-object

copyStream

protected PdfStream copyStream(PRStream in)
Translate a PRStream to a PdfStream. The data part copies itself.

freeReader

public void freeReader(PdfReader reader)

getCatalog

protected PdfDictionary getCatalog(PdfIndirectReference rootObj)

getImportedPage

public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber)
Grabs a page from the input document

Parameters: reader the reader of the document pageNumber which page to get

Returns: the page

open

public void open()

setFromIPage

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

setFromReader

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

setOutlines

public void setOutlines(List outlines)
Sets the bookmarks. The list structure is defined in SimpleBookmark#.

Parameters: outlines the bookmarks or null to remove any