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
Make copies of PDF documents. Documents can be edited after reading and
before writing them out.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classThis class holds information about indirect references, since they are renumbered by iText.protected static classA key to allow us to hash indirect referencesprotected classNested classes/interfaces inherited from class PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected HashSetprotected HashMapprotected HashMapprotected PdfIndirectReferenceprotected PdfIndirectReferenceprotected ArrayListprotected PdfReaderprotected HashSetprotected HashMapprotected PdfIndirectReferenceFields inherited from class 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(PdfOutline outline) (package private) PdfIndirectReferenceadd(PdfPage page, PdfContents contents) Adds somePdfContentsto this Writer.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 PdfArrayTranslate a PRArray to a PdfArray.Translate a PRDictionary to a PdfDictionary.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.getImportedPage(PdfReader reader, int pageNumber) Grabs a page from the input documentgetPageReference(int page) Gets a reference to a page existing or not.getParent(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 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, setXmpMetadataMethods inherited from class 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 Details
-
indirects
-
indirectMap
-
currentObjectNum
protected int currentObjectNum -
reader
-
topPageParent
-
pageNumbersToRefs
-
m_new_bookmarks
-
m_new_extensions
-
fullFormFieldNames
-
topFormFieldNames
-
topFormFieldReadersData
-
-
Constructor Details
-
PdfCopy
Constructor- Parameters:
document-os- outputstream- Throws:
DocumentException
-
PdfCopy
-
-
Method Details
-
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
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
Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.- Throws:
IOExceptionBadPdfFormatException
-
copyStream
Translate a PRStream to a PdfStream. The data part copies itself.- Throws:
IOExceptionBadPdfFormatException
-
copyArray
Translate a PRArray to a PdfArray. Also translate all of the objects contained in it- Throws:
IOExceptionBadPdfFormatException
-
copyObject
Translate a PR-object to a Pdf-object- Throws:
IOExceptionBadPdfFormatException
-
setFromIPage
convenience method. Given an importedpage, set our "globals" -
setFromReader
convenience method. Given a reader, set our "globals" -
getParent
-
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
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
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
Sets the bookmarks. The list structure is defined inSimpleBookmark#.- Parameters:
outlines- the bookmarks ornullto remove any
-
setExtensions
-
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
-
addAnnotation
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
-
add
Description copied from class:PdfWriterAdds somePdfContentsto this Writer.The document has to be open before you can begin to add content to the body of the document.
- Overrides:
addin classPdfWriter- Parameters:
page- thePdfPageto addcontents- thePdfContentsof the page- Returns:
- a
PdfIndirectReference - Throws:
PdfException- on error
-