Class PdfCopy
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.DocWriter
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PdfCopy.IndirectReferences
This class holds information about indirect references, since they are renumbered by iText.protected static class
PdfCopy.RefKey
A key to allow us to hash indirect referencesprotected class
PdfCopy.TopFormFieldData
-
Nested classes/interfaces inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer
-
-
Field Summary
Fields Modifier and Type Field Description protected int
currentObjectNum
protected java.util.HashSet
fullFormFieldNames
protected java.util.HashMap
indirectMap
protected java.util.HashMap
indirects
protected PdfIndirectReference
m_new_bookmarks
protected PdfIndirectReference
m_new_extensions
protected java.util.ArrayList
pageNumbersToRefs
protected PdfReader
reader
protected java.util.HashSet
topFormFieldNames
protected java.util.HashMap
topFormFieldReadersData
protected PdfIndirectReference
topPageParent
-
Fields inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
ALLOW_ASSEMBLY, ALLOW_COPY, ALLOW_DEGRADED_PRINTING, ALLOW_FILL_IN, ALLOW_MODIFY_ANNOTATIONS, ALLOW_MODIFY_CONTENTS, ALLOW_PRINTING, ALLOW_SCREENREADERS, AllowAssembly, AllowCopy, AllowDegradedPrinting, AllowFillIn, AllowModifyAnnotations, AllowModifyContents, AllowPrinting, AllowScreenReaders, body, CenterWindow, colorNumber, compressStreams, crypto, currentPageNumber, currentPdfReaderInstance, defaultColorspace, DID_PRINT, DID_SAVE, DirectionL2R, DirectionR2L, DisplayDocTitle, DO_NOT_ENCRYPT_METADATA, DOCUMENT_CLOSE, documentColors, documentExtGState, documentFonts, documentOCG, documentOCGorder, documentPatterns, documentProperties, documentShadingPatterns, documentShadings, documentSpotPatterns, EMBEDDED_FILES_ONLY, ENCRYPTION_AES_128, ENCRYPTION_MASK, fileID, filterStreams, FitWindow, fontNumber, formXObjects, formXObjectsCounter, fullCompression, GENERATION_MAX, group, HEADER, HideMenubar, HideToolbar, HideWindowUI, imageDictionary, importedPages, INVALID_ENCRYPTION, NO_SPACE_CHAR_RATIO, NonFullScreenPageModeUseNone, NonFullScreenPageModeUseOC, NonFullScreenPageModeUseOutlines, NonFullScreenPageModeUseThumbs, OCGRadioGroup, OCProperties, PAGE_CLOSE, PAGE_OPEN, PageLayoutOneColumn, PageLayoutSinglePage, PageLayoutTwoColumnLeft, PageLayoutTwoColumnRight, PageLayoutTwoPageLeft, PageLayoutTwoPageRight, PageModeFullScreen, PageModeUseAttachments, PageModeUseNone, PageModeUseOC, PageModeUseOutlines, PageModeUseThumbs, pageReferences, patternColorspaceCMYK, patternColorspaceGRAY, patternColorspaceRGB, patternNumber, PDF_VERSION_1_2, PDF_VERSION_1_3, PDF_VERSION_1_4, PDF_VERSION_1_5, PDF_VERSION_1_6, PDF_VERSION_1_7, PDFX1A2001, PDFX32002, PDFXKEY_CMYK, PDFXKEY_COLOR, PDFXKEY_FONT, PDFXKEY_GSTATE, PDFXKEY_IMAGE, PDFXKEY_LAYER, PDFXKEY_RGB, PDFXNONE, prevxref, PrintScalingNone, RUN_DIRECTION_DEFAULT, RUN_DIRECTION_LTR, RUN_DIRECTION_NO_BIDI, RUN_DIRECTION_RTL, runDirection, SIGNATURE_APPEND_ONLY, SIGNATURE_EXISTS, SPACE_CHAR_RATIO_DEFAULT, STANDARD_ENCRYPTION_128, STANDARD_ENCRYPTION_40, STRENGTH128BITS, STRENGTH40BITS, structureTreeRoot, tagged, userunit, VERSION_1_0, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6, VERSION_1_7, ViewerPreferencesMask, WILL_PRINT, WILL_SAVE, xmpMetadata
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfIndirectReference
add(PdfOutline outline)
(package private) PdfIndirectReference
add(PdfPage page, PdfContents contents)
Adds somePdfContents
to this Writer.void
addAnnotation(PdfAnnotation annot)
Adds aPdfAnnotation
or aPdfFormField
to the document.void
addPage(PdfImportedPage iPage)
Add an imported page to our outputvoid
close()
Signals that theDocument
was closed and that no otherElements
will be added.protected PdfArray
copyArray(PdfArray in)
Translate a PRArray to a PdfArray.PdfDictionary
copyDictionary(PdfDictionary in)
Translate a PRDictionary to a PdfDictionary.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 PdfObject
copyObject(PdfObject in)
Translate a PR-object to a Pdf-objectprotected PdfStream
copyStream(PRStream in)
Translate a PRStream to a PdfStream.protected PdfDictionary
getCatalog(PdfIndirectReference rootObj)
Copy the acroform for an input document.PdfImportedPage
getImportedPage(PdfReader reader, int pageNumber)
Grabs a page from the input documentPdfIndirectReference
getPageReference(int page)
Gets a reference to a page existing or not.PdfIndirectReference
getParent(PdfDictionary annot)
void
open()
Signals that theDocument
has been opened and thatElements
can be added.void
setExtensions(PdfIndirectReference extensions)
protected int
setFromIPage(PdfImportedPage iPage)
convenience method.void
setFromReader(PdfReader reader)
convenience method.void
setOutlines(PdfIndirectReference outlines)
Sets the bookmarks.-
Methods inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
addAnnotation, addCalculationOrder, addDirectTemplateSimple, addJavaScript, addJavaScript, addJavaScript, addLocalDestinations, addOCGRadioGroup, addSharedObjectsToBody, addSimple, addSimple, addSimpleExtGState, addSimplePattern, addSimplePatternColorspace, addSimpleProperty, addSimpleShading, addSimpleShadingPattern, addToBody, addToBody, addToBody, addToBody, addToBody, addToBody, checkPDFXConformance, eliminateFontSubset, freeReader, getAcroForm, getColorspaceName, getCurrentDocumentSize, getCurrentPage, getCurrentPageNumber, getDefaultColorspace, getDirectContent, getDirectContentUnder, getEncryption, getExtraCatalog, getFileID, getGroup, getImageReference, getIndirectReferenceNumber, getInfo, getNewObjectNumber, getOCProperties, getOs, getPageEvent, getPageNumber, getPdfDocument, getPdfIndirectReference, getPDFXConformance, getReaderFile, getRoot, getRootOutline, getRunDirection, getSpaceCharRatio, getStructureTreeRoot, getUserunit, getVerticalPosition, isFullCompression, isPaused, isStrictImageSequence, isTagged, propertyExists, registerLayer, releaseTemplate, reorderPages, resetContent, setAdditionalAction, setBoxSize, setCropBoxSize, setDefaultColorspace, setDuration, setEncryption, setEncryption, setFileID, setFullCompression, setGroup, setLinearPageMode, setOpenAction, setOpenAction, setOutputIntents, setOutputIntents, setPageAction, setPageEmpty, setPageEvent, setPageLabels, setPdfVersion, setPDFXConformance, setRunDirection, setSigFlags, setSpaceCharRatio, setStrictImageSequence, setTagged, setTransition, setUserunit, setViewerPreferences, setXmpMetadata
-
Methods inherited from class com.gitlab.pdftk_java.com.lowagie.text.DocWriter
add, addTabs, clearTextWrap, flush, getISOBytes, hasMarkupAttributes, isCloseStream, newPage, pause, resetFooter, resetHeader, resetPageCount, resume, setCloseStream, setMarginMirroring, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart
-
-
-
-
Field Detail
-
indirects
protected java.util.HashMap indirects
-
indirectMap
protected java.util.HashMap indirectMap
-
currentObjectNum
protected int currentObjectNum
-
reader
protected PdfReader reader
-
topPageParent
protected PdfIndirectReference topPageParent
-
pageNumbersToRefs
protected java.util.ArrayList pageNumbersToRefs
-
m_new_bookmarks
protected PdfIndirectReference m_new_bookmarks
-
m_new_extensions
protected PdfIndirectReference m_new_extensions
-
fullFormFieldNames
protected java.util.HashSet fullFormFieldNames
-
topFormFieldNames
protected java.util.HashSet topFormFieldNames
-
topFormFieldReadersData
protected java.util.HashMap topFormFieldReadersData
-
-
Constructor Detail
-
PdfCopy
public PdfCopy(Document document, java.io.OutputStream os) throws DocumentException
Constructor- Parameters:
document
-os
- outputstream- Throws:
DocumentException
-
PdfCopy
public PdfCopy(PdfWriter master)
-
-
Method Detail
-
open
public void open()
Description copied from class:PdfWriter
Signals that theDocument
has been opened and thatElements
can be added.When this method is called, the PDF-document header is written to the outputstream.
- Specified by:
open
in interfaceDocListener
- Overrides:
open
in classPdfWriter
-
getImportedPage
public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber) throws java.io.IOException
Grabs a page from the input document- Overrides:
getImportedPage
in classPdfWriter
- Parameters:
reader
- the reader of the documentpageNumber
- 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
-
copyDictionary
public PdfDictionary copyDictionary(PdfDictionary in) throws java.io.IOException, BadPdfFormatException
Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.- Throws:
java.io.IOException
BadPdfFormatException
-
copyStream
protected PdfStream copyStream(PRStream in) throws java.io.IOException, BadPdfFormatException
Translate a PRStream to a PdfStream. The data part copies itself.- Throws:
java.io.IOException
BadPdfFormatException
-
copyArray
protected PdfArray copyArray(PdfArray in) 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
-
copyObject
protected PdfObject copyObject(PdfObject in) throws java.io.IOException, BadPdfFormatException
Translate a PR-object to a Pdf-object- 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"
-
getParent
public PdfIndirectReference getParent(PdfDictionary annot)
-
addPage
public void addPage(PdfImportedPage iPage) throws java.io.IOException, BadPdfFormatException, DocumentException
Add an imported page to our output- Parameters:
iPage
- an imported page- Throws:
java.io.IOException
BadPdfFormatException
DocumentException
-
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 classPdfWriter
- Parameters:
page
- the page number. The first page is 1- Returns:
- the reference to the page
-
getCatalog
protected PdfDictionary getCatalog(PdfIndirectReference rootObj) throws DocumentException
Copy the acroform for an input document. Note that you can only have one, we make no effort to merge them.- Overrides:
getCatalog
in classPdfWriter
- Parameters:
reader
- The reader of the input file that is being copied- Throws:
DocumentException
-
setOutlines
public void setOutlines(PdfIndirectReference outlines)
Sets the bookmarks. The list structure is defined inSimpleBookmark#
.- Parameters:
outlines
- the bookmarks ornull
to remove any
-
setExtensions
public void setExtensions(PdfIndirectReference extensions)
-
close
public void close()
Signals that theDocument
was closed and that no otherElements
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 interfaceDocListener
- Overrides:
close
in classPdfWriter
-
add
public PdfIndirectReference add(PdfOutline outline)
-
addAnnotation
public void addAnnotation(PdfAnnotation annot)
Description copied from class:PdfWriter
Adds aPdfAnnotation
or aPdfFormField
to the document. Only the top parent of aPdfFormField
needs to be added.- Overrides:
addAnnotation
in classPdfWriter
- Parameters:
annot
- thePdfAnnotation
or thePdfFormField
to add
-
add
PdfIndirectReference add(PdfPage page, PdfContents contents) throws PdfException
Description copied from class:PdfWriter
Adds somePdfContents
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 classPdfWriter
- Parameters:
page
- thePdfPage
to addcontents
- thePdfContents
of the page- Returns:
- a
PdfIndirectReference
- Throws:
PdfException
- on error
-
-