Class PdfWriter
- All Implemented Interfaces:
DocListener
,ElementListener
,PdfAnnotations
,PdfDocumentActions
,PdfEncryptionSettings
,PdfPageActions
,PdfRunDirection
,PdfVersion
,PdfViewerPreferences
,EventListener
- Direct Known Subclasses:
FdfWriter.Wrt
,PdfAWriter
,PdfCopy
,PdfCopyFieldsImp
,PdfStamperImp
DocWriter
class for PDF.
When this PdfWriter
is added
to a certain PdfDocument
, the PDF representation of every Element
added to this Document will be written to the outputstream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class generates the structure of a PDF document.static class
PdfTrailer
is the PDF Trailer object. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
The operation permitted when the document is opened with the user passwordstatic final int
Deprecated.static final int
Deprecated.As of iText 2.0.7, useALLOW_COPY
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_DEGRADED_PRINTING
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_FILL_IN
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_MODIFY_ANNOTATIONS
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_MODIFY_CONTENTS
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_PRINTING
instead.static final int
Deprecated.As of iText 2.0.7, useALLOW_SCREENREADERS
instead.protected PdfWriter.PdfBody
body of the PDF documentstatic final int
A viewer preferenceprotected int
The color number counter for the colors in the document.protected ICC_Profile
protected int
The compression level of the content streams.protected static Counter
protected PdfEncryption
Contains the business logic for cryptography.protected int
The current page number.protected PdfReaderInstance
protected PdfDictionary
static final PdfName
action valuestatic final PdfName
action valueprotected PdfContentByte
The direct content in this document.protected PdfContentByte
The direct content under in this document.static final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
Add this to the mode to keep the metadata in clear textstatic final PdfName
action valueprotected HashMap
<ICachedColorSpace, ColorDetails> The colors of this documentprotected HashMap
<PdfDictionary, PdfObject[]> protected LinkedHashMap
<BaseFont, FontDetails> The fonts of this documentprotected LinkedHashSet
<PdfOCG> A hashSet containing all the PdfLayer objects.An array list used to define the order of an OCG tree.protected HashMap
<PdfPatternPainter, PdfName> The patterns of this documentprotected HashSet
<PdfShadingPattern> protected HashSet
<PdfShading> protected HashMap
<ColorDetails, ColorDetails> static final int
Add this to the mode to keep encrypt only the embedded files.static final int
Type of encryptionstatic final int
Type of encryption(package private) static final int
Mask to separate the encryption type from the encryption mode.protected PdfDictionary
Holds value of property extraCatalog this is used for Output Intents.static final int
A viewer preferenceprotected int
The font number counter for the fonts in the document.protected HashMap
<PdfIndirectReference, Object[]> The form XObjects in this document.protected int
The name counter for the form XObjects name.protected boolean
Holds value of property fullCompression.static final int
The highest generation number possible.protected PdfDictionary
A group attributes dictionary specifying the attributes of the page's page group for use in the transparent imaging modelstatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferenceprotected PdfDictionary
Dictionary, containing all the images of the PDF documentThis is the list with all the images in the document.protected HashMap
<PdfStream, PdfIndirectReference> A HashSet with Stream objects containing JBIG2 Globalsstatic final int
static final int
static final float
Disable the inter-character spacing.static final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferenceprotected PdfArray
The locked array in an OCG dictionaryprotected PdfArray
The RBGroups array in an OCG dictionaryprotected PdfOCProperties
The OCProperties in a catalog dictionary.protected byte[]
The original file ID (if present).static final PdfName
action valuestatic final PdfName
action valueprotected PdfDictionary
Additional page dictionary entries.private PdfPageEvent
ThePdfPageEvent
for this document.static final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferencestatic final int
A viewer preferenceprotected ArrayList
<PdfIndirectReference> The PdfIndirectReference to the pages.protected ColorDetails
protected ColorDetails
protected ColorDetails
protected int
The pattern number counter for the colors in the document.protected PdfDocument
the pdfdocument object.protected PdfVersionImp
Stores the version information for the header and the catalog.static final PdfName
possible PDF version (catalog)static final PdfName
possible PDF version (catalog)static final PdfName
possible PDF version (catalog)static final PdfName
possible PDF version (catalog)static final PdfName
possible PDF version (catalog)static final PdfName
possible PDF version (catalog)protected PdfIsoConformance
Stores the PDF ISO conformance.static final int
A PDF/X level.static final int
A PDF/X level.static final int
A PDF/X level.protected long
A number referring to the previous Cross-Reference Table.static final int
A viewer preferenceprotected HashMap
<PdfReader, PdfReaderInstance> Instances of PdfReader/PdfReaderInstance that are used to import pages.private boolean
Holds value of property RGBTranparency.protected PdfPages
The root of the page tree.static final int
Use the default run direction.static final int
Use bidirectional reordering with left-to-right preferential run direction.static final int
Do not use bidirectional reordering.static final int
Use bidirectional reordering with right-to-left preferential run direction.protected int
static final int
signature valuestatic final int
signature valuestatic final float
The default space-char ratio.private float
The ratio between the extra word spacing and the extra character spacing.static final int
Type of encryptionstatic final int
Type of encryptionstatic final boolean
Deprecated.As of iText 2.0.7, useSTANDARD_ENCRYPTION_128
instead.static final boolean
Deprecated.As of iText 2.0.7, useSTANDARD_ENCRYPTION_40
instead.protected PdfStructureTreeRoot
protected PdfName
The value of the Tabs entry in the page dictionary.protected boolean
protected int
protected TtfUnicodeWriter
private boolean
A flag indicating the presence of structure elements that contain user properties attributes.static final char
possible PDF version (header)static final char
possible PDF version (header)static final char
possible PDF version (header)static final char
possible PDF version (header)static final char
possible PDF version (header)static final char
possible PDF version (header)static final PdfName
action valuestatic final PdfName
action valueprotected byte[]
XMP Metadata for the document.protected XmpWriter
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructs aPdfWriter
.protected
PdfWriter
(PdfDocument document, OutputStream os) Constructs aPdfWriter
. -
Method Summary
Modifier and TypeMethodDescriptionprotected PdfIndirectReference
add
(PdfICCBased icc) (package private) PdfIndirectReference
add
(PdfImage pdfImage, PdfIndirectReference fixedRef) Writes aPdfImage
to the outputstream.(package private) PdfIndirectReference
add
(PdfPage page, PdfContents contents) Adds somePdfContents
to this Writer.void
addAnnotation
(PdfAnnotation annot) Use this methods to add aPdfAnnotation
or aPdfFormField
to the document.(package private) void
addAnnotation
(PdfAnnotation annot, int page) private void
addASEvent
(PdfName event, PdfName category) void
addCalculationOrder
(PdfFormField annot) Use this method to adds thePdfAnnotation
to the calculation order array.void
Adds a developer extension to the Extensions dictionary in the Catalog.addDirectImageSimple
(Image image) Use this method to adds an image to the document but not to the page resources.addDirectImageSimple
(Image image, PdfIndirectReference fixedRef) Adds an image to the document but not to the page resources.(package private) PdfName
addDirectTemplateSimple
(PdfTemplate template, PdfName forcedName) Adds a template to the document but not to the page resources.void
Use this method to add a file attachment at the document level.void
addFileAttachment
(String description, byte[] fileStore, String file, String fileDisplay) Use this method to add a file attachment at the document level.void
addFileAttachment
(String description, PdfFileSpecification fs) Use this method to add a file attachment at the document level.void
Use this method to add a JavaScript action at the document level.void
addJavaScript
(String code) Use this method to adds a JavaScript action at the document level.void
addJavaScript
(String code, boolean unicode) Use this method to add a JavaScript action at the document level.void
addJavaScript
(String name, PdfAction js) Use this method to add a JavaScript action at the document level.void
addJavaScript
(String name, String code) Use this method to adds a JavaScript action at the document level.void
addJavaScript
(String name, String code, boolean unicode) Use this method to add a JavaScript action at the document level.(package private) void
Adds the local destinations to the body of the document.void
addNamedDestination
(String name, int page, PdfDestination dest) Adds one named destination.void
addNamedDestinations
(Map<String, String> map, int page_offset) Adds named destinations in bulk.void
addOCGRadioGroup
(ArrayList<PdfLayer> group) Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm.void
addPageDictEntry
(PdfName key, PdfObject object) Adds an additional entry for the page dictionary.protected void
(package private) FontDetails
Adds aBaseFont
to the document but not to the page resources.(package private) ColorDetails
Adds aSpotColor
to the document but not to the page resources.(package private) PdfObject[]
addSimpleExtGState
(PdfDictionary gstate) (package private) PdfName
addSimplePattern
(PdfPatternPainter painter) (package private) ColorDetails
(package private) PdfObject[]
addSimpleProperty
(Object prop, PdfIndirectReference refi) (package private) void
addSimpleShading
(PdfShading shading) (package private) void
addSimpleShadingPattern
(PdfShadingPattern shading) Use this method to add a PDF object to the PDF body.Use this method to add a PDF object to the PDF body.Use this method to add a PDF object to the PDF body.Use this method to add a PDF object to the PDF body.addToBody
(PdfObject object, PdfIndirectReference ref) Use this method to add a PDF object to the PDF body.addToBody
(PdfObject object, PdfIndirectReference ref, boolean inObjStm) Use this method to add a PDF object to the PDF body.void
addViewerPreference
(PdfName key, PdfObject value) Adds a viewer preference.protected void
protected void
protected void
cacheObject
(PdfIndirectObject iobj) Use this method for caching objects.void
checkElementRole
(IAccessibleElement element, IAccessibleElement parent) void
checkPdfIsoConformance
(int key, Object obj1) static void
checkPdfIsoConformance
(PdfWriter writer, int key, Object obj1) void
Use this method to clear text wrapping around images (if applicable).void
close()
Signals that theDocument
was closed and that no otherElements
will be added.private void
completeExtraCatalog
(PdfDictionary extraCatalog) private void
createAnnotation
(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype) A wrapper around PdfAnnotation constructor.createAnnotation
(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype) A wrapper around PdfAnnotation constructor.createAnnotation
(Rectangle rect, PdfName subtype) A wrapper around PdfAnnotation constructor.void
Use this method to creates XMP Metadata based on the metadata in the PdfDocument.protected XmpWriter
createXmpWriter
(ByteArrayOutputStream baos, PdfDictionary info) protected XmpWriter
createXmpWriter
(ByteArrayOutputStream baos, HashMap<String, String> info) (package private) void
eliminateFontSubset
(PdfDictionary fonts) protected void
fillOCProperties
(boolean erase) protected void
protected void
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.Use this methods to get the AcroForm object.getBoxSize
(String boxName) Use this method to get the size of a trim, art, crop or bleed box, or null if not defined.getBoxSize
(String boxName, Rectangle intersectingRectangle) Returns the intersection between the crop, trim art or bleed box and the parameter intersectingRectangle.protected PdfDictionary
getCatalog
(PdfIndirectReference rootObj) (package private) PdfName
int
Returns the compression level used for streams written by this writer.protected Counter
long
Use this method to gets the current document size.(package private) PdfIndirectReference
int
Use this method to get the default colorspaces.Use this method to get the direct content for this document.Use this method to get the direct content under for this document.(package private) PdfEncryption
Sets extra keys to the catalog.getGroup()
Use this method to get the group dictionary.(package private) PdfIndirectReference
getImageReference
(PdfName name) return thePdfIndirectReference
to the image with a given name.getImportedPage
(PdfReader reader, int pageNumber) Use this method to get a page from other PDF document.protected int
getInfo()
Use this method to get the info dictionary if you want to change it directly (add keys and values to the info dictionary).static PdfWriter
getInstance
(Document document, OutputStream os) Use this method to get an instance of thePdfWriter
.static PdfWriter
getInstance
(Document document, OutputStream os, DocListener listener) Use this method to get an instance of thePdfWriter
.protected static String
getNameString
(PdfDictionary dic, PdfName key) protected int
getNewObjectNumber
(PdfReader reader, int number, int generation) private static void
getOCGOrder
(PdfArray order, PdfLayer layer) Use this method to get the Optional Content Properties Dictionary.getOs()
Returns the outputStreamCounter.Gets the additional pageDictEntries.Gets thePdfPageEvent
for this document ornull
if none is set.int
Gets the pagenumber of this document.getPageReference
(int page) Use this method to get a reference to a page existing or not.Use this method to get the size of the media box.(package private) PdfDocument
Gets thePdfDocument
associated with this writer.Use this to get anPdfIndirectReference
for an object that will be created in the future.protected PdfReaderInstance
getPdfReaderInstance
(PdfReader reader) Returns the PdfReaderInstance associated with the specified reader.(package private) PdfVersionImp
Returns the version information.int
(package private) RandomAccessFileOrArray
getReaderFile
(PdfReader reader) protected PdfIndirectReference
getReferenceJBIG2Globals
(byte[] content) Gets an indirect reference to a JBIG2 Globals stream.Use this method to get the root outline and construct bookmarks.int
Use this method to set the run direction.float
Use this method to gets the space/character extra spacing ratio for fully justified text.Gets the list of the standard structure element names (roles).Gets the structure tree root.getTabs()
Returns the value to be used for the Tabs entry in the page tree.protected TtfUnicodeWriter
float
getVerticalPosition
(boolean ensureNewLine) Use this method to get the current vertical page position.protected PdfIsoConformance
boolean
Use this method to find out if 1.5 compression is on.boolean
Checks if a newPage() will actually generate a new page.boolean
isPdfIso()
Checks if any PDF ISO conformance is necessary.boolean
isPdfX()
boolean
Gets the transparency blending colorspace.boolean
Use this method to get the strictImageSequence status.boolean
isTagged()
Check if the document is marked for tagging.boolean
Gets the flag indicating the presence of structure elements that contain user properties attributes.void
Use this method to lock an optional content group.boolean
void
open()
Signals that theDocument
has been opened and thatElements
can be added.(package private) boolean
propertyExists
(Object prop) (package private) void
registerLayer
(PdfOCG layer) void
Use this method to releases the memory used by a template.int
reorderPages
(int[] order) Use this method to reorder the pages in the document.(package private) void
Resets all the direct contents to empty.void
Resets the additional pageDictEntries.void
setAdditionalAction
(PdfName actionType, PdfAction action) Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole.void
setAtLeastPdfVersion
(char version) If the PDF Header hasn't been written yet, this changes the version as it will appear in the PDF Header, but only if the parameter refers to a higher version.void
setBoxSize
(String boxName, Rectangle size) Use this method to set the page box sizes.void
setCollection
(PdfCollection collection) Use this method to add the Collection dictionary.void
setCompressionLevel
(int compressionLevel) Sets the compression level to be used for streams written by this writer.void
setCropBoxSize
(Rectangle crop) Use this method to set the crop box.void
setDefaultColorspace
(PdfName key, PdfObject cs) Use this method to sets the default colorspace that will be applied to all the document.void
setDuration
(int seconds) Sets the display duration for the page (for presentations)void
setEncryption
(boolean strength, String userPassword, String ownerPassword, int permissions) Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}.void
setEncryption
(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}.void
setEncryption
(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) Sets the encryption options for this document.void
setEncryption
(int encryptionType, String userPassword, String ownerPassword, int permissions) Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}.void
setEncryption
(Certificate[] certs, int[] permissions, int encryptionType) Sets the encryption options for this document.void
Use this method to set the document's compression to the PDF 1.5 mode with object streams and xref streams.void
setGroup
(PdfDictionary group) Use this method to set the group dictionary.void
setInitialLeading
(float leading) Sets the initial leading for the PDF document.void
setLanguage
(String language) void
Use this method to make sure the page tree has a linear structure (every leave is attached directly to the root).void
setOpenAction
(PdfAction action) When the document opens thisaction
will be invoked.void
setOpenAction
(String name) When the document opens it will jump to the destination with this name.void
setOutlines
(List<HashMap<String, Object>> outlines) Sets the bookmarks.boolean
setOutputIntents
(PdfReader reader, boolean checkExistence) Use this method to copy the output intent dictionary from another document to this one.void
setOutputIntents
(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte[] destOutputProfile) Sets the values of the output intent dictionary.void
setOutputIntents
(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) Sets the values of the output intent dictionary.void
setPageAction
(PdfName actionType, PdfAction action) Sets the open and close page additional action.void
setPageEmpty
(boolean pageEmpty) Use this method to make sure a page is added, even if it's empty.void
setPageEvent
(PdfPageEvent event) Sets thePdfPageEvent
for this document.void
setPageLabels
(PdfPageLabels pageLabels) Use this method to add page labelsvoid
Sets the Viewport for the next page.void
setPageXmpMetadata
(byte[] xmpMetadata) Use this method to set the XMP Metadata for each page.void
setPdfVersion
(char version) If the PDF Header hasn't been written yet, this changes the version as it will appear in the PDF Header.void
setPdfVersion
(PdfName version) Sets the PDF version as it will appear in the Catalog.void
setPDFXConformance
(int pdfx) void
setRgbTransparencyBlending
(boolean rgbTransparencyBlending) Sets the transparency blending colorspace to RGB.void
setRunDirection
(int runDirection) Use this method to set the run direction.void
setSigFlags
(int f) Use this method to set the signature flags.void
setSpaceCharRatio
(float spaceCharRatio) Use this method to set the ratio between the extra word spacing and the extra character spacing when the text is fully justified.void
setStrictImageSequence
(boolean strictImageSequence) Use this method to set the image sequence, so that it follows the text in strict order (or not).void
Sets the value for the Tabs entry in the page tree.void
Mark this document for tagging.void
setTagged
(int taggingMode) void
setThumbnail
(Image image) Use this method to set the thumbnail image for the current page.void
setTransition
(PdfTransition transition) Sets the transition for the pagevoid
setUserProperties
(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.void
setUserunit
(float userunit) Use this method to set the user unit.void
setViewerPreferences
(int preferences) Sets the page layout and page mode preferences by ORing one or two of these constants.void
setXmpMetadata
(byte[] xmpMetadata) Use this method to set the XMP Metadata.void
useExternalCacheForTagStructure
(TempFileCache fileCache) protected static void
protected void
writeOutlines
(PdfDictionary catalog, boolean namedAsNames) 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
-
Field Details
-
GENERATION_MAX
public static final int GENERATION_MAXThe highest generation number possible.- Since:
- iText 2.1.6
- See Also:
-
COUNTER
-
pdf
the pdfdocument object. -
directContent
The direct content in this document. -
directContentUnder
The direct content under in this document. -
body
body of the PDF document -
colorProfile
-
extraCatalog
Holds value of property extraCatalog this is used for Output Intents. -
root
The root of the page tree. -
pageReferences
The PdfIndirectReference to the pages. -
currentPageNumber
protected int currentPageNumberThe current page number. -
tabs
The value of the Tabs entry in the page dictionary.- Since:
- 2.1.5
-
pageDictEntries
Additional page dictionary entries.- Since:
- 5.1.0
-
pageEvent
ThePdfPageEvent
for this document. -
prevxref
protected long prevxrefA number referring to the previous Cross-Reference Table. -
originalFileID
protected byte[] originalFileIDThe original file ID (if present). -
newBookmarks
-
VERSION_1_2
public static final char VERSION_1_2possible PDF version (header)- See Also:
-
VERSION_1_3
public static final char VERSION_1_3possible PDF version (header)- See Also:
-
VERSION_1_4
public static final char VERSION_1_4possible PDF version (header)- See Also:
-
VERSION_1_5
public static final char VERSION_1_5possible PDF version (header)- See Also:
-
VERSION_1_6
public static final char VERSION_1_6possible PDF version (header)- See Also:
-
VERSION_1_7
public static final char VERSION_1_7possible PDF version (header)- See Also:
-
PDF_VERSION_1_2
possible PDF version (catalog) -
PDF_VERSION_1_3
possible PDF version (catalog) -
PDF_VERSION_1_4
possible PDF version (catalog) -
PDF_VERSION_1_5
possible PDF version (catalog) -
PDF_VERSION_1_6
possible PDF version (catalog) -
PDF_VERSION_1_7
possible PDF version (catalog) -
pdf_version
Stores the version information for the header and the catalog. -
PageLayoutSinglePage
public static final int PageLayoutSinglePageA viewer preference- See Also:
-
PageLayoutOneColumn
public static final int PageLayoutOneColumnA viewer preference- See Also:
-
PageLayoutTwoColumnLeft
public static final int PageLayoutTwoColumnLeftA viewer preference- See Also:
-
PageLayoutTwoColumnRight
public static final int PageLayoutTwoColumnRightA viewer preference- See Also:
-
PageLayoutTwoPageLeft
public static final int PageLayoutTwoPageLeftA viewer preference- See Also:
-
PageLayoutTwoPageRight
public static final int PageLayoutTwoPageRightA viewer preference- See Also:
-
PageModeUseNone
public static final int PageModeUseNoneA viewer preference- See Also:
-
PageModeUseOutlines
public static final int PageModeUseOutlinesA viewer preference- See Also:
-
PageModeUseThumbs
public static final int PageModeUseThumbsA viewer preference- See Also:
-
PageModeFullScreen
public static final int PageModeFullScreenA viewer preference- See Also:
-
PageModeUseOC
public static final int PageModeUseOCA viewer preference- See Also:
-
PageModeUseAttachments
public static final int PageModeUseAttachmentsA viewer preference- See Also:
-
HideToolbar
public static final int HideToolbarA viewer preference- See Also:
-
HideMenubar
public static final int HideMenubarA viewer preference- See Also:
-
HideWindowUI
public static final int HideWindowUIA viewer preference- See Also:
-
FitWindow
public static final int FitWindowA viewer preference- See Also:
-
CenterWindow
public static final int CenterWindowA viewer preference- See Also:
-
DisplayDocTitle
public static final int DisplayDocTitleA viewer preference- See Also:
-
NonFullScreenPageModeUseNone
public static final int NonFullScreenPageModeUseNoneA viewer preference- See Also:
-
NonFullScreenPageModeUseOutlines
public static final int NonFullScreenPageModeUseOutlinesA viewer preference- See Also:
-
NonFullScreenPageModeUseThumbs
public static final int NonFullScreenPageModeUseThumbsA viewer preference- See Also:
-
NonFullScreenPageModeUseOC
public static final int NonFullScreenPageModeUseOCA viewer preference- See Also:
-
DirectionL2R
public static final int DirectionL2RA viewer preference- See Also:
-
DirectionR2L
public static final int DirectionR2LA viewer preference- See Also:
-
PrintScalingNone
public static final int PrintScalingNoneA viewer preference- See Also:
-
DOCUMENT_CLOSE
action value -
WILL_SAVE
action value -
DID_SAVE
action value -
WILL_PRINT
action value -
DID_PRINT
action value -
SIGNATURE_EXISTS
public static final int SIGNATURE_EXISTSsignature value- See Also:
-
SIGNATURE_APPEND_ONLY
public static final int SIGNATURE_APPEND_ONLYsignature value- See Also:
-
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the document. -
xmpWriter
-
PDFXNONE
public static final int PDFXNONEA PDF/X level.- See Also:
-
PDFX1A2001
public static final int PDFX1A2001A PDF/X level.- See Also:
-
PDFX32002
public static final int PDFX32002A PDF/X level.- See Also:
-
pdfIsoConformance
Stores the PDF ISO conformance. -
STANDARD_ENCRYPTION_40
public static final int STANDARD_ENCRYPTION_40Type of encryption- See Also:
-
STANDARD_ENCRYPTION_128
public static final int STANDARD_ENCRYPTION_128Type of encryption- See Also:
-
ENCRYPTION_AES_128
public static final int ENCRYPTION_AES_128Type of encryption- See Also:
-
ENCRYPTION_AES_256
public static final int ENCRYPTION_AES_256Type of encryption- See Also:
-
ENCRYPTION_MASK
static final int ENCRYPTION_MASKMask to separate the encryption type from the encryption mode.- See Also:
-
DO_NOT_ENCRYPT_METADATA
public static final int DO_NOT_ENCRYPT_METADATAAdd this to the mode to keep the metadata in clear text- See Also:
-
EMBEDDED_FILES_ONLY
public static final int EMBEDDED_FILES_ONLYAdd this to the mode to keep encrypt only the embedded files.- Since:
- 2.1.3
- See Also:
-
ALLOW_PRINTING
public static final int ALLOW_PRINTINGThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_MODIFY_CONTENTS
public static final int ALLOW_MODIFY_CONTENTSThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_COPY
public static final int ALLOW_COPYThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_MODIFY_ANNOTATIONS
public static final int ALLOW_MODIFY_ANNOTATIONSThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_FILL_IN
public static final int ALLOW_FILL_INThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_SCREENREADERS
public static final int ALLOW_SCREENREADERSThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_ASSEMBLY
public static final int ALLOW_ASSEMBLYThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
ALLOW_DEGRADED_PRINTING
public static final int ALLOW_DEGRADED_PRINTINGThe operation permitted when the document is opened with the user password- Since:
- 2.0.7
- See Also:
-
AllowPrinting
Deprecated.As of iText 2.0.7, useALLOW_PRINTING
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowModifyContents
Deprecated.As of iText 2.0.7, useALLOW_MODIFY_CONTENTS
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowCopy
Deprecated.As of iText 2.0.7, useALLOW_COPY
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowModifyAnnotations
Deprecated.As of iText 2.0.7, useALLOW_MODIFY_ANNOTATIONS
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowFillIn
Deprecated.As of iText 2.0.7, useALLOW_FILL_IN
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowScreenReaders
Deprecated.As of iText 2.0.7, useALLOW_SCREENREADERS
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowAssembly
Deprecated.As of iText 2.0.7, useALLOW_ASSEMBLY
instead. Scheduled for removal at or after 2.2.0- See Also:
-
AllowDegradedPrinting
Deprecated.As of iText 2.0.7, useALLOW_DEGRADED_PRINTING
instead. Scheduled for removal at or after 2.2.0- See Also:
-
STRENGTH40BITS
Deprecated.As of iText 2.0.7, useSTANDARD_ENCRYPTION_40
instead. Scheduled for removal at or after 2.2.0- See Also:
-
STRENGTH128BITS
Deprecated.As of iText 2.0.7, useSTANDARD_ENCRYPTION_128
instead. Scheduled for removal at or after 2.2.0- See Also:
-
crypto
Contains the business logic for cryptography. -
fullCompression
protected boolean fullCompressionHolds value of property fullCompression. -
compressionLevel
protected int compressionLevelThe compression level of the content streams.- Since:
- 2.1.3
-
documentFonts
The fonts of this document -
fontNumber
protected int fontNumberThe font number counter for the fonts in the document. -
formXObjects
The form XObjects in this document. The key is the xref and the value is Object[]{PdfName, template}. -
formXObjectsCounter
protected int formXObjectsCounterThe name counter for the form XObjects name. -
readerInstances
Instances of PdfReader/PdfReaderInstance that are used to import pages.- Since:
- 5.0.3
-
currentPdfReaderInstance
-
documentColors
The colors of this document -
colorNumber
protected int colorNumberThe color number counter for the colors in the document. -
documentPatterns
The patterns of this document -
patternNumber
protected int patternNumberThe pattern number counter for the colors in the document. -
documentShadingPatterns
-
documentShadings
-
documentExtGState
-
documentProperties
-
markAll
public static final int markAll- See Also:
-
markInlineElementsOnly
public static final int markInlineElementsOnly- See Also:
-
tagged
protected boolean tagged -
taggingMode
protected int taggingMode -
structureTreeRoot
-
documentOCG
A hashSet containing all the PdfLayer objects. -
documentOCGorder
An array list used to define the order of an OCG tree. -
OCProperties
The OCProperties in a catalog dictionary. -
OCGRadioGroup
The RBGroups array in an OCG dictionary -
OCGLocked
The locked array in an OCG dictionary- Since:
- 2.1.2
-
PAGE_OPEN
action value -
PAGE_CLOSE
action value -
group
A group attributes dictionary specifying the attributes of the page's page group for use in the transparent imaging model -
SPACE_CHAR_RATIO_DEFAULT
public static final float SPACE_CHAR_RATIO_DEFAULTThe default space-char ratio.- See Also:
-
NO_SPACE_CHAR_RATIO
public static final float NO_SPACE_CHAR_RATIODisable the inter-character spacing.- See Also:
-
spaceCharRatio
private float spaceCharRatioThe ratio between the extra word spacing and the extra character spacing. Extra word spacing will growratio
times more than extra character spacing. -
RUN_DIRECTION_DEFAULT
public static final int RUN_DIRECTION_DEFAULTUse the default run direction.- See Also:
-
RUN_DIRECTION_NO_BIDI
public static final int RUN_DIRECTION_NO_BIDIDo not use bidirectional reordering.- See Also:
-
RUN_DIRECTION_LTR
public static final int RUN_DIRECTION_LTRUse bidirectional reordering with left-to-right preferential run direction.- See Also:
-
RUN_DIRECTION_RTL
public static final int RUN_DIRECTION_RTLUse bidirectional reordering with right-to-left preferential run direction.- See Also:
-
runDirection
protected int runDirection -
defaultColorspace
-
documentSpotPatterns
-
patternColorspaceRGB
-
patternColorspaceGRAY
-
patternColorspaceCMYK
-
imageDictionary
Dictionary, containing all the images of the PDF document -
images
This is the list with all the images in the document. -
JBIG2Globals
A HashSet with Stream objects containing JBIG2 Globals- Since:
- 2.1.5
-
userProperties
private boolean userPropertiesA flag indicating the presence of structure elements that contain user properties attributes. -
rgbTransparencyBlending
private boolean rgbTransparencyBlendingHolds value of property RGBTranparency. -
ttfUnicodeWriter
-
standardStructElems_1_4
-
standardStructElems_1_7
-
-
Constructor Details
-
PdfWriter
protected PdfWriter()Constructs aPdfWriter
. -
PdfWriter
Constructs aPdfWriter
.Remark: a PdfWriter can only be constructed by calling the method
getInstance(Document document, OutputStream os)
.- Parameters:
document
- ThePdfDocument
that has to be writtenos
- TheOutputStream
the writer has to write to.
-
-
Method Details
-
getCounter
-
getInstance
Use this method to get an instance of thePdfWriter
.- Parameters:
document
- TheDocument
that has to be writtenos
- TheOutputStream
the writer has to write to.- Returns:
- a new
PdfWriter
- Throws:
DocumentException
- on error
-
getInstance
public static PdfWriter getInstance(Document document, OutputStream os, DocListener listener) throws DocumentException Use this method to get an instance of thePdfWriter
.- Parameters:
document
- TheDocument
that has to be writtenos
- TheOutputStream
the writer has to write to.listener
- ADocListener
to pass to the PdfDocument.- Returns:
- a new
PdfWriter
- Throws:
DocumentException
- on error
-
getPdfDocument
PdfDocument getPdfDocument()Gets thePdfDocument
associated with this writer.- Returns:
- the
PdfDocument
-
getInfo
Use this method to get the info dictionary if you want to change it directly (add keys and values to the info dictionary).- Returns:
- the info dictionary
-
getVerticalPosition
public float getVerticalPosition(boolean ensureNewLine) Use this method to get the current vertical page position.- Parameters:
ensureNewLine
- Tells whether a new line shall be enforced. This may cause side effects for elements that do not terminate the lines they've started because those lines will get terminated.- Returns:
- The current vertical page position.
-
setInitialLeading
Sets the initial leading for the PDF document. This has to be done before the document is opened.- Parameters:
leading
- the initial leading- Throws:
DocumentException
- if you try setting the leading after the document was opened.- Since:
- 2.1.6
-
getDirectContent
Use this method to get the direct content for this document. There is only one direct content, multiple calls to this method will allways retrieve the same object.- Returns:
- the direct content
-
getDirectContentUnder
Use this method to get the direct content under for this document. There is only one direct content, multiple calls to this method will always retrieve the same object.- Returns:
- the direct content
-
resetContent
void resetContent()Resets all the direct contents to empty. This happens when a new page is started. -
getColorProfile
-
addLocalDestinations
Adds the local destinations to the body of the document.- Parameters:
desto
- theHashMap
containing the destinations- Throws:
IOException
- on error
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-inObjStm
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-ref
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref, boolean inObjStm) throws IOException Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-ref
-inObjStm
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-refNumber
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
public PdfIndirectObject addToBody(PdfObject object, int refNumber, boolean inObjStm) throws IOException Use this method to add a PDF object to the PDF body. Use this method only if you know what you're doing!- Parameters:
object
-refNumber
-inObjStm
-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
cacheObject
Use this method for caching objects.- Parameters:
iobj
- @see PdfIndirectObject
-
getPdfIndirectReference
Use this to get anPdfIndirectReference
for an object that will be created in the future. Use this method only if you know what you're doing!- Returns:
- the
PdfIndirectReference
-
getIndirectReferenceNumber
protected int getIndirectReferenceNumber() -
getOs
Returns the outputStreamCounter.- Returns:
- the outputStreamCounter
-
getCatalog
-
buildStructTreeRootForTagged
-
getExtraCatalog
Sets extra keys to the catalog.- Returns:
- the catalog to change
-
addPageDictEntry
Adds an additional entry for the page dictionary.- Parameters:
key
- the keyobject
- the PdfObject for the given key- Since:
- 5.1.0
-
getPageDictEntries
Gets the additional pageDictEntries.- Returns:
- the page dictionary entries
- Since:
- 5.1.0
-
resetPageDictEntries
public void resetPageDictEntries()Resets the additional pageDictEntries.- Since:
- 5.1.0
-
setLinearPageMode
public void setLinearPageMode()Use this method to make sure the page tree has a linear structure (every leave is attached directly to the root). Use this method to allow page reordering with method reorderPages. -
reorderPages
Use this method to reorder the pages in the document. Anull
argument value only returns the number of pages to process. It is advisable to issue aDocument.newPage()
before using this method.- Parameters:
order
- an array with the new page sequence. It must have the same size as the number of pages.- Returns:
- the total number of pages
- Throws:
DocumentException
- if all the pages are not present in the array
-
getPageReference
Use this method to get 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.- Parameters:
page
- the page number. The first page is 1- Returns:
- the reference to the page
-
getPageNumber
public int getPageNumber()Gets the pagenumber of this document. This number can be different from the real pagenumber, if you have (re)set the page number previously.- Returns:
- a page number
-
getCurrentPage
PdfIndirectReference getCurrentPage() -
getCurrentPageNumber
public int getCurrentPageNumber() -
setPageViewport
Sets the Viewport for the next page.- Parameters:
vp
- an array consisting of Viewport dictionaries.- Since:
- 5.1.0
-
setTabs
Sets the value for the Tabs entry in the page tree.- Parameters:
tabs
- Can be PdfName.R, PdfName.C or PdfName.S. Since the Adobe Extensions Level 3, it can also be PdfName.A or PdfName.W- Since:
- 2.1.5
-
getTabs
Returns the value to be used for the Tabs entry in the page tree.- Returns:
- the Tabs PdfName
- Since:
- 2.1.5
-
add
Adds somePdfContents
to this Writer.The document has to be open before you can begin to add content to the body of the document.
- Parameters:
page
- thePdfPage
to addcontents
- thePdfContents
of the page- Returns:
- a
PdfIndirectReference
- Throws:
PdfException
- on error
-
setPageEvent
Sets thePdfPageEvent
for this document.- Parameters:
event
- thePdfPageEvent
for this document
-
getPageEvent
Gets thePdfPageEvent
for this document ornull
if none is set.- Returns:
- the
PdfPageEvent
for this document ornull
if none is set
-
open
public void open()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 classDocWriter
- See Also:
-
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 reference table is composed and everything is written to the outputstream embedded in a Trailer.
- Specified by:
close
in interfaceDocListener
- Overrides:
close
in classDocWriter
- See Also:
-
addXFormsToBody
- Throws:
IOException
-
getRootOutline
Use this method to get the root outline and construct bookmarks.- Returns:
- the root outline
-
setOutlines
Sets the bookmarks. The list structure is defined inSimpleBookmark
.- Parameters:
outlines
- the bookmarks ornull
to remove any
-
writeOutlines
- Throws:
IOException
-
setPdfVersion
public void setPdfVersion(char version) Description copied from interface:PdfVersion
If the PDF Header hasn't been written yet, this changes the version as it will appear in the PDF Header. If the PDF header was already written to the OutputStream, this changes the version as it will appear in the Catalog.- Specified by:
setPdfVersion
in interfacePdfVersion
- Parameters:
version
- a character representing the PDF version- See Also:
-
setAtLeastPdfVersion
public void setAtLeastPdfVersion(char version) Description copied from interface:PdfVersion
If the PDF Header hasn't been written yet, this changes the version as it will appear in the PDF Header, but only if the parameter refers to a higher version. If the PDF header was already written to the OutputStream, this changes the version as it will appear in the Catalog.- Specified by:
setAtLeastPdfVersion
in interfacePdfVersion
- Parameters:
version
- a character representing the PDF version- See Also:
-
setPdfVersion
Description copied from interface:PdfVersion
Sets the PDF version as it will appear in the Catalog. Note that this only has effect if you use a later version than the one that appears in the header. This method ignores the parameter if you try to set a lower version than the one currently set in the Catalog.- Specified by:
setPdfVersion
in interfacePdfVersion
- Parameters:
version
- the PDF name that will be used for the Version key in the catalog- See Also:
-
addDeveloperExtension
Description copied from interface:PdfVersion
Adds a developer extension to the Extensions dictionary in the Catalog.- Specified by:
addDeveloperExtension
in interfacePdfVersion
- Parameters:
de
- an object that contains the extensions prefix and dictionary- Since:
- 2.1.6
- See Also:
-
getPdfVersion
PdfVersionImp getPdfVersion()Returns the version information.- Returns:
- the PdfVersion
-
setViewerPreferences
public void setViewerPreferences(int preferences) Description copied from interface:PdfViewerPreferences
Sets the page layout and page mode preferences by ORing one or two of these constants.- The page layout to be used when the document is opened (choose one).
- PageLayoutSinglePage - Display one page at a time. (default)
- PageLayoutOneColumn - Display the pages in one column.
- PageLayoutTwoColumnLeft - Display the pages in two columns, with odd-numbered pages on the left.
- PageLayoutTwoColumnRight - Display the pages in two columns, with odd-numbered pages on the right.
- PageLayoutTwoPageLeft - Display the pages two at a time, with odd-numbered pages on the left.
- PageLayoutTwoPageRight - Display the pages two at a time, with odd-numbered pages on the right.
- The page mode how the document should be displayed
when opened (choose one).
- PageModeUseNone - Neither document outline nor thumbnail images visible. (default)
- PageModeUseOutlines - Document outline visible.
- PageModeUseThumbs - Thumbnail images visible.
- PageModeFullScreen - Full-screen mode, with no menu bar, window controls, or any other window visible.
- PageModeUseOC - Optional content group panel visible
- PageModeUseAttachments - Attachments panel visible
addViewerPreference(key, value)
if you want to change the following preferences:- HideToolbar - A flag specifying whether to hide the viewer application's tool bars when the document is active.
- HideMenubar - A flag specifying whether to hide the viewer application's menu bar when the document is active.
- HideWindowUI - A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.
- FitWindow - A flag specifying whether to resize the document's window to fit the size of the first displayed page.
- CenterWindow - A flag specifying whether to position the document's window in the center of the screen.
- DisplayDocTitle - A flag specifying whether to display the document's title in the top bar.
- The predominant reading order for text. This entry has no direct effect on the
document's contents or page numbering, but can be used to determine the relative
positioning of pages when displayed side by side or printed n-up (choose one).
- DirectionL2R - Left to right
- DirectionR2L - Right to left (including vertical writing systems such as Chinese, Japanese, and Korean)
- The document's page mode, specifying how to display the
document on exiting full-screen mode. It is meaningful only
if the page mode is PageModeFullScreen (choose one).
- NonFullScreenPageModeUseNone - Neither document outline nor thumbnail images visible
- NonFullScreenPageModeUseOutlines - Document outline visible
- NNonFullScreenPageModeUseThumbs - Thumbnail images visible
- NonFullScreenPageModeUseOC - Optional content group panel visible
- PrintScalingNone - Indicates that the print dialog should reflect no page scaling.
- Specified by:
setViewerPreferences
in interfacePdfViewerPreferences
- Parameters:
preferences
- the viewer preferences- See Also:
- The page layout to be used when the document is opened (choose one).
-
addViewerPreference
Description copied from interface:PdfViewerPreferences
Adds a viewer preference.- In case the key is one of these values:
- PdfName.HIDETOOLBAR
- PdfName.HIDEMENUBAR
- PdfName.HIDEWINDOWUI
- PdfName.FITWINDOW
- PdfName.CENTERWINDOW
- PdfName.DISPLAYDOCTITLE
- In case the key is PdfName.NONFULLSCREENPAGEMODE,
the value must be one of these names:
- PdfName.USENONE
- PdfName.USEOUTLINES
- PdfName.USETHUMBS
- PdfName.USEOC
- In case the key is PdfName.DIRECTION,
the value must be one of these names:
- PdfName.L2R
- PdfName.R2L
- In case the key is one of these values:
- PdfName.VIEWAREA
- PdfName.VIEWCLIP
- PdfName.PRINTAREA
- PdfName.PRINTCLIP
- PdfName.MEDIABOX
- PdfName.CROPBOX
- PdfName.BLEEDBOX
- PdfName.TRIMBOX
- PdfName.ARTBOX
- In case the key is PdfName.PRINTSCALING, the value can be
- PdfName.APPDEFAULT
- PdfName.NONE
- In case the key is PdfName.DUPLEX, the value can be:
- PdfName.SIMPLEX
- PdfName.DUPLEXFLIPSHORTEDGE
- PdfName.DUPLEXFLIPLONGEDGE
- In case the key is PdfName.PICKTRAYBYPDFSIZE, the value must be of type PdfBoolean.
- In case the key is PdfName.PRINTPAGERANGE, the value must be of type PdfArray.
- In case the key is PdfName.NUMCOPIES, the value must be of type PdfNumber.
- Specified by:
addViewerPreference
in interfacePdfViewerPreferences
- Parameters:
key
- the name of the viewer preferencevalue
- the value of the viewer preference- See Also:
- In case the key is one of these values:
-
setPageLabels
Use this method to add page labels- Parameters:
pageLabels
- the page labels
-
addNamedDestinations
Adds named destinations in bulk. Valid keys and values of the map can be found in the map that is created by SimpleNamedDestination.- Parameters:
map
- a map with strings as keys for the names, and structured strings as values for the destinationspage_offset
- number of pages that has to be added to the page numbers in the destinations (useful if you use this method in combination with PdfCopy).- Since:
- iText 5.0
-
addNamedDestination
Adds one named destination.- Parameters:
name
- the name for the destinationpage
- the page number where you want to jump todest
- an explicit destination- Since:
- iText 5.0
-
addJavaScript
Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
js
- The JavaScript action
-
addJavaScript
Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
code
- the JavaScript codeunicode
- select JavaScript unicode. Note that the internal Acrobat JavaScript engine does not support unicode, so this may or may not work for you
-
addJavaScript
Use this method to adds a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
code
- the JavaScript code
-
addJavaScript
Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
name
- The name of the JS Action in the name treejs
- The JavaScript action
-
addJavaScript
Use this method to add a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
name
- The name of the JS Action in the name treecode
- the JavaScript codeunicode
- select JavaScript unicode. Note that the internal Acrobat JavaScript engine does not support unicode, so this may or may not work for you
-
addJavaScript
Use this method to adds a JavaScript action at the document level. When the document opens, all this JavaScript runs.- Parameters:
name
- The name of the JS Action in the name treecode
- the JavaScript code
-
addFileAttachment
public void addFileAttachment(String description, byte[] fileStore, String file, String fileDisplay) throws IOException Use this method to add a file attachment at the document level.- Parameters:
description
- the file descriptionfileStore
- an array with the file. If it'snull
the file will be read from the diskfile
- the path to the file. It will only be used iffileStore
is notnull
fileDisplay
- the actual file name stored in the pdf- Throws:
IOException
- on error
-
addFileAttachment
Use this method to add a file attachment at the document level.- Parameters:
description
- the file descriptionfs
- the file specification- Throws:
IOException
- if the file attachment could not be added to the document
-
addFileAttachment
Use this method to add a file attachment at the document level.- Parameters:
fs
- the file specification- Throws:
IOException
- if the file attachment could not be added to the document
-
setOpenAction
Description copied from interface:PdfDocumentActions
When the document opens it will jump to the destination with this name.- Specified by:
setOpenAction
in interfacePdfDocumentActions
- Parameters:
name
- the name of the destination to jump to- See Also:
-
setOpenAction
Description copied from interface:PdfDocumentActions
When the document opens thisaction
will be invoked.- Specified by:
setOpenAction
in interfacePdfDocumentActions
- Parameters:
action
- the action to be invoked- See Also:
-
setAdditionalAction
Description copied from interface:PdfDocumentActions
Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole. The actions types allowed are:DOCUMENT_CLOSE
,WILL_SAVE
,DID_SAVE
,WILL_PRINT
andDID_PRINT
.- Specified by:
setAdditionalAction
in interfacePdfDocumentActions
- Parameters:
actionType
- the action typeaction
- the action to execute in response to the trigger- Throws:
DocumentException
- on invalid action type- See Also:
-
setCollection
Use this method to add the Collection dictionary.- Parameters:
collection
- a dictionary of type PdfCollection
-
getAcroForm
Description copied from interface:PdfAnnotations
Use this methods to get the AcroForm object. Use this method only if you know what you're doing- Specified by:
getAcroForm
in interfacePdfAnnotations
- Returns:
- the PdfAcroform object of the PdfDocument
- See Also:
-
addAnnotation
Description copied from interface:PdfAnnotations
Use this methods to add aPdfAnnotation
or aPdfFormField
to the document. Only the top parent of aPdfFormField
needs to be added.- Specified by:
addAnnotation
in interfacePdfAnnotations
- Parameters:
annot
- thePdfAnnotation
or thePdfFormField
to add- See Also:
-
addAnnotation
-
addCalculationOrder
Description copied from interface:PdfAnnotations
Use this method to adds thePdfAnnotation
to the calculation order array.- Specified by:
addCalculationOrder
in interfacePdfAnnotations
- Parameters:
annot
- thePdfAnnotation
to be added- See Also:
-
setSigFlags
public void setSigFlags(int f) Description copied from interface:PdfAnnotations
Use this method to set the signature flags.- Specified by:
setSigFlags
in interfacePdfAnnotations
- Parameters:
f
- the flags. This flags are ORed with current ones- See Also:
-
setLanguage
-
setXmpMetadata
public void setXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata.- Parameters:
xmpMetadata
- The xmpMetadata to set.
-
setPageXmpMetadata
Use this method to set the XMP Metadata for each page.- Parameters:
xmpMetadata
- The xmpMetadata to set.- Throws:
IOException
-
getXmpWriter
-
createXmpMetadata
public void createXmpMetadata()Use this method to creates XMP Metadata based on the metadata in the PdfDocument.- Since:
- 5.4.4 just creates XmpWriter instance which will be serialized in close.
-
initPdfIsoConformance
-
setPDFXConformance
public void setPDFXConformance(int pdfx) - See Also:
-
getPDFXConformance
public int getPDFXConformance()- See Also:
-
isPdfX
public boolean isPdfX()- See Also:
-
isPdfIso
public boolean isPdfIso()Checks if any PDF ISO conformance is necessary.- Returns:
true
if the PDF has to be in conformance with any of the PDF ISO specifications
-
setOutputIntents
public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) throws IOException Sets the values of the output intent dictionary. Null values are allowed to suppress any key.- Parameters:
outputConditionIdentifier
- a valueoutputCondition
- a valueregistryName
- a valueinfo
- a valuecolorProfile
- a value- Throws:
IOException
- on error- Since:
- 2.1.5
-
setOutputIntents
public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte[] destOutputProfile) throws IOException Sets the values of the output intent dictionary. Null values are allowed to suppress any key. Prefer theICC_Profile
-based version of this method.- Parameters:
outputConditionIdentifier
- a valueoutputCondition
- a value, "PDFA/A" to force GTS_PDFA1, otherwise cued by pdfxConformance.registryName
- a valueinfo
- a valuedestOutputProfile
- a value- Throws:
IOException
- Since:
- 1.x
-
setOutputIntents
Use this method to copy the output intent dictionary from another document to this one.- Parameters:
reader
- the other documentcheckExistence
-true
to just check for the existence of a valid output intent dictionary,false
to insert the dictionary if it exists- Returns:
true
if the output intent dictionary exists,false
otherwise- Throws:
IOException
- on error
-
getNameString
-
getEncryption
PdfEncryption getEncryption() -
setEncryption
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) throws DocumentException Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Specified by:
setEncryption
in interfacePdfEncryptionSettings
- Parameters:
userPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissionsencryptionType
- can be any of the following: PdfWriter#STANDARD_ENCRYPTION_40, PdfWriter#STANDARD_ENCRYPTION_128, PdfWriter#ENCRYPTION_AES_128 or PdfWriter#ENCRYPTION_AES_256- Throws:
DocumentException
- if the document is already open
-
setEncryption
public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Specified by:
setEncryption
in interfacePdfEncryptionSettings
- Parameters:
certs
- Certificates to encrypt the documentpermissions
- the user permissionsencryptionType
- can be any of the following: PdfWriter#STANDARD_ENCRYPTION_40, PdfWriter#STANDARD_ENCRYPTION_128, PdfWriter#ENCRYPTION_AES_128 or PdfWriter#ENCRYPTION_AES_256- Throws:
DocumentException
- if the document is already open
-
setEncryption
@Deprecated public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
userPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissionsstrength128Bits
-true
for 128 bit key length,false
for 40 bit key length- Throws:
DocumentException
- if the document is already open
-
setEncryption
@Deprecated public void setEncryption(boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
strength
-true
for 128 bit key length,false
for 40 bit key lengthuserPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissions- Throws:
DocumentException
- if the document is already open
-
setEncryption
@Deprecated public void setEncryption(int encryptionType, String userPassword, String ownerPassword, int permissions) throws DocumentException Deprecated.As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0Sets the encryption options for this document. The userPassword and the ownerPassword can be null or have zero length. In this case the ownerPassword is replaced by a random string. The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. The permissions can be combined by ORing them.- Parameters:
encryptionType
- the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartextuserPassword
- the user password. Can be null or emptyownerPassword
- the owner password. Can be null or emptypermissions
- the user permissions- Throws:
DocumentException
- if the document is already open
-
isFullCompression
public boolean isFullCompression()Use this method to find out if 1.5 compression is on.- Returns:
- the 1.5 compression status
-
setFullCompression
Use this method to set the document's compression to the PDF 1.5 mode with object streams and xref streams. It can be set at any time but once set it can't be unset.- Throws:
DocumentException
-
getCompressionLevel
public int getCompressionLevel()Returns the compression level used for streams written by this writer.- Returns:
- the compression level (0 = best speed, 9 = best compression, -1 is default)
- Since:
- 2.1.3
-
setCompressionLevel
public void setCompressionLevel(int compressionLevel) Sets the compression level to be used for streams written by this writer.- Parameters:
compressionLevel
- a value between 0 (best speed) and 9 (best compression)- Since:
- 2.1.3
-
addSimple
Adds aBaseFont
to the document but not to the page resources. It is used for templates.- Parameters:
bf
- theBaseFont
to add- Returns:
- an
Object[]
where position 0 is aPdfName
and position 1 is anPdfIndirectReference
-
eliminateFontSubset
-
addDirectTemplateSimple
Adds a template to the document but not to the page resources.- Parameters:
template
- the template to addforcedName
- the template name, rather than a generated one. Can be null- Returns:
- the
PdfName
for this template
-
releaseTemplate
Use this method to releases the memory used by a template. This method writes the template to the output. The template can still be added to any content but changes to the template itself won't have any effect.- Parameters:
tp
- the template to release- Throws:
IOException
- on error
-
getImportedPage
Use this method to get a page from other PDF document. The page can be used as any other PdfTemplate. Note that calling this method more than once with the same parameters will retrieve the same object.- Parameters:
reader
- the PDF document where the page ispageNumber
- the page number. The first page is 1- Returns:
- the template representing the imported page
-
getPdfReaderInstance
Returns the PdfReaderInstance associated with the specified reader. Multiple calls with the same reader object will return the same PdfReaderInstance.- Parameters:
reader
- the PDF reader that you want an instance for- Returns:
- the instance for the provided reader
- Since:
- 5.0.3
-
freeReader
Use this method to writes the reader to the document and free the memory used by it. The main use is when concatenating multiple documents to keep the memory usage restricted to the current appending document.- Parameters:
reader
- thePdfReader
to free- Throws:
IOException
- on error
-
getCurrentDocumentSize
public long getCurrentDocumentSize()Use this method to gets the current document size. This size only includes the data already written to the output stream, it does not include templates or fonts. It is useful if used withfreeReader()
when concatenating many documents and an idea of the current size is needed.- Returns:
- the approximate size without fonts or templates
-
getNewObjectNumber
-
getReaderFile
-
getColorspaceName
PdfName getColorspaceName() -
addSimple
Adds aSpotColor
to the document but not to the page resources.- Parameters:
spc
- theSpotColor
to add- Returns:
- an
Object[]
where position 0 is aPdfName
and position 1 is anPdfIndirectReference
-
addSimplePattern
-
addSimpleShadingPattern
-
addSimpleShading
-
addSimpleExtGState
-
addSimpleProperty
-
propertyExists
-
setTagged
public void setTagged()Mark this document for tagging. It must be called before open. -
setTagged
public void setTagged(int taggingMode) -
needToBeMarkedInContent
-
checkElementRole
-
isTagged
public boolean isTagged()Check if the document is marked for tagging.- Returns:
true
if the document is marked for tagging
-
flushTaggedObjects
Fix structure of tagged document: remove unused objects, remove unused items from class map, fix xref table due to removed objects.- Throws:
IOException
-
flushAcroFields
- Throws:
IOException
BadPdfFormatException
-
getStructureTreeRoot
Gets the structure tree root. If the document is not marked for tagging it will returnnull
.- Returns:
- the structure tree root
-
getOCProperties
Use this method to get the Optional Content Properties Dictionary. Each call fills the dictionary with the current layer state. It's advisable to only call this method right before close and do any modifications at that time.- Returns:
- the Optional Content Properties Dictionary
-
addOCGRadioGroup
Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm. That is, the state of at most one optional content group in the array should be ON at a time: if one group is turned ON, all others must be turned OFF.- Parameters:
group
- the radio group
-
lockLayer
Use this method to lock an optional content group. The state of a locked group cannot be changed through the user interface of a viewer application. Producers can use this entry to prevent the visibility of content that depends on these groups from being changed by users.- Parameters:
layer
- the layer that needs to be added to the array of locked OCGs- Since:
- 2.1.2
-
getOCGOrder
-
addASEvent
-
fillOCProperties
protected void fillOCProperties(boolean erase) - Parameters:
erase
- true to erase thePdfName.OCGS
andPdfName.D
from the OCProperties first.- Since:
- 2.1.2
-
registerLayer
-
getPageSize
Use this method to get the size of the media box.- Returns:
- a Rectangle
-
setCropBoxSize
Use this method to set the crop box. The crop box should not be rotated even if the page is rotated. This change only takes effect in the next page.- Parameters:
crop
- the crop box
-
setBoxSize
Use this method to set the page box sizes. Allowed names are: "crop", "trim", "art" and "bleed".- Parameters:
boxName
- the box sizesize
- the size
-
getBoxSize
Use this method to get the size of a trim, art, crop or bleed box, or null if not defined.- Parameters:
boxName
- crop, trim, art or bleed
-
getBoxSize
Returns the intersection between the crop, trim art or bleed box and the parameter intersectingRectangle. This method returns null when - there is no intersection - any of the above boxes are not defined - the parameter intersectingRectangle is null- Parameters:
boxName
- crop, trim, art, bleedintersectingRectangle
- the rectangle that intersects the rectangle associated to the boxName- Returns:
- the intersection of the two rectangles
-
setPageEmpty
public void setPageEmpty(boolean pageEmpty) Use this method to make sure a page is added, even if it's empty. If you use setPageEmpty(false), invoking newPage() after a blank page will add a newPage. setPageEmpty(true) won't have any effect.- Parameters:
pageEmpty
- the state
-
isPageEmpty
public boolean isPageEmpty()Checks if a newPage() will actually generate a new page.- Returns:
- true if a new page will be generated, false otherwise
- Since:
- 5.0.0
-
setPageAction
Description copied from interface:PdfPageActions
Sets the open and close page additional action.- Specified by:
setPageAction
in interfacePdfPageActions
- Parameters:
actionType
- the action type. It can bePdfWriter.PAGE_OPEN
orPdfWriter.PAGE_CLOSE
action
- the action to perform- Throws:
DocumentException
- if the action type is invalid- See Also:
-
setDuration
public void setDuration(int seconds) Description copied from interface:PdfPageActions
Sets the display duration for the page (for presentations)- Specified by:
setDuration
in interfacePdfPageActions
- Parameters:
seconds
- the number of seconds to display the page- See Also:
-
setTransition
Description copied from interface:PdfPageActions
Sets the transition for the page- Specified by:
setTransition
in interfacePdfPageActions
- Parameters:
transition
- the Transition object- See Also:
-
setThumbnail
Use this method to set the thumbnail image for the current page.- Parameters:
image
- the image- Throws:
PdfException
- on errorDocumentException
- or error
-
getGroup
Use this method to get the group dictionary.- Returns:
- Value of property group.
-
setGroup
Use this method to set the group dictionary.- Parameters:
group
- New value of property group.
-
getSpaceCharRatio
public float getSpaceCharRatio()Use this method to gets the space/character extra spacing ratio for fully justified text.- Returns:
- the space/character extra spacing ratio
-
setSpaceCharRatio
public void setSpaceCharRatio(float spaceCharRatio) Use this method to set the ratio between the extra word spacing and the extra character spacing when the text is fully justified. Extra word spacing will growspaceCharRatio
times more than extra character spacing. If the ratio isPdfWriter.NO_SPACE_CHAR_RATIO
then the extra character spacing will be zero.- Parameters:
spaceCharRatio
- the ratio between the extra word spacing and the extra character spacing
-
setRunDirection
public void setRunDirection(int runDirection) Use this method to set the run direction. This is only used as a placeholder as it does not affect anything.- Specified by:
setRunDirection
in interfacePdfRunDirection
- Parameters:
runDirection
- the run direction
-
getRunDirection
public int getRunDirection()Use this method to set the run direction.- Specified by:
getRunDirection
in interfacePdfRunDirection
- Returns:
- the run direction
-
setUserunit
Use this method to set the user unit. A UserUnit is a value that defines the default user space unit. The minimum UserUnit is 1 (1 unit = 1/72 inch). The maximum UserUnit is 75,000. Note that this userunit only works starting with PDF1.6!- Parameters:
userunit
- The userunit to set.- Throws:
DocumentException
- on error
-
getDefaultColorspace
Use this method to get the default colorspaces.- Returns:
- the default colorspaces
-
setDefaultColorspace
Use this method to sets the default colorspace that will be applied to all the document. The colorspace is only applied if another colorspace with the same name is not present in the content.The colorspace is applied immediately when creating templates and at the page end for the main document content.
- Parameters:
key
- the name of the colorspace. It can bePdfName.DEFAULTGRAY
,PdfName.DEFAULTRGB
orPdfName.DEFAULTCMYK
cs
- the colorspace. Anull
orPdfNull
removes any colorspace with the same name
-
addSimplePatternColorspace
-
isStrictImageSequence
public boolean isStrictImageSequence()Use this method to get the strictImageSequence status.- Returns:
- value of property strictImageSequence
-
setStrictImageSequence
public void setStrictImageSequence(boolean strictImageSequence) Use this method to set the image sequence, so that it follows the text in strict order (or not).- Parameters:
strictImageSequence
- new value of property strictImageSequence
-
clearTextWrap
Use this method to clear text wrapping around images (if applicable).- Throws:
DocumentException
-
addDirectImageSimple
Use this method to adds an image to the document but not to the page resources. It is used with templates andDocument.add(Image)
. Use this method only if you know what you're doing!- Parameters:
image
- theImage
to add- Returns:
- the name of the image added
- Throws:
PdfException
- on errorDocumentException
- on error
-
addDirectImageSimple
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws PdfException, DocumentException Adds an image to the document but not to the page resources. It is used with templates andDocument.add(Image)
. Use this method only if you know what you're doing!- Parameters:
image
- theImage
to addfixedRef
- the reference to used. It may benull
, aPdfIndirectReference
or aPRIndirectReference
.- Returns:
- the name of the image added
- Throws:
PdfException
- on errorDocumentException
- on error
-
add
Writes aPdfImage
to the outputstream.- Parameters:
pdfImage
- the image to be addedfixedRef
- the IndirectReference, may be null then a new indirect reference is returned- Returns:
- a
PdfIndirectReference
to the encapsulated image - Throws:
PdfException
- when a document isn't open yet, or has been closed
-
getImageReference
return thePdfIndirectReference
to the image with a given name.- Parameters:
name
- the name of the image- Returns:
- a
PdfIndirectReference
-
add
-
getReferenceJBIG2Globals
Gets an indirect reference to a JBIG2 Globals stream. Adds the stream if it hasn't already been added to the writer.- Parameters:
content
- a byte array that may already been added to the writer inside a stream object.- Returns:
- the PdfIndirectReference of the stream
- Since:
- 2.1.5
-
isUserProperties
public boolean isUserProperties()Gets the flag indicating the presence of structure elements that contain user properties attributes.- Returns:
- the user properties flag
-
setUserProperties
public void setUserProperties(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.- Parameters:
userProperties
- the user properties flag
-
isRgbTransparencyBlending
public boolean isRgbTransparencyBlending()Gets the transparency blending colorspace.- Returns:
true
if the transparency blending colorspace is RGB,false
if it is the default blending colorspace- Since:
- 2.1.0
-
setRgbTransparencyBlending
public void setRgbTransparencyBlending(boolean rgbTransparencyBlending) Sets the transparency blending colorspace to RGB. The default blending colorspace is CMYK and will result in faded colors in the screen and in printing. Calling this method will return the RGB colors to what is expected. The RGB blending will be applied to all subsequent pages until other value is set. Note that this is a generic solution that may not work in all cases.- Parameters:
rgbTransparencyBlending
-true
to set the transparency blending colorspace to RGB,false
to use the default blending colorspace- Since:
- 2.1.0
-
writeKeyInfo
- Throws:
IOException
-
getTtfUnicodeWriter
-
createXmpWriter
protected XmpWriter createXmpWriter(ByteArrayOutputStream baos, PdfDictionary info) throws IOException - Throws:
IOException
-
createXmpWriter
protected XmpWriter createXmpWriter(ByteArrayOutputStream baos, HashMap<String, String> info) throws IOException- Throws:
IOException
-
createAnnotation
A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Parameters:
rect
-subtype
-- Returns:
-
createAnnotation
public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype) A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Parameters:
llx
-lly
-urx
-ury
-title
-content
-subtype
-- Returns:
-
createAnnotation
public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype) A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Parameters:
llx
-lly
-urx
-ury
-action
-subtype
-- Returns:
-
checkPdfIsoConformance
-
checkPdfIsoConformance
-
completeInfoDictionary
-
completeExtraCatalog
-
getStandardStructElems
Gets the list of the standard structure element names (roles).- Returns:
-
useExternalCacheForTagStructure
-
ALLOW_ASSEMBLY
instead.