Class PdfWriter
java.lang.Object
com.aowagie.text.DocWriter
com.aowagie.text.pdf.PdfWriter
- All Implemented Interfaces:
DocListener, ElementListener, PdfAnnotations, PdfDocumentActions, PdfEncryptionSettings, PdfPageActions, PdfRunDirection, PdfVersion, PdfViewerPreferences, PdfXConformance, EventListener
- Direct Known Subclasses:
PdfStamperImp
public class PdfWriter
extends DocWriter
implements PdfViewerPreferences, PdfEncryptionSettings, PdfVersion, PdfDocumentActions, PdfPageActions, PdfXConformance, PdfRunDirection, PdfAnnotations
A
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.aowagie.text.pdf.PdfWriter.PdfBodybody of the PDF documentstatic final intA viewer preferenceprotected intThe compression level of the content streams.protected com.aowagie.text.pdf.PdfEncryptionContains the business logic for cryptography.protected com.aowagie.text.pdf.PdfReaderInstancestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected HashSetA hashSet containing all the PdfLayer objects.static final intA viewer preferenceprotected booleanHolds value of property fullCompression.static final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected Liststatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected PdfArrayThe locked array in an OCG dictionaryprotected PdfArrayThe RBGroups array in an OCG dictionaryprotected com.aowagie.text.pdf.PdfOCPropertiesThe OCProperties in a catalog dictionary.static final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected com.aowagie.text.pdf.PdfDocumentthe pdfdocument object.protected PdfVersionImpStores the version information for the header and the catalog.static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final PdfNamepossible PDF version (catalog)static final intPDFA-1A level.static final intPDFA-1B level.static final intPDFA-2A level.static final intPDFA-2B level.static final intA PDF/X level.static final intA PDF/X level.static final intA PDF/X level.protected intA number referring to the previous Cross-Reference Table.static final intA viewer preferenceprotected com.aowagie.text.pdf.PdfPagesThe root of the page tree.static final intUse the default run direction.static final charpossible PDF version (header)static final charpossible PDF version (header)static final charpossible PDF version (header)static final charpossible PDF version (header)static final charpossible PDF version (header)static final charpossible PDF version (header)protected byte[]XMP Metadata for the document. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs aPdfWriter.protectedPdfWriter(com.aowagie.text.pdf.PdfDocument document, OutputStream os) Constructs aPdfWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(PdfAnnotation annot) Use this methods to add aPdfAnnotationor aPdfFormFieldto the document.voidAdds a developer extension to the Extensions dictionary in the Catalog.voidaddFileAttachment(String description, byte[] fileStore, String file, String fileDisplay) Use this method to add a file attachment at the document level.protected voidUse 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.voidaddViewerPreference(PdfName key, PdfObject value) Adds a viewer preference.voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.voidprotected voidfillOCProperties(boolean erase) voidfreeReader(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.protected PdfDictionarygetCatalog(PdfIndirectReference rootObj) intReturns the compression level used for streams written by this writer.intUse this method to gets the current document size.intUse 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.Sets extra keys to the catalog.getGroup()Use this method to get the group dictionary.getImportedPage(PdfReader reader, int pageNumber) Use this method to get a page from other PDF document.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 PdfWritergetInstance(Document document, OutputStream os) Use this method to get an instance of thePdfWriter.protected intgetNewObjectNumber(PdfReader reader, int number, int generation) com.aowagie.text.pdf.PdfOCPropertiesUse this method to get the Optional Content Properties Dictionary.Gets thePdfPageEventfor this document ornullif none is set.intGets 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.Use this to get anPdfIndirectReferencefor an object that will be created in the future.intGetter for the PDF/X Conformance value.protected PdfIndirectReferencegetReferenceJBIG2Globals(byte[] content) Gets an indirect reference to a JBIG2 Globals stream.Use this method to get the root outline and construct bookmarks.intUse this method to set the run direction.floatUse this method to gets the space/character extra spacing ratio for fully justified text.com.aowagie.text.pdf.PdfStructureTreeRootGets the structure tree root.getTabs()Returns the value to be used for the Tabs entry in the page tree.floatUse this method to get the user unit.booleanUse this method to find out if 1.5 compression is on.booleanisPdfX()Checks if the PDF/X Conformance is necessary.booleanGets the transparency blending colorspace.booleanUse this method to get the strictImageSequence status.booleanisTagged()Check if the document is marked for tagging.booleanGets the flag indicating the presence of structure elements that contain user properties attributes.voidopen()Signals that theDocumenthas been opened and thatElementscan be added.voidsetAdditionalAction(PdfName actionType, PdfAction action) voidsetAtLeastPdfVersion(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.voidsetCollection(PdfCollection collection) Use this method to add the Collection dictionary.voidsetCompressionLevel(int compressionLevel) Sets the compression level to be used for streams written by this writer.voidsetCropBoxSize(Rectangle crop) Use this method to set the crop box.voidsetDuration(int seconds) Sets the display duration for the page (for presentations)voidsetEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) Sets the encryption options for this document.voidsetEncryption(Certificate[] certs, int[] permissions, int encryptionType) Sets the certificate encryption options for this document.voidsetGroup(PdfDictionary group) Use this method to set the group dictionary.voidsetInitialLeading(float leading) Sets the initial leading for the PDF document.voidsetOpenAction(PdfAction action) When the document opens thisactionwill be invoked.voidsetOpenAction(String name) When the document opens it will jump to the destination with this name.voidsetOutlines(List outlines) Sets the bookmarks.voidsetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) Sets the values of the output intent dictionary.voidsetPageAction(PdfName actionType, PdfAction action) voidsetPageEmpty(boolean pageEmpty) Use this method to make sure a page is added, even if it's empty.voidsetPageEvent(PdfPageEvent event) Sets thePdfPageEventfor this document.voidsetPageLabels(com.aowagie.text.pdf.PdfPageLabels pageLabels) Use this method to add page labelsvoidsetPageXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata for each page.voidsetPdfVersion(char version) If the PDF Header hasn't been written yet, this changes the version as it will appear in the PDF Header.voidsetPdfVersion(PdfName version) Sets the PDF version as it will appear in the Catalog.voidsetPDFXConformance(int pdfx) Sets the PDF/X conformance level.voidsetRgbTransparencyBlending(boolean rgbTransparencyBlending) Sets the transparency blending colorspace to RGB.voidsetRunDirection(int runDirection) Use this method to set the run direction.voidsetSigFlags(int f) Use this method to set the signature flags.voidsetSpaceCharRatio(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.voidsetStrictImageSequence(boolean strictImageSequence) Use this method to set the image sequence, so that it follows the text in strict order (or not).voidSets the value for the Tabs entry in the page tree.voidMark this document for tagging.voidsetThumbnail(Image image) Use this method to set the thumbnail image for the current page.voidsetTransition(PdfTransition transition) Sets the transition for the pagevoidsetUserProperties(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.voidsetUserunit(float userunit) Use this method to set the user unit.voidsetViewerPreferences(int preferences) Sets the page layout and page mode preferences by ORing one or two of these constants.voidsetXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata.protected voidwriteOutlines(PdfDictionary catalog, boolean namedAsNames) Methods inherited from class DocWriter
add, getISOBytes, isCloseStream, isPaused, newPage, resetFooter, resetHeader, resetPageCount, setCloseStream, setFooter, setHeader, setMarginMirroring, setMarginMirroringTopBottom, setMargins, setPageCount, setPageSize
-
Field Details
-
pdf
protected com.aowagie.text.pdf.PdfDocument pdfthe pdfdocument object. -
body
protected com.aowagie.text.pdf.PdfWriter.PdfBody bodybody of the PDF document -
root
protected com.aowagie.text.pdf.PdfPages rootThe root of the page tree. -
prevxref
protected int prevxrefA number referring to the previous Cross-Reference Table. -
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:
-
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the document. -
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:
-
PDFA1A
public static final int PDFA1APDFA-1A level.- See Also:
-
PDFA1B
public static final int PDFA1BPDFA-1B level.- See Also:
-
PDFA2A
public static final int PDFA2APDFA-2A level.- See Also:
-
PDFA2B
public static final int PDFA2BPDFA-2B level.- See Also:
-
crypto
protected com.aowagie.text.pdf.PdfEncryption cryptoContains 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
-
currentPdfReaderInstance
protected com.aowagie.text.pdf.PdfReaderInstance currentPdfReaderInstance -
documentOCG
A hashSet containing all the PdfLayer objects. -
OCProperties
protected com.aowagie.text.pdf.PdfOCProperties OCPropertiesThe OCProperties in a catalog dictionary. -
OCGRadioGroup
The RBGroups array in an OCG dictionary -
OCGLocked
-
RUN_DIRECTION_DEFAULT
public static final int RUN_DIRECTION_DEFAULTUse the default run direction.- See Also:
-
-
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- ThePdfDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.
-
-
Method Details
-
getInstance
Use this method to get an instance of thePdfWriter.- Parameters:
document- TheDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.- Returns:
- a new
PdfWriter - Throws:
DocumentException- on error
-
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
-
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
-
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- object to addinObjStm- info about inObjStm property- Returns:
- a PdfIndirectObject
- Throws:
IOException- Exception with a IO 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- object to addref- reference to add- Returns:
- a PdfIndirectObject
- Throws:
IOException- Exception with information about a IO error
-
getPdfIndirectReference
Use this to get anPdfIndirectReferencefor an object that will be created in the future. Use this method only if you know what you're doing!- Returns:
- the
PdfIndirectReference
-
getCatalog
-
getExtraCatalog
Sets extra keys to the catalog.- Returns:
- the catalog to change
-
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
-
getCurrentPageNumber
public int getCurrentPageNumber() -
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
- Since:
- 2.1.5
-
setPageEvent
Sets thePdfPageEventfor this document.- Parameters:
event- thePdfPageEventfor this document
-
getPageEvent
Gets thePdfPageEventfor this document ornullif none is set.- Returns:
- the
PdfPageEventfor this document ornullif none is set
-
open
public void open()Signals 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 classDocWriter- See Also:
-
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 reference table is composed and everything is written to the outputstream embedded in a Trailer.
- Specified by:
closein interfaceDocListener- Overrides:
closein classDocWriter- See Also:
-
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 ornullto remove any
-
writeOutlines
- Throws:
IOException
-
setPdfVersion
public void setPdfVersion(char version) Description copied from interface:PdfVersionIf 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:
setPdfVersionin interfacePdfVersion- Parameters:
version- a character representing the PDF version- See Also:
-
setAtLeastPdfVersion
public void setAtLeastPdfVersion(char version) Description copied from interface:PdfVersionIf 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:
setAtLeastPdfVersionin interfacePdfVersion- Parameters:
version- a character representing the PDF version- See Also:
-
setPdfVersion
Description copied from interface:PdfVersionSets 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.- Specified by:
setPdfVersionin interfacePdfVersion- Parameters:
version- the PDF name that will be used for the Version key in the catalog- See Also:
-
addDeveloperExtension
Description copied from interface:PdfVersionAdds a developer extension to the Extensions dictionary in the Catalog.- Specified by:
addDeveloperExtensionin interfacePdfVersion- Parameters:
de- an object that contains the extensions prefix and dictionary- Since:
- 2.1.6
- See Also:
-
setViewerPreferences
public void setViewerPreferences(int preferences) Description copied from interface:PdfViewerPreferencesSets 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).
- PAGE_LAYOUT_SINGLE_PAGE - Display one page at a time. (default)
- PAGE_LAYOUT_ONE_COLUMN - Display the pages in one column.
- PAGE_LAYOUT_TWO_COLUMN_LEFT - Display the pages in two columns, with oddnumbered pages on the left.
- PAGE_LAYOUT_TWO_COLUMN_RIGHT - Display the pages in two columns, with oddnumbered pages on the right.
- PAGE_LAYOUT_TWO_PAGE_LEFT - Display the pages two at a time, with oddnumbered pages on the left.
- PAGE_LAYOUT_TWO_PAGE_RIGHT - Display the pages two at a time, with oddnumbered pages on the right.
- The page mode how the document should be displayed
when opened (choose one).
- PAGE_MODE_USE_NONE - Neither document outline nor thumbnail images visible. (default)
- PAGE_MODE_USE_OUTLINES - Document outline visible.
- PAGE_MODE_USE_THUMBS - Thumbnail images visible.
- PAGE_MODE_FULL_SCREEN - Full-screen mode, with no menu bar, window controls, or any other window visible.
- PAGE_MODE_USE_OC - Optional content group panel visible
- PAGE_MODE_USE_ATTACHMENTS - Attachments panel visible
addViewerPreference(key, value)if you want to change the following preferences:- HIDE_TOOLBAR - A flag specifying whether to hide the viewer application's tool bars when the document is active.
- HIDE_MENUBAR - A flag specifying whether to hide the viewer application's menu bar when the document is active.
- HIDE_WINDOW_UI - 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.
- FIT_WINDOW - A flag specifying whether to resize the document's window to fit the size of the first displayed page.
- CENTER_WINDOW - A flag specifying whether to position the document's window in the center of the screen.
- DISPLAY_DOC_TITLE - 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).
- DIRECTION_L2R - Left to right
- DIRECTION_R2L - 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).
- NON_FULL_SCREEN_PAGE_MODE_USE_NONE - Neither document outline nor thumbnail images visible
- NON_FULL_SCREEN_PAGE_MODE_USE_OUTLINES - Document outline visible
- NON_FULL_SCREEN_PAGE_MODE_USE_THUMBS - Thumbnail images visible
- NON_FULL_SCREEN_PAGE_MODE_USE_OC - Optional content group panel visible
- PRINT_SCALING_NONE - Indicates that the print dialog should reflect no page scaling.
- Specified by:
setViewerPreferencesin 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:PdfViewerPreferencesAdds 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:
addViewerPreferencein 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
public void setPageLabels(com.aowagie.text.pdf.PdfPageLabels pageLabels) Use this method to add page labels- Parameters:
pageLabels- the page labels
-
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'snullthe file will be read from the diskfile- the path to the file. It will only be used iffileStoreis notnullfileDisplay- the actual file name stored in the pdf- Throws:
IOException- on error
-
setOpenAction
Description copied from interface:PdfDocumentActionsWhen the document opens it will jump to the destination with this name.- Specified by:
setOpenActionin interfacePdfDocumentActions- Parameters:
name- the name of the destination to jump to- See Also:
-
setOpenAction
Description copied from interface:PdfDocumentActionsWhen the document opens thisactionwill be invoked.- Specified by:
setOpenActionin interfacePdfDocumentActions- Parameters:
action- the action to be invoked- See Also:
-
setAdditionalAction
- Throws:
DocumentException
-
setCollection
Use this method to add the Collection dictionary.- Parameters:
collection- a dictionary of type PdfCollection
-
getAcroForm
Description copied from interface:PdfAnnotationsUse this methods to get the AcroForm object. Use this method only if you know what you're doing- Specified by:
getAcroFormin interfacePdfAnnotations- Returns:
- the PdfAcroform object of the PdfDocument
- See Also:
-
addAnnotation
Description copied from interface:PdfAnnotationsUse this methods to add aPdfAnnotationor aPdfFormFieldto the document. Only the top parent of aPdfFormFieldneeds to be added.- Specified by:
addAnnotationin interfacePdfAnnotations- Parameters:
annot- thePdfAnnotationor thePdfFormFieldto add- See Also:
-
setSigFlags
public void setSigFlags(int f) Description copied from interface:PdfAnnotationsUse this method to set the signature flags.- Specified by:
setSigFlagsin interfacePdfAnnotations- Parameters:
f- the flags. This flags are ORed with current ones- See Also:
-
setXmpMetadata
public void setXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata.- Parameters:
xmpMetadata- The xmpMetadata to set.
-
setPageXmpMetadata
public void setPageXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata for each page.- Parameters:
xmpMetadata- The xmpMetadata to set.
-
createXmpMetadata
public void createXmpMetadata() -
setPDFXConformance
public void setPDFXConformance(int pdfx) Description copied from interface:PdfXConformanceSets the PDF/X conformance level. Allowed values are PDFX1A2001, PDFX32002, PDFA1A and PDFA1B. It must be called before opening the document.- Specified by:
setPDFXConformancein interfacePdfXConformance- Parameters:
pdfx- the conformance level- See Also:
-
getPDFXConformance
public int getPDFXConformance()Description copied from interface:PdfXConformanceGetter for the PDF/X Conformance value.- Specified by:
getPDFXConformancein interfacePdfXConformance- Returns:
- the pdfxConformance
- See Also:
-
isPdfX
public boolean isPdfX()Description copied from interface:PdfXConformanceChecks if the PDF/X Conformance is necessary.- Specified by:
isPdfXin interfacePdfXConformance- Returns:
- true if the PDF has to be in conformance with any of the PDF/X specifications
- See Also:
-
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 value, "PDFA/A" to force GTS_PDFA1, otherwise cued by pdfxConformance.registryName- a valueinfo- a valuecolorProfile- a value- Throws:
IOException- on error- Since:
- 2.1.5
-
setEncryption
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) throws DocumentException Description copied from interface:PdfEncryptionSettingsSets 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:
setEncryptionin interfacePdfEncryptionSettings- Parameters:
userPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsencryptionType- 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 cleartext- Throws:
DocumentException- if the document is already open- See Also:
-
setEncryption
public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException Description copied from interface:PdfEncryptionSettingsSets the certificate encryption options for this document. An array of one or more public certificates must be provided together with an array of the same size for the permissions for each certificate. 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. Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext- Specified by:
setEncryptionin interfacePdfEncryptionSettings- Parameters:
certs- the public certificates to be used for the encryptionpermissions- the user permissions for each of the certificatesencryptionType- the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.- Throws:
DocumentException- if the document is already open- See Also:
-
isFullCompression
public boolean isFullCompression()Use this method to find out if 1.5 compression is on.- Returns:
- the 1.5 compression status
-
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
-
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
-
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- thePdfReaderto free- Throws:
IOException- on error
-
getCurrentDocumentSize
public int 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
-
setTagged
public void setTagged()Mark this document for tagging. It must be called before open. -
isTagged
public boolean isTagged()Check if the document is marked for tagging.- Returns:
trueif the document is marked for tagging
-
getStructureTreeRoot
public com.aowagie.text.pdf.PdfStructureTreeRoot getStructureTreeRoot()Gets the structure tree root. If the document is not marked for tagging it will returnnull.- Returns:
- the structure tree root
-
getOCProperties
public com.aowagie.text.pdf.PdfOCProperties 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
-
fillOCProperties
protected void fillOCProperties(boolean erase) - Since:
- 2.1.2
-
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
-
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.- Parameters:
pageEmpty- the state
-
setPageAction
- Throws:
DocumentException
-
setDuration
public void setDuration(int seconds) Description copied from interface:PdfPageActionsSets the display duration for the page (for presentations)- Specified by:
setDurationin interfacePdfPageActions- Parameters:
seconds- the number of seconds to display the page- See Also:
-
setTransition
Description copied from interface:PdfPageActionsSets the transition for the page- Specified by:
setTransitionin 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:
com.aowagie.text.pdf.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 growspaceCharRatiotimes more than extra character spacing. If the ratio isPdfWriter.NO_SPACE_CHAR_RATIOthen 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:
setRunDirectionin interfacePdfRunDirection- Parameters:
runDirection- the run direction
-
getRunDirection
public int getRunDirection()Use this method to set the run direction.- Specified by:
getRunDirectionin interfacePdfRunDirection- Returns:
- the run direction
-
getUserunit
public float getUserunit()Use this method to get the user unit. A user unit 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!- Returns:
- Returns the userunit.
-
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
-
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
-
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.- 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:
trueif the transparency blending colorspace is RGB,falseif 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-trueto set the transparency blending colorspace to RGB,falseto use the default blending colorspace- Since:
- 2.1.0
-