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 class
This class holds information about indirect references, since they are renumbered by iText.protected static class
A key to allow us to hash indirect referencesprotected class
Nested classes/interfaces inherited from class com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected HashSet
protected HashMap
protected HashMap
protected PdfIndirectReference
protected PdfIndirectReference
protected ArrayList
protected PdfReader
protected HashSet
protected HashMap
protected PdfIndirectReference
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(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
Translate 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 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.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) 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 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: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
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:
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:
IOException
BadPdfFormatException
-
copyDictionary
Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.- Throws:
IOException
BadPdfFormatException
-
copyStream
Translate a PRStream to a PdfStream. The data part copies itself.- Throws:
IOException
BadPdfFormatException
-
copyArray
Translate a PRArray to a PdfArray. Also translate all of the objects contained in it- Throws:
IOException
BadPdfFormatException
-
copyObject
Translate a PR-object to a Pdf-object- Throws:
IOException
BadPdfFormatException
-
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:
IOException
BadPdfFormatException
DocumentException
-
getPageReference
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
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
Sets the bookmarks. The list structure is defined inSimpleBookmark#
.- Parameters:
outlines
- the bookmarks ornull
to remove any
-
setExtensions
-
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
-
addAnnotation
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
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
-