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,EventListener
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
Nested Classes Modifier and Type Class Description protected static classPdfCopy.RefKeyA key to allow us to hash indirect referencesprotected classPdfCopy.TopFormFieldData-
Nested classes/interfaces inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
PdfWriter.PdfBody
-
-
Field Summary
Fields Modifier and Type Field Description protected intcurrentObjectNumprotected HashSetfullFormFieldNamesprotected HashMapindirectMapprotected HashMapindirectsprotected PdfIndirectReferencem_new_bookmarksprotected PdfIndirectReferencem_new_extensionsprotected ArrayListpageNumbersToRefsprotected PdfReaderreaderprotected HashSettopFormFieldNamesprotected HashMaptopFormFieldReadersDataprotected PdfIndirectReferencetopPageParent-
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, 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, 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, WILL_PRINT, WILL_SAVE, xmpMetadata
-
-
Constructor Summary
Constructors Constructor Description PdfCopy(Document document, OutputStream os)ConstructorPdfCopy(PdfWriter master)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfIndirectReferenceadd(PdfOutline outline)voidaddAnnotation(PdfAnnotation annot)Adds aPdfAnnotationor aPdfFormFieldto the document.voidaddPage(PdfImportedPage iPage)Add an imported page to our outputvoidclose()Signals that theDocumentwas closed and that no otherElementswill be added.protected PdfArraycopyArray(PdfArray in)Translate a PRArray to a PdfArray.PdfDictionarycopyDictionary(PdfDictionary in)Translate a PRDictionary to a PdfDictionary.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-objectprotected PdfStreamcopyStream(PRStream in)Translate a PRStream to a PdfStream.protected PdfDictionarygetCatalog(PdfIndirectReference rootObj)Copy the acroform for an input document.PdfImportedPagegetImportedPage(PdfReader reader, int pageNumber)Grabs a page from the input documentPdfIndirectReferencegetPageReference(int page)Gets a reference to a page existing or not.PdfIndirectReferencegetParent(PdfDictionary annot)voidopen()Signals that theDocumenthas been opened and thatElementscan be added.voidsetExtensions(PdfIndirectReference extensions)protected intsetFromIPage(PdfImportedPage iPage)convenience method.voidsetFromReader(PdfReader reader)convenience method.voidsetOutlines(PdfIndirectReference outlines)Sets the bookmarks.-
Methods inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
addCalculationOrder, addJavaScript, addJavaScript, addJavaScript, addOCGRadioGroup, addSharedObjectsToBody, addToBody, addToBody, addToBody, addToBody, addToBody, addToBody, freeReader, getAcroForm, getCurrentDocumentSize, getDefaultColorspace, getDirectContent, getDirectContentUnder, getExtraCatalog, getFileID, getGroup, getInfo, getNewObjectNumber, getOCProperties, getOs, getPageEvent, getPageNumber, getPdfDocument, getPdfIndirectReference, getPDFXConformance, getRoot, getRootOutline, getRunDirection, getSpaceCharRatio, getStructureTreeRoot, getUserunit, getVerticalPosition, isFullCompression, isStrictImageSequence, isTagged, releaseTemplate, reorderPages, 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 HashMap indirects
-
indirectMap
protected HashMap indirectMap
-
currentObjectNum
protected int currentObjectNum
-
reader
protected PdfReader reader
-
topPageParent
protected PdfIndirectReference topPageParent
-
pageNumbersToRefs
protected ArrayList pageNumbersToRefs
-
m_new_bookmarks
protected PdfIndirectReference m_new_bookmarks
-
m_new_extensions
protected PdfIndirectReference m_new_extensions
-
fullFormFieldNames
protected HashSet fullFormFieldNames
-
topFormFieldNames
protected HashSet topFormFieldNames
-
topFormFieldReadersData
protected HashMap topFormFieldReadersData
-
-
Constructor Detail
-
PdfCopy
public PdfCopy(Document document, 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:PdfWriterSignals that theDocumenthas been opened and thatElementscan be added.When this method is called, the PDF-document header is written to the outputstream.
- Specified by:
openin interfaceDocListener- Overrides:
openin classPdfWriter
-
getImportedPage
public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber) throws IOException
Grabs a page from the input document- Overrides:
getImportedPagein classPdfWriter- Parameters:
reader- the reader of the documentpageNumber- which page to get- Returns:
- the page
- Throws:
IOException
-
copyIndirect
public PdfIndirectReference copyIndirect(PRIndirectReference in) throws 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:
IOExceptionBadPdfFormatException
-
copyDictionary
public PdfDictionary copyDictionary(PdfDictionary in) throws IOException, BadPdfFormatException
Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.- Throws:
IOExceptionBadPdfFormatException
-
copyStream
protected PdfStream copyStream(PRStream in) throws IOException, BadPdfFormatException
Translate a PRStream to a PdfStream. The data part copies itself.- Throws:
IOExceptionBadPdfFormatException
-
copyArray
protected PdfArray copyArray(PdfArray in) throws IOException, BadPdfFormatException
Translate a PRArray to a PdfArray. Also translate all of the objects contained in it- Throws:
IOExceptionBadPdfFormatException
-
copyObject
protected PdfObject copyObject(PdfObject in) throws IOException, BadPdfFormatException
Translate a PR-object to a Pdf-object- Throws:
IOExceptionBadPdfFormatException
-
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 IOException, BadPdfFormatException, DocumentException
Add an imported page to our output- Parameters:
iPage- an imported page- Throws:
IOExceptionBadPdfFormatExceptionDocumentException
-
getPageReference
public PdfIndirectReference getPageReference(int page)
Description copied from class:PdfWriterGets 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:
getPageReferencein 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:
getCatalogin 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 ornullto remove any
-
setExtensions
public void setExtensions(PdfIndirectReference extensions)
-
close
public void close()
Signals that theDocumentwas closed and that no otherElementswill 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:
closein interfaceDocListener- Overrides:
closein classPdfWriter
-
add
public PdfIndirectReference add(PdfOutline outline)
-
addAnnotation
public void addAnnotation(PdfAnnotation annot)
Description copied from class:PdfWriterAdds aPdfAnnotationor aPdfFormFieldto the document. Only the top parent of aPdfFormFieldneeds to be added.- Overrides:
addAnnotationin classPdfWriter- Parameters:
annot- thePdfAnnotationor thePdfFormFieldto add
-
-