com.lowagie.text.pdf

Class PdfDocument

class PdfDocument extends Document

PdfDocument is the class that is used by PdfWriter to translate a Document into a PDF with different pages.

A PdfDocument always listens to a Document and adds the Pdf representation of every Element that is added to the Document.

See Also: Document DocListener PdfWriter

Nested Class Summary
static classPdfDocument.Indentation
static classPdfDocument.PdfCatalog
PdfCatalog is the PDF Catalog-object.
static classPdfDocument.PdfInfo
PdfInfo is the PDF InfoDictionary.
static classPdfDocument.RenderingContext
This is a helper class for adding a Table to a document.
Field Summary
PdfDictionaryadditionalActions
intalignment
This represents the current alignment of the PDF Elements.
PdfActionanchorAction
The current active PdfAction when processing an Anchor.
PdfAnnotationsImpannotationsImp
protected HashMapboxSize
This is the size of the several boxes that will be used in the next page.
PdfCollectioncollection
floatcurrentHeight
This is the current height of the document.
PdfOutlinecurrentOutline
This is the current PdfOutline in the hierarchy of outlines.
HashMapdocumentFileAttachment
ArrayListdocumentJavaScript
Stores a list of document level JavaScript actions.
protected intduration
The duration of the page
booleanfirstPageEvent
Signals that OnOpenDocument should be called.
PdfContentBytegraphics
This is the PdfContentByte object, containing the borders and other Graphics.
static StringhangingPunctuation
The characters to be applied the hanging punctuation.
floatimageEnd
This is the position where the image ends.
ImageimageWait
This is the image that could not be shown on a previous page.
PdfDocument.Indentationindentation
PdfDocument.PdfInfoinfo
some meta information about the Document.
booleanisNewpage
booleanisParagraph
Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).
intlastElementType
Holds the type of the last element, that has been added to the document.
floatleading
This represents the leading of the lines.
PdfLineline
The line that is currently being written.
ArrayListlines
The lines that are written until now.
TreeMaplocalDestinations
Stores the destinations keyed by name.
protected intmarkPoint
protected floatnextMarginBottom
margin in y direction starting from the bottom.
protected floatnextMarginLeft
margin in x direction starting from the left.
protected floatnextMarginRight
margin in x direction starting from the right.
protected floatnextMarginTop
margin in y direction starting from the top.
protected RectanglenextPageSize
This is the size of the next page.
PdfActionopenActionAction
StringopenActionName
protected PdfDictionarypageAA
booleanpageEmpty
This checks if the page is empty.
protected PdfPageLabelspageLabels
protected PageResourcespageResources
This are the page resources of the current Page.
PdfOutlinerootOutline
This is the root outline of the document.
booleanstrictImageSequence
Holds value of property strictImageSequence.
PdfContentBytetext
This is the PdfContentByte object, containing the text.
inttextEmptySize
protected HashMapthisBoxSize
This is the size of the several boxes of the current Page.
PdfIndirectReferencethumb
protected PdfTransitiontransition
The page transition
protected PdfViewerPreferencesImpviewerPreferences
Contains the Viewer preferences of this PDF document.
PdfWriterwriter
The PdfWriter.
Constructor Summary
PdfDocument()
Constructs a new PDF document.
Method Summary
booleanadd(Element element)
Signals that an Element was added to the Document.
voidadd(Image image)
Adds an image to the document.
voidadd(PdfTable table, boolean onlyFirstPage)
Adds a new table to the document.
voidaddAdditionalAction(PdfName actionType, PdfAction action)
voidaddAnnotation(PdfAnnotation annot)
voidaddCalculationOrder(PdfFormField formField)
voidaddFileAttachment(String description, PdfFileSpecification fs)
voidaddJavaScript(PdfAction js)
voidaddOutline(PdfOutline outline, String name)
Adds a named outline to the document .
voidaddPTable(PdfPTable ptable)
Adds a PdfPTable to the document.
voidaddSpacing(float extraspace, float oldleading, Font f)
Adds extra space.
voidaddViewerPreference(PdfName key, PdfObject value)
voidaddWriter(PdfWriter writer)
Adds a PdfWriter to the PdfDocument.
voidanalyzeRow(ArrayList rows, PdfDocument.RenderingContext ctx)
floatbottom(Table table)
Returns the bottomvalue of a Table if it were added to this document.
booleanbreakTableIfDoesntFit(PdfTable table)
voidcalculateOutlineCount()
Updates the count in the outlines.
voidcarriageReturn()
If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.
voidclearTextWrap()
Method added by Pelikan Stephan
voidclose()
Closes the document.
voidconsumeRowspan(ArrayList row, PdfDocument.RenderingContext ctx)
voiddoFooter()
voiddoHeader()
voidensureNewLine()
Ensures that a new line has been started.
ArrayListextractRows(ArrayList cells, PdfDocument.RenderingContext ctx)
booleanfitsPage(PdfPTable table, float margin)
Checks if a PdfPTable fits the current page of the PdfDocument.
floatflushLines()
Writes all the lines to the text-object.
PdfAcroFormgetAcroForm()
Gets the AcroForm object.
RectanglegetBoxSize(String boxName)
Gives the size of a trim, art, crop or bleed box, or null if not defined.
PdfDocument.PdfCataloggetCatalog(PdfIndirectReference pages)
Gets the PdfCatalog-object.
HashMapgetDocumentFileAttachment()
ArrayListgetDocumentJavaScript()
PdfDocument.PdfInfogetInfo()
Gets the PdfInfo-object.
PdfActiongetLocalGotoAction(String name)
intgetMarkPoint()
PageResourcesgetPageResources()
PdfTablegetPdfTable(Table table, boolean supportRowAdditions)
Gets a PdfTable object (contributed by dperezcar@fcc.es)
PdfOutlinegetRootOutline()
Gets the root outline.
floatgetVerticalPosition(boolean ensureNewLine)
Gets the current vertical page position.
voidincMarkPoint()
floatindentBottom()
Gets the indentation on the bottom side.
floatindentLeft()
Gets the indentation on the left side.
floatindentRight()
Gets the indentation on the right side.
floatindentTop()
Gets the indentation on the top side.
voidinitPage()
Initializes a page.
booleanisStrictImageSequence()
Getter for property strictImageSequence.
booleanlocalDestination(String name, PdfDestination destination)
The local destination to where a local goto with the same name will jump to.
voidlocalGoto(String name, float llx, float lly, float urx, float ury)
Implements a link to other part of the document.
booleanmayBeRemoved(ArrayList row)
voidnewLine()
Adds the current line to the list of lines and also adds an empty line.
booleannewPage()
Makes a new page and sends it to the PdfWriter.
voidopen()
Opens the document.
voidoutlineTree(PdfOutline outline)
Recursive method used to write outlines.
voidremoteGoto(String filename, String name, float llx, float lly, float urx, float ury)
Implements a link to another document.
voidremoteGoto(String filename, int page, float llx, float lly, float urx, float ury)
Implements a link to another document.
voidrenderCells(PdfDocument.RenderingContext ctx, List cells, boolean hasToFit)
voidresetFooter()
Resets the footer of this document.
voidresetHeader()
Resets the header of this document.
voidresetPageCount()
Sets the page number to 0.
voidsetAction(PdfAction action, float llx, float lly, float urx, float ury)
Implements an action in an area.
voidsetBoxSize(String boxName, Rectangle size)
voidsetCollection(PdfCollection collection)
Sets the collection dictionary.
voidsetCropBoxSize(Rectangle crop)
voidsetDuration(int seconds)
Sets the display duration for the page (for presentations)
voidsetFooter(HeaderFooter footer)
Changes the footer of this document.
voidsetHeader(HeaderFooter header)
Changes the header of this document.
booleansetMarginMirroring(boolean MarginMirroring)
booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.
voidsetOpenAction(String name)
voidsetOpenAction(PdfAction action)
voidsetPageAction(PdfName actionType, PdfAction action)
voidsetPageCount(int pageN)
Sets the page number.
voidsetPageEmpty(boolean pageEmpty)
voidsetPageLabels(PdfPageLabels pageLabels)
Sets the page labels
booleansetPageSize(Rectangle pageSize)
Sets the pagesize.
voidsetSigFlags(int f)
voidsetStrictImageSequence(boolean strictImageSequence)
Setter for property strictImageSequence.
voidsetThumbnail(Image image)
voidsetTransition(PdfTransition transition)
Sets the transition for the page
voidsetViewerPreferences(int preferences)
voidtraverseOutlineCount(PdfOutline outline)
Recursive method to update the count in the outlines.
voidwriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
Writes a text line to the document.
voidwriteOutlines()
Writes the outline tree to the body of the PDF document.

Field Detail

additionalActions

private PdfDictionary additionalActions

alignment

private int alignment
This represents the current alignment of the PDF Elements.

anchorAction

private PdfAction anchorAction
The current active PdfAction when processing an Anchor.

annotationsImp

PdfAnnotationsImp annotationsImp

boxSize

protected HashMap boxSize
This is the size of the several boxes that will be used in the next page.

collection

private PdfCollection collection

currentHeight

private float currentHeight
This is the current height of the document.

currentOutline

private PdfOutline currentOutline
This is the current PdfOutline in the hierarchy of outlines.

documentFileAttachment

private HashMap documentFileAttachment

documentJavaScript

private ArrayList documentJavaScript
Stores a list of document level JavaScript actions.

duration

protected int duration
The duration of the page

firstPageEvent

private boolean firstPageEvent
Signals that OnOpenDocument should be called.

graphics

private PdfContentByte graphics
This is the PdfContentByte object, containing the borders and other Graphics.

hangingPunctuation

static final String hangingPunctuation
The characters to be applied the hanging punctuation.

imageEnd

private float imageEnd
This is the position where the image ends.

imageWait

private Image imageWait
This is the image that could not be shown on a previous page.

indentation

PdfDocument.Indentation indentation

info

private PdfDocument.PdfInfo info
some meta information about the Document.

isNewpage

private boolean isNewpage

isParagraph

private boolean isParagraph
Signals that onParagraph is valid (to avoid that a Chapter/Section title is treated as a Paragraph).

lastElementType

private int lastElementType
Holds the type of the last element, that has been added to the document.

leading

private float leading
This represents the leading of the lines.

line

private PdfLine line
The line that is currently being written.

lines

private ArrayList lines
The lines that are written until now.

localDestinations

private TreeMap localDestinations
Stores the destinations keyed by name. Value is Object[]{PdfAction,PdfIndirectReference,PdfDestintion}.

markPoint

protected int markPoint

nextMarginBottom

protected float nextMarginBottom
margin in y direction starting from the bottom. Will be valid in the next page

nextMarginLeft

protected float nextMarginLeft
margin in x direction starting from the left. Will be valid in the next page

nextMarginRight

protected float nextMarginRight
margin in x direction starting from the right. Will be valid in the next page

nextMarginTop

protected float nextMarginTop
margin in y direction starting from the top. Will be valid in the next page

nextPageSize

protected Rectangle nextPageSize
This is the size of the next page.

openActionAction

private PdfAction openActionAction

openActionName

private String openActionName

pageAA

protected PdfDictionary pageAA

pageEmpty

private boolean pageEmpty
This checks if the page is empty.

pageLabels

protected PdfPageLabels pageLabels

pageResources

protected PageResources pageResources
This are the page resources of the current Page.

rootOutline

private PdfOutline rootOutline
This is the root outline of the document.

strictImageSequence

private boolean strictImageSequence
Holds value of property strictImageSequence.

text

private PdfContentByte text
This is the PdfContentByte object, containing the text.

textEmptySize

private int textEmptySize

thisBoxSize

protected HashMap thisBoxSize
This is the size of the several boxes of the current Page.

thumb

private PdfIndirectReference thumb

transition

protected PdfTransition transition
The page transition

viewerPreferences

protected PdfViewerPreferencesImp viewerPreferences
Contains the Viewer preferences of this PDF document.

writer

private PdfWriter writer
The PdfWriter.

Constructor Detail

PdfDocument

public PdfDocument()
Constructs a new PDF document.

Throws: DocumentException on error

Method Detail

add

public boolean add(Element element)
Signals that an Element was added to the Document.

Parameters: element the element to add

Returns: true if the element was added, false if not.

Throws: DocumentException when a document isn't open yet, or has been closed

add

private void add(Image image)
Adds an image to the document.

Parameters: image the Image to add

Throws: PdfException on error DocumentException on error

add

private void add(PdfTable table, boolean onlyFirstPage)
Adds a new table to the document.

Parameters: table Table to add. Rendered rows will be deleted after processing. onlyFirstPage Render only the first full page

Throws: DocumentException

addAdditionalAction

void addAdditionalAction(PdfName actionType, PdfAction action)

addAnnotation

void addAnnotation(PdfAnnotation annot)

addCalculationOrder

void addCalculationOrder(PdfFormField formField)

addFileAttachment

void addFileAttachment(String description, PdfFileSpecification fs)

addJavaScript

void addJavaScript(PdfAction js)

addOutline

void addOutline(PdfOutline outline, String name)
Adds a named outline to the document .

Parameters: outline the outline to be added name the name of this local destination

addPTable

void addPTable(PdfPTable ptable)
Adds a PdfPTable to the document.

Parameters: ptable the PdfPTable to be added to the document.

Throws: DocumentException on error

addSpacing

private void addSpacing(float extraspace, float oldleading, Font f)
Adds extra space. This method should probably be rewritten.

addViewerPreference

void addViewerPreference(PdfName key, PdfObject value)

See Also: PdfViewerPreferences

addWriter

public void addWriter(PdfWriter writer)
Adds a PdfWriter to the PdfDocument.

Parameters: writer the PdfWriter that writes everything what is added to this document to an outputstream.

Throws: DocumentException on error

analyzeRow

private void analyzeRow(ArrayList rows, PdfDocument.RenderingContext ctx)

bottom

float bottom(Table table)

Deprecated:

Returns the bottomvalue of a Table if it were added to this document.

Parameters: table the table that may or may not be added to this document

Returns: a bottom value

breakTableIfDoesntFit

boolean breakTableIfDoesntFit(PdfTable table)

Deprecated:

Parameters: table Table to add

Returns: true if the table will be broken

Throws: DocumentException

See Also: (contributed by dperezcar@fcc.es)

calculateOutlineCount

void calculateOutlineCount()
Updates the count in the outlines.

carriageReturn

private void carriageReturn()
If the current line is not empty or null, it is added to the arraylist of lines and a new empty line is added.

Throws: DocumentException on error

clearTextWrap

public void clearTextWrap()
Method added by Pelikan Stephan

close

public void close()
Closes the document. Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.

consumeRowspan

private void consumeRowspan(ArrayList row, PdfDocument.RenderingContext ctx)

doFooter

private void doFooter()

doHeader

private void doHeader()

ensureNewLine

private void ensureNewLine()
Ensures that a new line has been started.

extractRows

private ArrayList extractRows(ArrayList cells, PdfDocument.RenderingContext ctx)

fitsPage

boolean fitsPage(PdfPTable table, float margin)
Checks if a PdfPTable fits the current page of the PdfDocument.

Parameters: table the table that has to be checked margin a certain margin

Returns: true if the PdfPTable fits the page, false otherwise.

flushLines

private float flushLines()
Writes all the lines to the text-object.

Returns: the displacement that was caused

Throws: DocumentException on error

getAcroForm

PdfAcroForm getAcroForm()
Gets the AcroForm object.

Returns: the PdfAcroform object of the PdfDocument

getBoxSize

Rectangle getBoxSize(String boxName)
Gives the size of a trim, art, crop or bleed box, or null if not defined.

Parameters: boxName crop, trim, art or bleed

getCatalog

PdfDocument.PdfCatalog getCatalog(PdfIndirectReference pages)
Gets the PdfCatalog-object.

Parameters: pages an indirect reference to this document pages

Returns: PdfCatalog

getDocumentFileAttachment

HashMap getDocumentFileAttachment()

getDocumentJavaScript

ArrayList getDocumentJavaScript()

getInfo

PdfDocument.PdfInfo getInfo()
Gets the PdfInfo-object.

Returns: PdfInfo

getLocalGotoAction

PdfAction getLocalGotoAction(String name)

getMarkPoint

int getMarkPoint()

getPageResources

PageResources getPageResources()

getPdfTable

PdfTable getPdfTable(Table table, boolean supportRowAdditions)
Gets a PdfTable object (contributed by dperezcar@fcc.es)

Parameters: table a high level table object supportRowAdditions

Returns: returns a PdfTable object

See Also: getPdfTable

getRootOutline

public PdfOutline getRootOutline()
Gets the root outline. All the outlines must be created with a parent. The first level is created with this outline.

Returns: the root outline

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.

incMarkPoint

void incMarkPoint()

indentBottom

float indentBottom()
Gets the indentation on the bottom side.

Returns: a margin

indentLeft

private float indentLeft()
Gets the indentation on the left side.

Returns: a margin

indentRight

private float indentRight()
Gets the indentation on the right side.

Returns: a margin

indentTop

private float indentTop()
Gets the indentation on the top side.

Returns: a margin

initPage

private void initPage()
Initializes a page.

If the footer/header is set, it is printed.

Throws: DocumentException on error

isStrictImageSequence

boolean isStrictImageSequence()
Getter for property strictImageSequence.

Returns: Value of property strictImageSequence.

localDestination

boolean localDestination(String name, PdfDestination destination)
The local destination to where a local goto with the same name will jump to.

Parameters: name the name of this local destination destination the PdfDestination with the jump coordinates

Returns: true if the local destination was added, false if a local destination with the same name already existed

localGoto

void localGoto(String name, float llx, float lly, float urx, float ury)
Implements a link to other part of the document. The jump will be made to a local destination with the same name, that must exist.

Parameters: name the name for this link llx the lower left x corner of the activation area lly the lower left y corner of the activation area urx the upper right x corner of the activation area ury the upper right y corner of the activation area

mayBeRemoved

private boolean mayBeRemoved(ArrayList row)

newLine

private void newLine()
Adds the current line to the list of lines and also adds an empty line.

Throws: DocumentException on error

newPage

public boolean newPage()
Makes a new page and sends it to the PdfWriter.

Returns: a boolean

Throws: DocumentException on error

open

public void open()
Opens the document.

You have to open the document before you can begin to add content to the body of the document.

outlineTree

void outlineTree(PdfOutline outline)
Recursive method used to write outlines.

remoteGoto

void remoteGoto(String filename, String name, float llx, float lly, float urx, float ury)
Implements a link to another document.

Parameters: filename the filename for the remote document name the name to jump to llx the lower left x corner of the activation area lly the lower left y corner of the activation area urx the upper right x corner of the activation area ury the upper right y corner of the activation area

remoteGoto

void remoteGoto(String filename, int page, float llx, float lly, float urx, float ury)
Implements a link to another document.

Parameters: filename the filename for the remote document page the page to jump to llx the lower left x corner of the activation area lly the lower left y corner of the activation area urx the upper right x corner of the activation area ury the upper right y corner of the activation area

renderCells

private void renderCells(PdfDocument.RenderingContext ctx, List cells, boolean hasToFit)

resetFooter

public void resetFooter()
Resets the footer of this document.

resetHeader

public void resetHeader()
Resets the header of this document.

resetPageCount

public void resetPageCount()
Sets the page number to 0.

setAction

void setAction(PdfAction action, float llx, float lly, float urx, float ury)
Implements an action in an area.

Parameters: action the PdfAction llx the lower left x corner of the activation area lly the lower left y corner of the activation area urx the upper right x corner of the activation area ury the upper right y corner of the activation area

setBoxSize

void setBoxSize(String boxName, Rectangle size)

setCollection

public void setCollection(PdfCollection collection)
Sets the collection dictionary.

Parameters: collection a dictionary of type PdfCollection

setCropBoxSize

void setCropBoxSize(Rectangle crop)

setDuration

void setDuration(int seconds)
Sets the display duration for the page (for presentations)

Parameters: seconds the number of seconds to display the page

setFooter

public void setFooter(HeaderFooter footer)
Changes the footer of this document.

Parameters: footer the new footer

setHeader

public void setHeader(HeaderFooter header)
Changes the header of this document.

Parameters: header the new header

setMarginMirroring

public boolean setMarginMirroring(boolean MarginMirroring)

See Also: DocListener

setMargins

public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.

Parameters: marginLeft the margin on the left marginRight the margin on the right marginTop the margin on the top marginBottom the margin on the bottom

Returns: a boolean

setOpenAction

void setOpenAction(String name)

setOpenAction

void setOpenAction(PdfAction action)

setPageAction

void setPageAction(PdfName actionType, PdfAction action)

setPageCount

public void setPageCount(int pageN)
Sets the page number.

Parameters: pageN the new page number

setPageEmpty

void setPageEmpty(boolean pageEmpty)

setPageLabels

void setPageLabels(PdfPageLabels pageLabels)
Sets the page labels

Parameters: pageLabels the page labels

setPageSize

public boolean setPageSize(Rectangle pageSize)
Sets the pagesize.

Parameters: pageSize the new pagesize

Returns: true if the page size was set

setSigFlags

void setSigFlags(int f)

setStrictImageSequence

void setStrictImageSequence(boolean strictImageSequence)
Setter for property strictImageSequence.

Parameters: strictImageSequence New value of property strictImageSequence.

setThumbnail

void setThumbnail(Image image)

setTransition

void setTransition(PdfTransition transition)
Sets the transition for the page

Parameters: transition the PdfTransition object

setViewerPreferences

void setViewerPreferences(int preferences)

traverseOutlineCount

void traverseOutlineCount(PdfOutline outline)
Recursive method to update the count in the outlines.

writeLineToContent

void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
Writes a text line to the document. It takes care of all the attributes.

Before entering the line position must have been established and the text argument must be in text object scope (beginText()).

Parameters: line the line to be written text the PdfContentByte where the text will be written to graphics the PdfContentByte where the graphics will be written to currentValues the current font and extra spacing values ratio

Throws: DocumentException on error

writeOutlines

void writeOutlines()
Writes the outline tree to the body of the PDF document.