You are on page 1of 21

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.

4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

Overview Package Class Use Tree Deprecated Index Help


PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes DETAIL: FIELD | CONSTR | METHOD

com.itextpdf.text

Class Document
java.lang.Object com.itextpdf.text.Document

All Implemented Interfaces: DocListener, ElementListener, IAccessibleElement, EventListener Direct Known Subclasses: PdfDocument
public class Document extends Object implements DocListener, IAccessibleElement

A generic Document class. All kinds of Text-elements can be added to a HTMLDocument. The Document signals all the listeners hen an element has been added. !emark" %. (. *. .. #nce a document is created $ou can add some meta information. &ou can also set the headers'footers. &ou have to o)en the document before $ou can rite content. &ou can onl$ rite content +no more meta-formation,- once a document is o)ened. 0. /hen $ou change the header'footer on a certain )age, this ill be effective starting on the next )age. 1. After closing the document, ever$ listener +as ell as its OutputStream- is closed too. Exam)le"
// creation of the document with a certain size and certain margins Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { // creation of the different writers HtmlWriter.getInstance(document , System.out); PdfWriter.getInstance(document , new FileOutputStream("text.pdf")); // we add some meta information to the document document.addAuthor("Bruno Lowagie"); document.addSubject("This is the result of a Test."); // we open the document for writing document.open();

% of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

document.add(new Paragraph("Hello world")); } catch(DocumentException de) { System.err.println(de.getMessage()); } document.close();

Field Summary
protected accessibleAttributes HashMap<PdfName,PdfObject> protected int chapternumber

This is a cha)ter number in case 8ha)terAuto9umber is used.


protected boolean close

:as the document alread$ been closed;


static boolean compress

Allo s the )df documents to be )roduced com)ression for debugging )ur)oses.


protected String htmlStyleClass

ithout

<t$le class in :T7L bod$ tag


protected id AccessibleElementId protected String javaScript_onLoad

8ontent of 3ava<cri)t onLoad function


protected String javaScript_onUnLoad

8ontent of 3ava<cri)t on=nLoad function


protected listeners ArrayList<DocListener> protected

The DocListener. margin in $ direction starting from the bottom

float marginBottom

protected

float marginLeft

margin in x direction starting from the left


protected boolean marginMirroring

mirroring of the left'right margins


protected boolean marginMirroringTopBottom

mirroring of the to)'bottom margins


protected float marginRight

margin in x direction starting from the right


protected float marginTop

margin in $ direction starting from the to)


protected boolean open

Is the document o)en or not;


protected int pageN

8urrent )agenumber

( of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

protected

Rectangle pageSize

The si>e of the )age.


static boolean plainRandomAccess

/hen true the file access is not done through a memor$ ma))ed file.
protected PdfName role

static float wmfFontCorrection

<cales the /72 font si>e.

Constructor Summary
Document()

8onstructs a ne 8onstructs a ne

Document

-ob?ect. -ob?ect.

Document(Rectangle pageSize) Document

Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)

8onstructs a ne

Document

-ob?ect.

Method Summary
boolean add(Element element)

Adds an Element to the Document.


boolean addAuthor(String author)

Adds the author to a Document.


boolean addCreationDate()

Adds the current date and time to a Document.


boolean addCreator(String creator)

Adds the creator to a Document.


void addDocListener(DocListener listener)

Adds a DocListener to the Document.


boolean addHeader(String name, String content)

Adds a user defined header to the document.


boolean addKeywords(String keywords)

Adds the ke$ ords to a Document.


boolean addLanguage(String language)

Adds a language to th document.


boolean addProducer()

Adds the )roducer to a Document.


boolean addSubject(String subject)

Adds the sub?ect to a Document.


boolean addTitle(String title)

Adds the title to a Document.

* of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

float bottom()

!eturns the lo er left $-coordinate.


float bottom(float margin)

!eturns the lo er left $-coordinate, considering a given margin.


float bottomMargin()

!eturns the bottom margin.


void close()

8loses the document.


PdfObject getAccessibleAttribute(PdfName key)

@et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-.
HashMap<PdfName,PdfObject> getAccessibleAttributes()

@ets all the )ro)erties of accessible element.


String getHtmlStyleClass()

@ets the st$le class of the :T7L bod$ tag


AccessibleElementId getId()

String getJavaScript_onLoad()

@ets the 3ava<cri)t onLoad command.


String getJavaScript_onUnLoad()

@ets the 3ava<cri)t on=nLoad command.


int getPageNumber()

!eturns the current )age number.


Rectangle getPageSize()

@ets the )agesi>e.


PdfName getRole()

@ets the role of the accessible element.


boolean isInline()

boolean isMarginMirroring()

@ets the margin mirroring flag.


boolean isOpen()

8hecks if the document is o)en.


float left()

!eturns the lo er left x-coordinate.


float left(float margin)

!eturns the lo er left x-coordinate considering a given margin.


float leftMargin()

!eturns the left margin.


boolean newPage()

<ignals that an ne

)age has to be started.

. of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

void open()

#)ens the document.


void removeDocListener(DocListener listener)

!emoves a DocListener from the Document.


void resetPageCount()

<ets the )age number to 4.


float right()

!eturns the u))er right x-coordinate.


float right(float margin)

!eturns the u))er right x-coordinate, considering a given margin.


float rightMargin()

!eturn the right margin.


void setAccessibleAttribute(PdfName key, PdfObject value)

<et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-.
void setHtmlStyleClass(String htmlStyleClass)

Adds a st$le class to the :T7L bod$ tag


void setId(AccessibleElementId id)

void setJavaScript_onLoad(String code)

Adds a 3ava<cri)t onLoad function to the :T7L bod$ tag


void setJavaScript_onUnLoad(String code)

Adds a 3ava<cri)t on=nLoad function to the :T7L bod$ tag


boolean setMarginMirroring(boolean marginMirroring)

<et the margin mirroring.


boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom)

<et the margin mirroring.


boolean setMargins(float marginLeft, float marginRight,

float marginTop, float marginBottom)

<ets the margins.


void setPageCount(int pageN)

<ets the )age number.


boolean setPageSize(Rectangle pageSize)

<ets the )agesi>e.


void setRole(PdfName role)

<ets the role of the accessiblee element.


float top()

!eturns the u))er right $-coordinate.


float top(float margin)

!eturns the u))er right $-coordinate, considering a given margin.

0 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

float topMargin()

!eturns the to) margin. Methods inherited from class a!a.lan".#b ect
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail
compress
public static boolean compress

Allo s the )df documents to be )roduced )ur)oses.

ithout com)ression for debugging

plain$andomAccess
public static boolean plainRandomAccess

/hen true the file access is not done through a memor$ ma))ed file. =se it if the file is too big to be ma))ed in $our address s)ace.

wmfFontCorrection
public static float wmfFontCorrection

<cales the /72 font si>e. The default value is 4.51.

listeners
protected ArrayList<DocListener> listeners

The DocListener. Since: iText 0.%.4 changed from )rivate to )rotected

open
protected boolean open

Is the document o)en or not;

1 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

close
protected boolean close

:as the document alread$ been closed;

pa"eSi%e
protected Rectangle pageSize

The si>e of the )age.

mar"in&eft
protected float marginLeft

margin in x direction starting from the left

mar"in$i"ht
protected float marginRight

margin in x direction starting from the right

mar"in'op
protected float marginTop

margin in $ direction starting from the to)

mar"in(ottom
protected float marginBottom

margin in $ direction starting from the bottom

mar"inMirrorin"
protected boolean marginMirroring

mirroring of the left'right margins

mar"inMirrorin"'op(ottom
B of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

protected boolean marginMirroringTopBottom

mirroring of the to)'bottom margins Since: (.%.1

a!aScript)on&oad
protected String javaScript_onLoad

8ontent of 3ava<cri)t onLoad function

a!aScript)on*n&oad
protected String javaScript_onUnLoad

8ontent of 3ava<cri)t on=nLoad function

htmlStyleClass
protected String htmlStyleClass

<t$le class in :T7L bod$ tag

pa"e+
protected int pageN

8urrent )agenumber

chapternumber
protected int chapternumber

This is a cha)ter number in case 8ha)terAuto9umber is used.

role
protected PdfName role

accessibleAttributes
protected HashMap<PdfName,PdfObject> accessibleAttributes

5 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

id
protected AccessibleElementId id

Constructor Detail
Document
public Document()

8onstructs a ne

Document

-ob?ect.

Document
public Document(Rectangle pageSize)

8onstructs a ne

Document

-ob?ect.

,arameters: pageSize - the )age<i>e

Document
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)

8onstructs a ne

Document

-ob?ect.

,arameters: pageSize - the )age<i>e marginLeft - the margin on the left marginRight - the margin on the right marginTop - the margin on the to) marginBottom - the margin on the bottom

Method Detail
addDoc&istener
public void addDocListener(DocListener listener)

Adds a DocListener to the Document.

6 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

,arameters: listener - the ne

DocListener.

remo!eDoc&istener
public void removeDocListener(DocListener listener)

!emoves a DocListener from the Document. ,arameters: listener - the DocListener that has to be removed.

add
public boolean add(Element element) throws DocumentException

Adds an Element to the Document. Specified by: add in interface ElementListener ,arameters: element - the Element to add $eturns: true if the element as added, false if not 'hrows: DocumentException - hen a document isnCt o)en $et, or has been closed

open
public void open()

#)ens the document. #nce the document is o)ened, $ou canCt rite an$ :eader- or 7eta-information an$more. &ou have to o)en the document before $ou can begin to add content to the bod$ of the document. Specified by: open in interface DocListener

set,a"eSi%e
public boolean setPageSize(Rectangle pageSize)

<ets the )agesi>e.

%4 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

Specified by:
setPageSize

in interface DocListener )agesi>e

,arameters: pageSize - the ne $eturns: a boolean

setMar"ins
public boolean setMargins(float float float float marginLeft, marginRight, marginTop, marginBottom)

<ets the margins. Specified by:


setMargins

in interface DocListener

,arameters: - the margin on the left marginRight - the margin on the right marginTop - the margin on the to) marginBottom - the margin on the bottom $eturns: a boolean
marginLeft

new,a"e
public boolean newPage()

<ignals that an ne

)age has to be started.

Specified by: newPage in interface DocListener $eturns: true if the )age as added, false if not.

reset,a"eCount
public void resetPageCount()

<ets the )age number to 4. Specified by:


resetPageCount

in interface DocListener

%% of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

set,a"eCount
public void setPageCount(int pageN)

<ets the )age number. Specified by:


setPageCount

in interface DocListener )age number

,arameters: pageN - the ne

"et,a"e+umber
public int getPageNumber()

!eturns the current )age number. $eturns: the current )age number

close
public void close()

8loses the document. #nce all the content has been ritten in the bod$, $ou have to close the bod$. After that nothing can be ritten to the bod$ an$more. Specified by: close in interface DocListener

add-eader
public boolean addHeader(String name, String content)

Adds a user defined header to the document. ,arameters: name - the name of the header content - the content of the header $eturns: true if successful, false other ise

add'itle
%( of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

public boolean addTitle(String title)

Adds the title to a Document. ,arameters: title - the title $eturns: true if successful, false other ise

addSub ect
public boolean addSubject(String subject)

Adds the sub?ect to a Document. ,arameters: subject - the sub?ect $eturns: true if successful, false other ise

addKeywords
public boolean addKeywords(String keywords)

Adds the ke$ ords to a Document. ,arameters: keywords - adds the ke$ ords to the document $eturns: true if successful, false other ise

addAuthor
public boolean addAuthor(String author)

Adds the author to a Document. ,arameters: author - the name of the author $eturns: true if successful, false other ise

addCreator
public boolean addCreator(String creator)

%* of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

Adds the creator to a Document. ,arameters: creator - the name of the creator $eturns: true if successful, false other ise

add,roducer
public boolean addProducer()

Adds the )roducer to a Document. $eturns: true if successful, false other ise

add&an"ua"e
public boolean addLanguage(String language)

Adds a language to th document. !eDuired for PD2'=A com)atible documents. ,arameters: language $eturns: true if successfull, false other ise

addCreationDate
public boolean addCreationDate()

Adds the current date and time to a Document. $eturns: true if successful, false other ise

leftMar"in
public float leftMargin()

!eturns the left margin. $eturns: the left margin

%. of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

ri"htMar"in
public float rightMargin()

!eturn the right margin. $eturns: the right margin

topMar"in
public float topMargin()

!eturns the to) margin. $eturns: the to) margin

bottomMar"in
public float bottomMargin()

!eturns the bottom margin. $eturns: the bottom margin

left
public float left()

!eturns the lo er left x-coordinate. $eturns: the lo er left x-coordinate

ri"ht
public float right()

!eturns the u))er right x-coordinate. $eturns: the u))er right x-coordinate

%0 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

top
public float top()

!eturns the u))er right $-coordinate. $eturns: the u))er right $-coordinate

bottom
public float bottom()

!eturns the lo er left $-coordinate. $eturns: the lo er left $-coordinate

left
public float left(float margin)

!eturns the lo er left x-coordinate considering a given margin. ,arameters: margin - a margin $eturns: the lo er left x-coordinate

ri"ht
public float right(float margin)

!eturns the u))er right x-coordinate, considering a given margin. ,arameters: margin - a margin $eturns: the u))er right x-coordinate

top
public float top(float margin)

!eturns the u))er right $-coordinate, considering a given margin.

%1 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

,arameters: margin - a margin $eturns: the u))er right $-coordinate

bottom
public float bottom(float margin)

!eturns the lo er left $-coordinate, considering a given margin. ,arameters: margin - a margin $eturns: the lo er left $-coordinate

"et,a"eSi%e
public Rectangle getPageSize()

@ets the )agesi>e. $eturns: the )age si>e

is#pen
public boolean isOpen()

8hecks if the document is o)en. $eturns: true if the document is o)en

set.a!aScript)on&oad
public void setJavaScript_onLoad(String code)

Adds a 3ava<cri)t onLoad function to the :T7L bod$ tag ,arameters: code - the 3ava<cri)t code to be executed on load of the :T7L )age

"et.a!aScript)on&oad

%B of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

public String getJavaScript_onLoad()

@ets the 3ava<cri)t onLoad command. $eturns: the 3ava<cri)t onLoad command

set.a!aScript)on*n&oad
public void setJavaScript_onUnLoad(String code)

Adds a 3ava<cri)t on=nLoad function to the :T7L bod$ tag ,arameters: code - the 3ava<cri)t code to be executed on unload of the :T7L )age

"et.a!aScript)on*n&oad
public String getJavaScript_onUnLoad()

@ets the 3ava<cri)t on=nLoad command. $eturns: the 3ava<cri)t on=nLoad command

set-tmlStyleClass
public void setHtmlStyleClass(String htmlStyleClass)

Adds a st$le class to the :T7L bod$ tag ,arameters:


htmlStyleClass

- the st$le class for the :T7L bod$ tag

"et-tmlStyleClass
public String getHtmlStyleClass()

@ets the st$le class of the :T7L bod$ tag $eturns: the st$le class of the :T7L bod$ tag

setMar"inMirrorin"
public boolean setMarginMirroring(boolean marginMirroring)

%5 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

<et the margin mirroring. It Specified by:


setMarginMirroring

ill mirror right'left margins for odd'even )ages.

in interface DocListener

,arameters:
marginMirroring

- true to mirror the margins

$eturns: al a$s true

setMar"inMirrorin"'op(ottom
public boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom)

<et the margin mirroring. It Specified by:

ill mirror to)'bottom margins for odd'even )ages.

setMarginMirroringTopBottom

in interface DocListener

,arameters:
marginMirroringTopBottom

- true to mirror the margins

$eturns: al a$s true Since: (.%.1

isMar"inMirrorin"
public boolean isMarginMirroring()

@ets the margin mirroring flag. $eturns: the margin mirroring flag

"etAccessibleAttribute
public PdfObject getAccessibleAttribute(PdfName key)

Description copied from interface: IAccessibleElement @et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-. Specified by:
getAccessibleAttribute

in interface IAccessibleElement

$eturns:

%6 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

setAccessibleAttribute
public void setAccessibleAttribute(PdfName key, PdfObject value)

Description copied from interface: IAccessibleElement <et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-. Specified by:
setAccessibleAttribute

in interface IAccessibleElement

"etAccessibleAttributes
public HashMap<PdfName,PdfObject> getAccessibleAttributes()

Description copied from interface: IAccessibleElement @ets all the )ro)erties of accessible element. Specified by:
getAccessibleAttributes

in interface IAccessibleElement

$eturns:

"et$ole
public PdfName getRole()

Description copied from interface: IAccessibleElement @ets the role of the accessible element. Specified by: getRole in interface IAccessibleElement $eturns:

set$ole
public void setRole(PdfName role)

Description copied from interface: IAccessibleElement <ets the role of the accessiblee element. <et role to null if $ou donCt this element. 9ote that all child elements onCt also be tagged. Specified by: setRole in interface IAccessibleElement

ant to tag

"etId
(4 of (%

('%5'(4%. 5"(6 P7

Document +iText, a 2ree 3ava-PD2 librar$ 0.0.4 API-

htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...

public AccessibleElementId getId()

Specified by: getId in interface IAccessibleElement

setId
public void setId(AccessibleElementId id)

Specified by: setId in interface IAccessibleElement

isInline
public boolean isInline()

Specified by: isInline in interface IAccessibleElement Overview Package Class Use Tree Deprecated Index Help
PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes DETAIL: FIELD | CONSTR | METHOD

8o)$right E (4%.. All !ights !eserved.

(% of (%

('%5'(4%. 5"(6 P7

You might also like