public class Document extends Object implements DocListener, IAccessibleElement
All kinds of Text-elements can be added to a HTMLDocument
. The Document
signals all the listeners when an element has been added.
Remark:
OutputStream
) is closed too. // 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(); document.add(new Paragraph("Hello world")); } catch(DocumentException de) { System.err.println(de.getMessage()); } document.close();
Modifier and Type | Field and Description |
---|---|
protected HashMap<PdfName,PdfObject> |
accessibleAttributes |
protected int |
chapternumber
This is a chapter number in case ChapterAutoNumber is used.
|
protected boolean |
close
Has the document already been closed?
|
static boolean |
compress
Allows the pdf documents to be produced without compression for debugging purposes.
|
protected String |
htmlStyleClass
Style class in HTML body tag
|
protected AccessibleElementId |
id |
protected String |
javaScript_onLoad
Content of JavaScript onLoad function
|
protected String |
javaScript_onUnLoad
Content of JavaScript onUnLoad function
|
protected ArrayList<DocListener> |
listeners
The DocListener.
|
protected float |
marginBottom
margin in y direction starting from the bottom
|
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 top/bottom margins
|
protected float |
marginRight
margin in x direction starting from the right
|
protected float |
marginTop
margin in y direction starting from the top
|
protected boolean |
open
Is the document open or not?
|
protected int |
pageN
Current pagenumber
|
protected Rectangle |
pageSize
The size of the page.
|
static boolean |
plainRandomAccess
When true the file access is not done through a memory mapped file.
|
protected PdfName |
role |
static float |
wmfFontCorrection
Scales the WMF font size.
|
Constructor and Description |
---|
Document()
Constructs a new Document -object.
|
Document(Rectangle pageSize)
Constructs a new Document -object.
|
Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Constructs a new Document -object.
|
Modifier and Type | Method and Description |
---|---|
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 keywords to a Document.
|
boolean |
addLanguage(String language)
Adds a language to th document.
|
boolean |
addProducer()
Adds the producer to a Document.
|
boolean |
addSubject(String subject)
Adds the subject to a Document.
|
boolean |
addTitle(String title)
Adds the title to a Document.
|
float |
bottom()
Returns the lower left y-coordinate.
|
float |
bottom(float margin)
Returns the lower left y-coordinate, considering a given margin.
|
float |
bottomMargin()
Returns the bottom margin.
|
void |
close()
Closes the document.
|
PdfObject |
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything in A dictionary + Lang , Alt , ActualText , E ).
|
HashMap<PdfName,PdfObject> |
getAccessibleAttributes()
Gets all the properties of accessible element.
|
String |
getHtmlStyleClass()
Gets the style class of the HTML body tag
|
AccessibleElementId |
getId() |
String |
getJavaScript_onLoad()
Gets the JavaScript onLoad command.
|
String |
getJavaScript_onUnLoad()
Gets the JavaScript onUnLoad command.
|
int |
getPageNumber()
Returns the current page number.
|
Rectangle |
getPageSize()
Gets the pagesize.
|
PdfName |
getRole()
Gets the role of the accessible element.
|
boolean |
isInline() |
boolean |
isMarginMirroring()
Gets the margin mirroring flag.
|
boolean |
isOpen()
Checks if the document is open.
|
float |
left()
Returns the lower left x-coordinate.
|
float |
left(float margin)
Returns the lower left x-coordinate considering a given margin.
|
float |
leftMargin()
Returns the left margin.
|
boolean |
newPage()
Signals that an new page has to be started.
|
void |
open()
Opens the document.
|
void |
removeDocListener(DocListener listener)
Removes a DocListener from the Document .
|
void |
resetPageCount()
Sets the page number to 0.
|
float |
right()
Returns the upper right x-coordinate.
|
float |
right(float margin)
Returns the upper right x-coordinate, considering a given margin.
|
float |
rightMargin()
Return the right margin.
|
void |
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything in A dictionary + Lang , Alt , ActualText , E ).
|
void |
setHtmlStyleClass(String htmlStyleClass)
Adds a style class to the HTML body tag
|
void |
setId(AccessibleElementId id) |
void |
setJavaScript_onLoad(String code)
Adds a JavaScript onLoad function to the HTML body tag
|
void |
setJavaScript_onUnLoad(String code)
Adds a JavaScript onUnLoad function to the HTML body tag
|
boolean |
setMarginMirroring(boolean marginMirroring)
Set the margin mirroring.
|
boolean |
setMarginMirroringTopBottom(boolean marginMirroringTopBottom)
Set the margin mirroring.
|
boolean |
setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
Sets the margins.
|
void |
setPageCount(int pageN)
Sets the page number.
|
boolean |
setPageSize(Rectangle pageSize)
Sets the pagesize.
|
void |
setRole(PdfName role)
Sets the role of the accessiblee element.
|
float |
top()
Returns the upper right y-coordinate.
|
float |
top(float margin)
Returns the upper right y-coordinate, considering a given margin.
|
float |
topMargin()
Returns the top margin.
|
public static boolean compress
public static boolean plainRandomAccess
public static float wmfFontCorrection
protected ArrayList<DocListener> listeners
protected boolean open
protected boolean close
protected Rectangle pageSize
protected float marginLeft
protected float marginRight
protected float marginTop
protected float marginBottom
protected boolean marginMirroring
protected boolean marginMirroringTopBottom
protected String javaScript_onLoad
protected String javaScript_onUnLoad
protected String htmlStyleClass
protected int pageN
protected int chapternumber
protected PdfName role
protected AccessibleElementId id
public Document()
Document
-object.
public Document(Rectangle pageSize)
Document
-object.
pageSize
- the pageSize
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
Document
-object.
pageSize
- the pageSize
marginLeft
- the margin on the left
marginRight
- the margin on the right
marginTop
- the margin on the top
marginBottom
- the margin on the bottom
public void addDocListener(DocListener listener)
DocListener
to the Document
.
listener
- the new DocListener.
public void removeDocListener(DocListener listener)
DocListener
from the Document
.
listener
- the DocListener that has to be removed.
public boolean add(Element element) throws DocumentException
Element
to the Document
.
add
in interface ElementListener
element
- the Element
to add
true
if the element was added, false
if not
DocumentException
- when a document isn't open yet, or has been closed
public void open()
Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.
open
in interface DocListener
public boolean setPageSize(Rectangle pageSize)
setPageSize
in interface DocListener
pageSize
- the new pagesize
boolean
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
setMargins
in interface DocListener
marginLeft
- the margin on the left
marginRight
- the margin on the right
marginTop
- the margin on the top
marginBottom
- the margin on the bottom
boolean
public boolean newPage()
newPage
in interface DocListener
true
if the page was added, false
if not.
public void resetPageCount()
resetPageCount
in interface DocListener
public void setPageCount(int pageN)
setPageCount
in interface DocListener
pageN
- the new page number
public int getPageNumber()
public void close()
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.
close
in interface DocListener
public boolean addHeader(String name, String content)
name
- the name of the header
content
- the content of the header
true
if successful, false
otherwise
public boolean addTitle(String title)
title
- the title
true
if successful, false
otherwise
public boolean addSubject(String subject)
subject
- the subject
true
if successful, false
otherwise
public boolean addKeywords(String keywords)
keywords
- adds the keywords to the document
true
if successful, false
otherwise
public boolean addAuthor(String author)
author
- the name of the author
true
if successful, false
otherwise
public boolean addCreator(String creator)
creator
- the name of the creator
true
if successful, false
otherwise
public boolean addProducer()
true
if successful, false
otherwise
public boolean addLanguage(String language)
language
-
true
if successfull, false
otherwise
public boolean addCreationDate()
true
if successful, false
otherwise
public float leftMargin()
public float rightMargin()
public float topMargin()
public float bottomMargin()
public float left()
public float right()
public float top()
public float bottom()
public float left(float margin)
margin
- a margin
public float right(float margin)
margin
- a margin
public float top(float margin)
margin
- a margin
public float bottom(float margin)
margin
- a margin
public Rectangle getPageSize()
public boolean isOpen()
true
if the document is open
public void setJavaScript_onLoad(String code)
code
- the JavaScript code to be executed on load of the HTML page
public String getJavaScript_onLoad()
public void setJavaScript_onUnLoad(String code)
code
- the JavaScript code to be executed on unload of the HTML page
public String getJavaScript_onUnLoad()
public void setHtmlStyleClass(String htmlStyleClass)
htmlStyleClass
- the style class for the HTML body tag
public String getHtmlStyleClass()
public boolean setMarginMirroring(boolean marginMirroring)
setMarginMirroring
in interface DocListener
marginMirroring
- true
to mirror the margins
true
public boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom)
setMarginMirroringTopBottom
in interface DocListener
marginMirroringTopBottom
- true
to mirror the margins
true
public boolean isMarginMirroring()
public PdfObject getAccessibleAttribute(PdfName key)
IAccessibleElement
A
dictionary + Lang
, Alt
, ActualText
, E
).
getAccessibleAttribute
in interface IAccessibleElement
public void setAccessibleAttribute(PdfName key, PdfObject value)
IAccessibleElement
A
dictionary + Lang
, Alt
, ActualText
, E
).
setAccessibleAttribute
in interface IAccessibleElement
public HashMap<PdfName,PdfObject> getAccessibleAttributes()
IAccessibleElement
getAccessibleAttributes
in interface IAccessibleElement
public PdfName getRole()
IAccessibleElement
getRole
in interface IAccessibleElement
public void setRole(PdfName role)
IAccessibleElement
null
if you don't want to tag this element. Note that all child elements won't also be tagged.
setRole
in interface IAccessibleElement
public AccessibleElementId getId()
getId
in interface IAccessibleElement
public void setId(AccessibleElementId id)
setId
in interface IAccessibleElement
public boolean isInline()
isInline
in interface IAccessibleElement
Copyright © 1998–2022. All rights reserved.