|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.itextpdf.text.DocWriter
com.itextpdf.text.pdf.PdfWriter
com.itextpdf.text.pdf.PdfCopy
public class PdfCopy
Make copies of PDF documents. Documents can be edited after reading and before writing them out.
Nested Class Summary | |
---|---|
protected static class |
PdfCopy.ImportedPage
|
static class |
PdfCopy.PageStamp
|
protected static class |
PdfCopy.RefKey
A key to allow us to hash indirect references |
static class |
PdfCopy.StampContent
|
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.PdfWriter |
---|
PdfWriter.PdfBody, PdfWriter.PdfTrailer |
Field Summary | |
---|---|
protected PdfIndirectReference |
acroForm
|
protected static Counter |
COUNTER
|
protected HashSet<PdfObject> |
disableIndirects
|
protected PdfArray |
fieldArray
|
protected HashSet<PdfTemplate> |
fieldTemplates
|
protected ArrayList<PdfCopy.ImportedPage> |
importedPages
|
protected HashMap<PdfReader,HashMap<PdfCopy.RefKey,com.itextpdf.text.pdf.PdfCopy.IndirectReferences>> |
indirectMap
|
protected HashMap<PdfCopy.RefKey,PdfIndirectObject> |
indirectObjects
|
protected HashMap<PdfCopy.RefKey,com.itextpdf.text.pdf.PdfCopy.IndirectReferences> |
indirects
|
protected int[] |
namePtr
|
protected HashMap<PdfObject,PdfObject> |
parentObjects
|
protected PdfReader |
reader
|
protected ArrayList<PdfIndirectObject> |
savedObjects
|
protected HashSet<PdfCopy.RefKey> |
streams
|
protected PRIndirectReference |
structTreeRootReference
|
protected boolean |
updateRootKids
|
Fields inherited from class com.itextpdf.text.DocWriter |
---|
closeStream, document, EQUALS, FORWARD, GT, LT, NEWLINE, open, os, pageSize, pause, QUOTE, SPACE, TAB |
Constructor Summary | |
---|---|
PdfCopy(Document document,
OutputStream os)
Constructor |
Method Summary | |
---|---|
PdfIndirectReference |
add(PdfOutline outline)
|
void |
addAnnotation(PdfAnnotation annot)
Use this methods to add a PdfAnnotation or a PdfFormField
to the document. |
void |
addPage(PdfImportedPage iPage)
Add an imported page to our output |
void |
addPage(Rectangle rect,
int rotation)
Adds a blank page. |
PdfIndirectObject |
addToBody(PdfObject object)
Use this method to add a PDF object to the PDF body. |
PdfIndirectObject |
addToBody(PdfObject object,
PdfIndirectReference ref)
Use this method to add a PDF object to the PDF body. |
void |
close()
Signals that the Document was closed and that no other
Elements will be added. |
void |
copyAcroForm(PdfReader reader)
Copy the acroform for an input document. |
protected PdfArray |
copyArray(PdfArray in)
Translate a PRArray to a PdfArray. |
protected PdfArray |
copyArray(PdfArray in,
boolean keepStruct,
boolean directRootKids)
Translate a PRArray to a PdfArray. |
protected PdfDictionary |
copyDictionary(PdfDictionary in)
Translate a PRDictionary to a PdfDictionary. |
protected PdfDictionary |
copyDictionary(PdfDictionary in,
boolean keepStruct,
boolean directRootKids)
Translate a PRDictionary to a PdfDictionary. |
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. |
protected PdfIndirectReference |
copyIndirect(PRIndirectReference in,
boolean keepStructure,
boolean directRootKids)
Translate a PRIndirectReference to a PdfIndirectReference In addition, translates the object numbers, and copies the referenced object to the output file. |
protected PdfObject |
copyObject(PdfObject in)
Translate a PR-object to a Pdf-object |
protected PdfObject |
copyObject(PdfObject in,
boolean keepStruct,
boolean directRootKids)
Translate a PR-object to a Pdf-object |
protected PdfStream |
copyStream(PRStream in)
Translate a PRStream to a PdfStream. |
PdfCopy.PageStamp |
createPageStamp(PdfImportedPage iPage)
Create a page stamp. |
protected void |
fixStructureTreeRoot(HashSet<PdfCopy.RefKey> activeKeys,
HashSet<PdfName> activeClassMaps)
|
protected void |
fixTaggedStructure()
|
protected void |
flushIndirectObjects()
|
protected void |
flushTaggedObjects()
Fix structure of tagged document: remove unused objects, remove unused items from class map, fix xref table due to removed objects. |
void |
freeReader(PdfReader reader)
Use this method to writes the reader to the document and free the memory used by it. |
protected PdfDictionary |
getCatalog(PdfIndirectReference rootObj)
|
protected Counter |
getCounter()
|
PdfImportedPage |
getImportedPage(PdfReader reader,
int pageNumber)
Grabs a page from the input document |
PdfImportedPage |
getImportedPage(PdfReader reader,
int pageNumber,
boolean keepTaggedPdfStructure)
|
protected PdfImportedPage |
getImportedPageImpl(PdfReader reader,
int pageNumber)
|
boolean |
isRotateContents()
Getter for property rotateContents. |
protected boolean |
isStructTreeRootReference(PdfIndirectReference prRef)
|
protected int |
setFromIPage(PdfImportedPage iPage)
convenience method. |
protected void |
setFromReader(PdfReader reader)
convenience method. |
void |
setPageEvent(PdfPageEvent event)
Setting page events isn't possible with Pdf(Smart)Copy. |
void |
setRotateContents(boolean rotateContents)
Setter for property rotateContents. |
Methods inherited from class com.itextpdf.text.DocWriter |
---|
add, addTabs, flush, getISOBytes, isCloseStream, isPaused, newPage, pause, resetPageCount, resume, setCloseStream, setMarginMirroring, setMarginMirroringTopBottom, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Counter COUNTER
protected HashMap<PdfCopy.RefKey,com.itextpdf.text.pdf.PdfCopy.IndirectReferences> indirects
protected HashMap<PdfReader,HashMap<PdfCopy.RefKey,com.itextpdf.text.pdf.PdfCopy.IndirectReferences>> indirectMap
protected HashMap<PdfObject,PdfObject> parentObjects
protected HashSet<PdfObject> disableIndirects
protected PdfReader reader
protected PdfIndirectReference acroForm
protected int[] namePtr
protected PdfArray fieldArray
protected HashSet<PdfTemplate> fieldTemplates
protected PRIndirectReference structTreeRootReference
protected HashMap<PdfCopy.RefKey,PdfIndirectObject> indirectObjects
protected ArrayList<PdfIndirectObject> savedObjects
protected ArrayList<PdfCopy.ImportedPage> importedPages
protected HashSet<PdfCopy.RefKey> streams
protected boolean updateRootKids
Constructor Detail |
---|
public PdfCopy(Document document, OutputStream os) throws DocumentException
document
- documentos
- outputstream
DocumentException
Method Detail |
---|
protected Counter getCounter()
getCounter
in class PdfWriter
public void setPageEvent(PdfPageEvent event)
setPageEvent
in class PdfWriter
event
- the PdfPageEvent
for this documentPdfWriter.setPageEvent(com.itextpdf.text.pdf.PdfPageEvent)
public boolean isRotateContents()
public void setRotateContents(boolean rotateContents)
rotateContents
- New value of property rotateContents.public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber)
getImportedPage
in class PdfWriter
reader
- the reader of the documentpageNumber
- which page to get
public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber, boolean keepTaggedPdfStructure) throws BadPdfFormatException
BadPdfFormatException
protected void fixStructureTreeRoot(HashSet<PdfCopy.RefKey> activeKeys, HashSet<PdfName> activeClassMaps)
protected PdfImportedPage getImportedPageImpl(PdfReader reader, int pageNumber)
protected PdfIndirectReference copyIndirect(PRIndirectReference in, boolean keepStructure, boolean directRootKids) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfIndirectReference copyIndirect(PRIndirectReference in) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfDictionary copyDictionary(PdfDictionary in, boolean keepStruct, boolean directRootKids) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfDictionary copyDictionary(PdfDictionary in) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfStream copyStream(PRStream in) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfArray copyArray(PdfArray in, boolean keepStruct, boolean directRootKids) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfArray copyArray(PdfArray in) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfObject copyObject(PdfObject in, boolean keepStruct, boolean directRootKids) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected PdfObject copyObject(PdfObject in) throws IOException, BadPdfFormatException
IOException
BadPdfFormatException
protected int setFromIPage(PdfImportedPage iPage)
protected void setFromReader(PdfReader reader)
public void addPage(PdfImportedPage iPage) throws IOException, BadPdfFormatException
iPage
- an imported page
IOException,
- BadPdfFormatException
IOException
BadPdfFormatException
public void addPage(Rectangle rect, int rotation) throws DocumentException
rect
- The page dimensionrotation
- The rotation angle in degrees
DocumentException
public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref) throws IOException
PdfWriter
addToBody
in class PdfWriter
IOException
public PdfIndirectObject addToBody(PdfObject object) throws IOException
PdfWriter
addToBody
in class PdfWriter
IOException
protected void flushTaggedObjects() throws IOException
PdfWriter
flushTaggedObjects
in class PdfWriter
IOException
protected void fixTaggedStructure() throws IOException
IOException
protected void flushIndirectObjects() throws IOException
IOException
public void copyAcroForm(PdfReader reader) throws IOException, BadPdfFormatException
reader
- The reader of the input file that is being copied
IOException,
- BadPdfFormatException
IOException
BadPdfFormatException
protected PdfDictionary getCatalog(PdfIndirectReference rootObj)
getCatalog
in class PdfWriter
protected boolean isStructTreeRootReference(PdfIndirectReference prRef)
public void close()
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.
close
in interface DocListener
close
in class PdfWriter
DocWriter.close()
public PdfIndirectReference add(PdfOutline outline)
public void addAnnotation(PdfAnnotation annot)
PdfAnnotations
PdfAnnotation
or a PdfFormField
to the document. Only the top parent of a PdfFormField
needs to be added.
addAnnotation
in interface PdfAnnotations
addAnnotation
in class PdfWriter
annot
- the PdfAnnotation
or the PdfFormField
to addPdfAnnotations.addAnnotation(com.itextpdf.text.pdf.PdfAnnotation)
public void freeReader(PdfReader reader) throws IOException
PdfWriter
freeReader
in class PdfWriter
reader
- the PdfReader
to free
IOException
- on errorpublic PdfCopy.PageStamp createPageStamp(PdfImportedPage iPage)
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);
iPage
- an imported page
PageStamp
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |