Professional Documents
Culture Documents
4 API-
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
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
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
Field Summary
protected accessibleAttributes HashMap<PdfName,PdfObject> protected int chapternumber
ithout
float marginBottom
protected
float marginLeft
8urrent )agenumber
( of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
protected
Rectangle pageSize
/hen true the file access is not done through a memor$ ma))ed file.
protected PdfName role
Constructor Summary
Document()
8onstructs a ne 8onstructs a ne
Document
-ob?ect. -ob?ect.
Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
8onstructs a ne
Document
-ob?ect.
Method Summary
boolean add(Element element)
* of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
float bottom()
@et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-.
HashMap<PdfName,PdfObject> getAccessibleAttributes()
String getJavaScript_onLoad()
boolean isMarginMirroring()
<ignals that an ne
. of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
void open()
<et the attribute of accessible element +ever$thing in A dictionar$ A Lang, Alt, ActualText, E-.
void setHtmlStyleClass(String htmlStyleClass)
0 of (%
('%5'(4%. 5"(6 P7
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
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
listeners
protected ArrayList<DocListener> listeners
open
protected boolean open
1 of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
close
protected boolean close
pa"eSi%e
protected Rectangle pageSize
mar"in&eft
protected float marginLeft
mar"in$i"ht
protected float marginRight
mar"in'op
protected float marginTop
mar"in(ottom
protected float marginBottom
mar"inMirrorin"
protected boolean marginMirroring
mar"inMirrorin"'op(ottom
B of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
a!aScript)on&oad
protected String javaScript_onLoad
a!aScript)on*n&oad
protected String javaScript_onUnLoad
htmlStyleClass
protected String htmlStyleClass
pa"e+
protected int pageN
8urrent )agenumber
chapternumber
protected int chapternumber
role
protected PdfName role
accessibleAttributes
protected HashMap<PdfName,PdfObject> accessibleAttributes
5 of (%
('%5'(4%. 5"(6 P7
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.
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)
6 of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
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)
%4 of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
Specified by:
setPageSize
setMar"ins
public boolean setMargins(float float float float marginLeft, marginRight, marginTop, marginBottom)
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
Specified by: newPage in interface DocListener $eturns: true if the )age as added, false if not.
reset,a"eCount
public void resetPageCount()
in interface DocListener
%% of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
set,a"eCount
public void setPageCount(int pageN)
"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
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
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
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()
%. of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
ri"htMar"in
public float rightMargin()
topMar"in
public float topMargin()
bottomMar"in
public float bottomMargin()
left
public float left()
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
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()
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)
%1 of (%
('%5'(4%. 5"(6 P7
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
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()
is#pen
public boolean isOpen()
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
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
@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)
"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
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
in interface DocListener
,arameters:
marginMirroring
setMar"inMirrorin"'op(ottom
public boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom)
setMarginMirroringTopBottom
in interface DocListener
,arameters:
marginMirroringTopBottom
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
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
htt)"''a)i.itext)df.com'itext'com'itext)df'text'Document...
setId
public void setId(AccessibleElementId id)
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
(% of (%
('%5'(4%. 5"(6 P7