Class PdfWriter
- All Implemented Interfaces:
DocListener, ElementListener, EventListener
- Direct Known Subclasses:
FdfWriter.Wrt, 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 classThis class generates the structure of a PDF document.(package private) static classPdfTraileris the PDF Trailer object. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordstatic final intThe operation permitted when the document is opened with the user passwordprotected PdfWriter.PdfBodybody of the PDF documentstatic final intA viewer preferenceprotected intThe color number counter for the colors in the document.booleanprotected PdfEncryptionprotected intprotected PdfReaderInstanceprotected PdfDictionarystatic final PdfNameaction valuestatic final PdfNameaction valueprivate PdfContentByteThe direct content in this document.private PdfContentByteThe direct content under in this document.static final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intAdd this to the mode to keep the metadata in clear textstatic final PdfNameaction valueprotected HashMapThe colors of this documentprotected HashMapprotected HashMapThe fonts of this documentprotected HashSetprotected ArrayListprotected HashMapThe patterns of this documentprotected HashMapprotected HashMapprotected HashMapprotected HashMapstatic final intAdd this to the mode to keep encrypt only the embedded files.static final intType of encryption(package private) static final intMask to separate the encryption type from the encryption mode.private PdfDictionaryHolds value of property extraCatalog.protected PdfObjectbooleanstatic final intA viewer preferenceprotected intThe font number counter for the fonts in the document.protected HashMapThe form XObjects in this document.protected intThe name counter for the form XObjects name.protected booleanHolds value of property fullCompression.static final intThe highest generation number possible.protected PdfDictionaryprotected byte[]this is the header of a PDF documentstatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected PdfDictionaryDictionary, containing all the images of the PDF documentprotected HashMapstatic final intType of encryptionstatic final floatDisable the inter-character spacing.static final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferencestatic final intA viewer preferenceprotected PdfArrayprotected PdfOCPropertiesstatic final PdfNameaction valuestatic final PdfNameaction valueprivate PdfPageEventThePdfPageEventfor this document.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 ArrayListThe PdfIndirectReference to the pages.protected ColorDetailsprotected ColorDetailsprotected ColorDetailsprotected intThe patten number counter for the colors in the document.private PdfDocumentthe pdfdocument object.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 intPDF/X valuestatic final intPDF/X valueprivate int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final intstatic final intPDF/X valueprotected intstatic final intA viewer preferenceprivate PdfPagesstatic final intUse the default run direction.static final intUse bidirectional reordering with left-to-right preferential run direction.static final intDo not use bidirectional reordering.static final intUse bidirectional reordering with right-to-left preferential run direction.protected intstatic final intsignature valuestatic final intsignature valuestatic final floatThe default space-char ratio.private floatThe ratio between the extra word spacing and the extra character spacing.static final intType of encryptionstatic final intType of encryptionstatic final booleanType of encryptionstatic final booleanType of encryptionprotected PdfStructureTreeRootprotected booleanprotected floatstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF versionstatic final charpossible PDF version(package private) static final intThe mask to decide if a ViewerPreferences dictionary is neededprivate static final intstatic final PdfNameaction valuestatic final PdfNameaction valueprotected byte[]XMP Metadata for the document. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedConstructs aPdfWriter. -
Method Summary
Modifier and TypeMethodDescription(package private) PdfIndirectReferenceadd(PdfPage page, PdfContents contents) Adds somePdfContentsto this Writer.voidaddAnnotation(PdfAnnotation annot) Adds aPdfAnnotationor aPdfFormFieldto the document.(package private) voidaddAnnotation(PdfAnnotation annot, int page) private voidaddASEvent(PdfName event, PdfName category) voidaddCalculationOrder(PdfFormField annot) Adds thePdfAnnotationto the calculation order array.(package private) PdfNameaddDirectTemplateSimple(PdfTemplate template, PdfName forcedName) Adds a template to the document but not to the page resources.voidAdds a JavaScript action at the document level.voidaddJavaScript(String code) Adds a JavaScript action at the document level.voidaddJavaScript(String code, boolean unicode) Adds a JavaScript action at the document level.(package private) voidaddLocalDestinations(TreeMap dest) Adds the local destinations to the body of the document.voidaddOCGRadioGroup(ArrayList group) Sets a collection of optional content groups whose states are intended to follow a "radio button" paradigm.protected void(package private) FontDetailsAdds aBaseFontto the document but not to the page resources.(package private) ColorDetailsaddSimple(PdfSpotColor spc) Adds aSpotColorto the document but not to the page resources.(package private) PdfObject[]addSimpleExtGState(PdfDictionary gstate) (package private) PdfNameaddSimplePattern(PdfPatternPainter painter) (package private) ColorDetailsaddSimplePatternColorspace(Color color) (package private) PdfObject[]addSimpleProperty(Object prop, PdfIndirectReference refi) (package private) voidaddSimpleShading(PdfShading shading) (package private) voidaddSimpleShadingPattern(PdfShadingPattern shading) Adds an object to the PDF body.Adds an object to the PDF body.Adds an object to the PDF body.Adds an object to the PDF body.addToBody(PdfObject object, PdfIndirectReference ref) Adds an object to the PDF body.addToBody(PdfObject object, PdfIndirectReference ref, boolean inObjStm) Adds an object to the PDF body.(package private) static voidcheckPDFXConformance(PdfWriter writer, int key, Object obj1) voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.(package private) voideliminateFontSubset(PdfDictionary fonts) private voidfillOCProperties(boolean erase) voidfreeReader(PdfReader reader) Writes the reader to the document and frees the memory used by it.Gets the AcroForm object.protected PdfDictionarygetCatalog(PdfIndirectReference rootObj) (package private) PdfNameintGets the current document size.(package private) PdfIndirectReference(package private) intGets the default colorspaces.Gets the direct content for this document.Gets the direct content under for this document.(package private) PdfEncryptionSets extra keys to the catalog.Get the pre-set PDF ID; sstewardgetGroup()Getter for property group.(package private) PdfIndirectReferencegetImageReference(PdfName name) return thePdfIndirectReferenceto the image with a given name.getImportedPage(PdfReader reader, int pageNumber) Gets a page from other PDF document.(package private) intgetInfo()Gets the info dictionary for changing.private static StringgetNameString(PdfDictionary dic, PdfName key) protected intgetNewObjectNumber(PdfReader reader, int number, int generation) private static voidgetOCGOrder(PdfArray order, PdfLayer layer) Gets the Optional Content Properties Dictionary.getOs()Returns the outputStreamCounter.Gets thePdfPageEventfor this document ornullif none is set.intGets the current pagenumber of this document.getPageReference(int page) Gets a reference to a page existing or not.Gets thePdfDocumentassociated with this writer.Gets aPdfIndirectReferencefor an object that will be created in the future.intGets the PDFX conformance level.(package private) RandomAccessFileOrArraygetReaderFile(PdfReader reader) getRoot()Gets the root outline.intGets the run direction.floatGets the space/character extra spacing ratio for fully justified text.Gets the structure tree root.floatA UserUnit is a value that defines the default user space unit.floatgetVerticalPosition(boolean ensureNewLine) Gets the current vertical page position.booleanGets the 1.5 compression status.(package private) booleanisPaused()Checks if writing is paused.booleanGetter for property strictImageSequence.booleanisTagged()Check if the document is marked for tagging.voidopen()Signals that theDocumenthas been opened and thatElementscan be added.(package private) booleanpropertyExists(Object prop) (package private) voidregisterLayer(PdfOCG layer) voidReleases the memory used by a template by writing it to the output.intreorderPages(int[] order) Reorder the pages in the document.(package private) voidResets all the direct contents to empty.voidsetAdditionalAction(PdfName actionType, PdfAction action) Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole.voidsetBoxSize(String boxName, Rectangle size) Sets the page box sizes.voidsetCropBoxSize(Rectangle crop) Sets the crop box.voidsetDefaultColorspace(PdfName key, PdfObject cs) Sets the default colorspace that will be applied to all the document.voidsetDuration(int seconds) Sets the display duration for the page (for presentations)voidsetEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) Sets the encryption options for this document.voidsetEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) voidSet the PDF ID; sstewardvoidSets the document's compression to the new 1.5 mode with object streams and xref streams.voidsetGroup(PdfDictionary group) Setter for property group.voidSets the document in a suitable way to do page reordering.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.booleansetOutputIntents(PdfReader reader, boolean checkExistence) Copies the output intent dictionary from other document to this one.voidsetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte[] destOutputProfile) Sets the values of the output intent dictionary.voidsetPageAction(PdfName actionType, PdfAction action) Sets the open and close page additional action.voidsetPageEmpty(boolean pageEmpty) If you use setPageEmpty(false), invoking newPage() after a blank page will add a newPage.voidsetPageEvent(PdfPageEvent pageEvent) Sets thePdfPageEventfor this document.voidsetPageLabels(PdfPageLabels pageLabels) Sets the page labelsvoidsetPdfVersion(char version) Sets the PDF version.voidsetPDFXConformance(int pdfxConformance) Sets the PDFX conformance level.voidsetRunDirection(int runDirection) Sets the run direction.voidsetSigFlags(int f) Set the signature flags.voidsetSpaceCharRatio(float spaceCharRatio) Sets the ratio between the extra word spacing and the extra character spacing when the text is fully justified.voidsetStrictImageSequence(boolean strictImageSequence) Sets the image sequence to follow the text in strict order.voidMark this document for tagging.voidsetTransition(PdfTransition transition) Sets the transition for the pagevoidsetUserunit(float userunit) A UserUnit is a value that defines the default user space unit.voidsetViewerPreferences(int preferences) Sets the viewer preferences by ORing some constants.voidsetXmpMetadata(byte[] xmpMetadata) Sets XMP Metadata.Methods inherited from class DocWriter
add, addTabs, clearTextWrap, flush, getISOBytes, hasMarkupAttributes, isCloseStream, newPage, pause, resetFooter, resetHeader, resetPageCount, resume, setCloseStream, setMarginMirroring, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart
-
Field Details
-
GENERATION_MAX
public static final int GENERATION_MAXThe highest generation number possible.- Since:
- iText 2.1.6
- See Also:
-
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:
-
ViewerPreferencesMask
static final int ViewerPreferencesMaskThe mask to decide if a ViewerPreferences dictionary is needed- See Also:
-
AllowPrinting
public static final int AllowPrintingThe operation permitted when the document is opened with the user password- See Also:
-
AllowModifyContents
public static final int AllowModifyContentsThe operation permitted when the document is opened with the user password- See Also:
-
AllowCopy
public static final int AllowCopyThe operation permitted when the document is opened with the user password- See Also:
-
AllowModifyAnnotations
public static final int AllowModifyAnnotationsThe operation permitted when the document is opened with the user password- See Also:
-
AllowFillIn
public static final int AllowFillInThe operation permitted when the document is opened with the user password- See Also:
-
AllowScreenReaders
public static final int AllowScreenReadersThe operation permitted when the document is opened with the user password- See Also:
-
AllowAssembly
public static final int AllowAssemblyThe operation permitted when the document is opened with the user password- See Also:
-
AllowDegradedPrinting
public static final int AllowDegradedPrintingThe operation permitted when the document is opened with the user password- See Also:
-
STRENGTH40BITS
public static final boolean STRENGTH40BITSType of encryption- See Also:
-
STRENGTH128BITS
public static final boolean STRENGTH128BITSType of encryption- See Also:
-
DOCUMENT_CLOSE
action value -
WILL_SAVE
action value -
DID_SAVE
action value -
WILL_PRINT
action value -
DID_PRINT
action value -
PAGE_OPEN
action value -
PAGE_CLOSE
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:
-
VERSION_1_0
public static final char VERSION_1_0possible PDF version- See Also:
-
VERSION_1_1
public static final char VERSION_1_1possible PDF version- See Also:
-
VERSION_1_2
public static final char VERSION_1_2possible PDF version- See Also:
-
VERSION_1_3
public static final char VERSION_1_3possible PDF version- See Also:
-
VERSION_1_4
public static final char VERSION_1_4possible PDF version- See Also:
-
VERSION_1_5
public static final char VERSION_1_5possible PDF version- See Also:
-
VERSION_1_6
public static final char VERSION_1_6possible PDF version- See Also:
-
VERSION_1_7
public static final char VERSION_1_7possible PDF version- 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) -
VPOINT
private static final int VPOINT- See Also:
-
HEADER
protected byte[] HEADERthis is the header of a PDF document -
prevxref
protected int prevxref -
root
-
imageDictionary
Dictionary, containing all the images of the PDF 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. -
fontNumber
protected int fontNumberThe font number counter for the fonts in the document. -
colorNumber
protected int colorNumberThe color number counter for the colors in the document. -
patternNumber
protected int patternNumberThe patten number counter for the colors in the document. -
directContent
The direct content in this document. -
directContentUnder
The direct content under in this document. -
documentFonts
The fonts of this document -
documentColors
The colors of this document -
documentPatterns
The patterns of this document -
documentShadings
-
documentShadingPatterns
-
patternColorspaceRGB
-
patternColorspaceGRAY
-
patternColorspaceCMYK
-
documentSpotPatterns
-
documentExtGState
-
documentProperties
-
documentOCG
-
documentOCGorder
-
OCProperties
-
OCGRadioGroup
-
defaultColorspace
-
userunit
protected float userunit -
PDFXNONE
public static final int PDFXNONEPDF/X value- See Also:
-
PDFX1A2001
public static final int PDFX1A2001PDF/X value- See Also:
-
PDFX32002
public static final int PDFX32002PDF/X value- See Also:
-
pdfxConformance
private int pdfxConformance -
PDFXKEY_COLOR
static final int PDFXKEY_COLOR- See Also:
-
PDFXKEY_CMYK
static final int PDFXKEY_CMYK- See Also:
-
PDFXKEY_RGB
static final int PDFXKEY_RGB- See Also:
-
PDFXKEY_FONT
static final int PDFXKEY_FONT- See Also:
-
PDFXKEY_IMAGE
static final int PDFXKEY_IMAGE- See Also:
-
PDFXKEY_GSTATE
static final int PDFXKEY_GSTATE- See Also:
-
PDFXKEY_LAYER
static final int PDFXKEY_LAYER- See Also:
-
body
body of the PDF document -
pdf
the pdfdocument object. -
pageEvent
ThePdfPageEventfor this document. -
importedPages
-
currentPdfReaderInstance
-
pageReferences
The PdfIndirectReference to the pages. -
currentPageNumber
protected int currentPageNumber -
group
-
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:
-
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 -
spaceCharRatio
private float spaceCharRatioThe ratio between the extra word spacing and the extra character spacing. Extra word spacing will growratiotimes more than extra character spacing. -
extraCatalog
Holds value of property extraCatalog. -
filterStreams
public boolean filterStreams -
compressStreams
public boolean compressStreams -
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the document. -
fullCompression
protected boolean fullCompressionHolds value of property fullCompression. -
tagged
protected boolean tagged -
fileID
-
structureTreeRoot
-
INVALID_ENCRYPTION
public static final int INVALID_ENCRYPTIONType of encryption- See Also:
-
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_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- See Also:
-
ALLOW_MODIFY_CONTENTS
public static final int ALLOW_MODIFY_CONTENTSThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_COPY
public static final int ALLOW_COPYThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_MODIFY_ANNOTATIONS
public static final int ALLOW_MODIFY_ANNOTATIONSThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_FILL_IN
public static final int ALLOW_FILL_INThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_SCREENREADERS
public static final int ALLOW_SCREENREADERSThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_ASSEMBLY
public static final int ALLOW_ASSEMBLYThe operation permitted when the document is opened with the user password- See Also:
-
ALLOW_DEGRADED_PRINTING
public static final int ALLOW_DEGRADED_PRINTINGThe operation permitted when the document is opened with the user password- See Also:
-
crypto
-
-
Constructor Details
-
PdfWriter
protected PdfWriter() -
PdfWriter
Constructs aPdfWriter.Remark: a PdfWriter can only be constructed by calling the method
getInstance(Document document, OutputStream os).- Parameters:
os- TheOutputStreamthe writer has to write to.document- ThePdfDocumentthat has to be written
-
-
Method Details
-
add
Adds somePdfContentsto this Writer.The document has to be open before you can begin to add content to the body of the document.
- Parameters:
page- thePdfPageto addcontents- thePdfContentsof the page- Returns:
- a
PdfIndirectReference - Throws:
PdfException- on error
-
getImageReference
return thePdfIndirectReferenceto the image with a given name.- Parameters:
name- the name of the image- Returns:
- a
PdfIndirectReference
-
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
-
getOCGOrder
-
addASEvent
-
fillOCProperties
private void fillOCProperties(boolean erase) -
getCatalog
- Throws:
DocumentException
-
close
public void close()Signals that theDocumentwas closed and that no otherElementswill be added.The pages-tree is built and written to the outputstream. A Catalog is constructed, as well as an Info-object, the referencetable is composed and everything is written to the outputstream embedded in a Trailer.
- Specified by:
closein interfaceDocListener- Overrides:
closein classDocWriter
-
getVerticalPosition
public float getVerticalPosition(boolean ensureNewLine) Gets 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.
-
isPaused
boolean isPaused()Checks if writing is paused.- Returns:
trueif writing temporarely has to be paused,falseotherwise.
-
getDirectContent
Gets the direct content for this document. There is only one direct content, multiple calls to this method will allways retrieve the same.- Returns:
- the direct content
-
getDirectContentUnder
Gets the direct content under for this document. There is only one direct content, multiple calls to this method will allways retrieve the same.- Returns:
- the direct content
-
resetContent
void resetContent()Resets all the direct contents to empty. This happens when a new page is started. -
getAcroForm
Gets the AcroForm object.- Returns:
- the
PdfAcroForm - Throws:
DocumentException
-
getRootOutline
-
getOs
Returns the outputStreamCounter.- Returns:
- the outputStreamCounter
-
addSimple
Adds aBaseFontto the document but not to the page resources. It is used for templates.- Parameters:
bf- theBaseFontto add- Returns:
- an
Object[]where position 0 is aPdfNameand position 1 is anPdfIndirectReference
-
eliminateFontSubset
-
getColorspaceName
PdfName getColorspaceName() -
addSimple
Adds aSpotColorto the document but not to the page resources.- Parameters:
spc- theSpotColorto add- Returns:
- an
Object[]where position 0 is aPdfNameand position 1 is anPdfIndirectReference
-
addSimplePatternColorspace
-
addSimpleShadingPattern
-
addSimpleShading
-
addSimpleExtGState
-
registerLayer
-
addSimpleProperty
-
propertyExists
-
getPdfDocument
Gets thePdfDocumentassociated with this writer.- Returns:
- the
PdfDocument
-
getPdfIndirectReference
Gets aPdfIndirectReferencefor an object that will be created in the future.- Returns:
- the
PdfIndirectReference
-
getIndirectReferenceNumber
int getIndirectReferenceNumber() -
addSimplePattern
-
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
PdfNamefor this template
-
setPageEvent
Sets thePdfPageEventfor this document.- Parameters:
pageEvent- thePdfPageEventfor this document
-
getPageEvent
Gets thePdfPageEventfor this document ornullif none is set.- Returns:
- the
PdfPageEventfor this document ornullif none is set
-
addLocalDestinations
Adds the local destinations to the body of the document.- Parameters:
dest- theHashMapcontaining the destinations- Throws:
IOException- on error
-
getPageNumber
public int getPageNumber()Gets the current pagenumber of this document.- Returns:
- a page number
-
setViewerPreferences
public void setViewerPreferences(int preferences) Sets the viewer preferences by ORing some 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 oddnumbered pages on the left.
- PageLayoutTwoColumnRight - Display the pages in two columns, with oddnumbered 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
- 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
- NonFullScreenPageModeUseThumbs - Thumbnail images visible
- NonFullScreenPageModeUseOC - Optional content group panel visible
- PrintScalingNone - Indicates that the print dialog should reflect no page scaling.
- Parameters:
preferences- the viewer preferences
- The page layout to be used when the document is opened (choose one).
-
getEncryption
PdfEncryption getEncryption() -
setEncryption
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) 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.- Parameters:
userPassword- the user password. Can be null or emptyownerPassword- the owner password. Can be null or emptypermissions- the user permissionsstrength128Bits-truefor 128 bit key length,falsefor 40 bit key length- Throws:
DocumentException- if the document is already open
-
setEncryption
public void setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType) throws DocumentException - Throws:
DocumentException
-
addToBody
Adds an object to the PDF body.- Parameters:
object-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Adds an object to the PDF body.- Parameters:
object-inObjStm-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Adds an object to the PDF body.- Parameters:
object-ref-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref, boolean inObjStm) throws IOException Adds an object to the PDF body.- Parameters:
object-ref-inObjStm-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
Adds an object to the PDF body.- Parameters:
object-refNumber-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
addToBody
public PdfIndirectObject addToBody(PdfObject object, int refNumber, boolean inObjStm) throws IOException Adds an object to the PDF body.- Parameters:
object-refNumber-inObjStm-- Returns:
- a PdfIndirectObject
- Throws:
IOException
-
setOpenAction
When the document opens it will jump to the destination with this name.- Parameters:
name- the name of the destination to jump to
-
setAdditionalAction
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_PRINTandDID_PRINT.- Parameters:
actionType- the action typeaction- the action to execute in response to the trigger- Throws:
PdfException- on invalid action type
-
setOpenAction
When the document opens thisactionwill be invoked.- Parameters:
action- the action to be invoked
-
setPageLabels
Sets the page labels- Parameters:
pageLabels- the page labels
-
getReaderFile
- Throws:
IOException
-
getNewObjectNumber
-
getImportedPage
Gets 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
- Throws:
IOException
-
addJavaScript
Adds a JavaScript action at the document level. When the document opens all this JavaScript runs.- Parameters:
js- The JavaScrip action
-
addJavaScript
Adds 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
Adds a JavaScript action at the document level. When the document opens all this JavaScript runs.- Parameters:
code- the JavaScript code
-
setCropBoxSize
Sets 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
-
getPageReference
Gets a reference to a page existing or not. If the page does not exist yet the reference will be created in advance. If on closing the document, a page number greater than the total number of pages was requested, an exception is thrown.- Parameters:
page- the page number. The first page is 1- Returns:
- the reference to the page
-
getCurrentPage
PdfIndirectReference getCurrentPage() -
getCurrentPageNumber
int getCurrentPageNumber() -
addCalculationOrder
Adds thePdfAnnotationto the calculation order array.- Parameters:
annot- thePdfAnnotationto be added- Throws:
DocumentException
-
setSigFlags
Set the signature flags.- Parameters:
f- the flags. This flags are ORed with current ones- Throws:
DocumentException
-
addAnnotation
Adds aPdfAnnotationor aPdfFormFieldto the document. Only the top parent of aPdfFormFieldneeds to be added.- Parameters:
annot- thePdfAnnotationor thePdfFormFieldto add
-
addAnnotation
-
setPdfVersion
public void setPdfVersion(char version) Sets the PDF version. Must be used right before the document is opened. Valid options are VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5 and VERSION_1_6. VERSION_1_4 is the default.- Parameters:
version- the version number
-
reorderPages
Reorder the pages in the document. Anullargument 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
-
getSpaceCharRatio
public float getSpaceCharRatio()Gets the space/character extra spacing ratio for fully justified text.- Returns:
- the space/character extra spacing ratio
-
setSpaceCharRatio
public void setSpaceCharRatio(float spaceCharRatio) Sets 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) Sets the run direction. This is only used as a placeholder as it does not affect anything.- Parameters:
runDirection- the run direction
-
getRunDirection
public int getRunDirection()Gets the run direction.- Returns:
- the run direction
-
setDuration
public void setDuration(int seconds) Sets the display duration for the page (for presentations)- Parameters:
seconds- the number of seconds to display the page
-
setTransition
Sets the transition for the page- Parameters:
transition- the Transition object
-
freeReader
Writes the reader to the document and frees 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
-
setPageAction
Sets the open and close page additional action.- Parameters:
actionType- the action type. It can bePdfWriter.PAGE_OPENorPdfWriter.PAGE_CLOSEaction- the action to perform- Throws:
PdfException- if the action type is invalid
-
getCurrentDocumentSize
public int getCurrentDocumentSize()Gets the current document size. This size only includes the data already writen to the output stream, it does not include templates or fonts. It is usefull if used withfreeReader()when concatenating many documents and an idea of the current size is needed.- Returns:
- the approximate size without fonts or templates
-
isStrictImageSequence
public boolean isStrictImageSequence()Getter for property strictImageSequence.- Returns:
- value of property strictImageSequence
-
setStrictImageSequence
public void setStrictImageSequence(boolean strictImageSequence) Sets the image sequence to follow the text in strict order.- Parameters:
strictImageSequence- new value of property strictImageSequence
-
setPageEmpty
public void setPageEmpty(boolean pageEmpty) If you use setPageEmpty(false), invoking newPage() after a blank page will add a newPage.- Parameters:
pageEmpty- the state
-
getInfo
-
getExtraCatalog
Sets extra keys to the catalog.- Returns:
- the catalog to change
-
setLinearPageMode
public void setLinearPageMode()Sets the document in a suitable way to do page reordering. -
getGroup
-
setGroup
Setter for property group.- Parameters:
group- New value of property group.
-
setPDFXConformance
public void setPDFXConformance(int pdfxConformance) Sets the PDFX conformance level. Allowed values are PDFX1A2001 and PDFX32002. It must be called before opening the document.- Parameters:
pdfxConformance- the conformance level
-
getPDFXConformance
public int getPDFXConformance()Gets the PDFX conformance level.- Returns:
- the PDFX conformance level
-
checkPDFXConformance
-
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.- Parameters:
outputConditionIdentifier- a valueoutputCondition- a valueregistryName- a valueinfo- a valuedestOutputProfile- a value- Throws:
IOException- on error
-
getNameString
-
setOutputIntents
Copies the output intent dictionary from other document to this one.- Parameters:
reader- the other documentcheckExistence-trueto just check for the existence of a valid output intent dictionary,falseto insert the dictionary if it exists- Returns:
trueif the output intent dictionary exists,falseotherwise- Throws:
IOException- on error
-
setBoxSize
-
getDefaultColorspace
Gets the default colorspaces.- Returns:
- the default colorspaces
-
setDefaultColorspace
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.DEFAULTRGBorPdfName.DEFAULTCMYKcs- the colorspace. AnullorPdfNullremoves any colorspace with the same name
-
isFullCompression
public boolean isFullCompression()Gets the 1.5 compression status.- Returns:
trueif the 1.5 compression is on
-
setFullCompression
public void setFullCompression()Sets the document's compression to the new 1.5 mode with object streams and xref streams. It can be set at any time but once set it can't be unset.If set before opening the document it will also set the pdf version to 1.5.
-
getOCProperties
Gets 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
Sets 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
-
getUserunit
public float getUserunit()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. Remark that this userunit only works starting with PDF1.6!- Returns:
- Returns the userunit.
-
setUserunit
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. Remark that this userunit only works starting with PDF1.6!- Parameters:
userunit- The userunit to set.- Throws:
DocumentException
-
setXmpMetadata
public void setXmpMetadata(byte[] xmpMetadata) Sets XMP Metadata.- Parameters:
xmpMetadata- The xmpMetadata to set.
-
releaseTemplate
Releases the memory used by a template by writing it 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
-
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
-
setFileID
Set the PDF ID; ssteward -
getFileID
Get the pre-set PDF ID; ssteward -
getStructureTreeRoot
Gets the structure tree root. If the document is not marked for tagging it will returnnull.- Returns:
- the structure tree root
-
getRoot
-