All kinds of Text-elements can be added to a HTMLDocument.
The Document signals all the listeners when an element has
been added.
Remark:
Once a document is created you can add some meta information.
You can also set the headers/footers.
You have to open the document before you can write content.
You can only write content (no more meta-formation!) once a document is
opened.
When you change the header/footer on a certain page, this will be
effective starting on the next page.
Ater closing the document, every listener (as well as its
OutputStream) is closed too.
Example:
// 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();
Field Summary
protected int
chapternumber This is a chapter number in case ChapterAutoNumber is used.
Constructs a new Document -object.
Parameters: pageSize - the pageSize Parameters: marginLeft - the margin on the left Parameters: marginRight - the margin on the right Parameters: marginTop - the margin on the top Parameters: marginBottom - the margin on the bottom
Adds an Element to the Document.
Parameters: element - the Element to add true if the element was added, false if not throws: DocumentException - when a document isn't open yet, or has been closed
Adds a user defined header to the document.
Parameters: name - the name of the header Parameters: content - the content of the header true if successful, false otherwise
Signals that an new page has to be started.
true if the page was added, falseif not. throws: DocumentException - when a document isn't open yet, or has been closed
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.
Changes the header of this document.
Parameters: header - the new header
setHtmlStyleClass
public void setHtmlStyleClass(String htmlStyleClass)(Code)
Adds a style class to the HTML body tag
Parameters: htmlStyleClass - the style class for the HTML body tag
setJavaScript_onLoad
public void setJavaScript_onLoad(String code)(Code)
Adds a JavaScript onLoad function to the HTML body tag
Parameters: code - the JavaScript code to be executed on load of the HTML page
setJavaScript_onUnLoad
public void setJavaScript_onUnLoad(String code)(Code)
Adds a JavaScript onUnLoad function to the HTML body tag
Parameters: code - the JavaScript code to be executed on unload of the HTML page
setMarginMirroring
public boolean setMarginMirroring(boolean marginMirroring)(Code)
Set the margin mirroring. It will mirror margins for odd/even pages.
Note: it will not work with
Table .
Parameters: marginMirroring - true to mirror the margins always true
setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)(Code)
Sets the margins.
Parameters: marginLeft - the margin on the left Parameters: marginRight - the margin on the right Parameters: marginTop - the margin on the top Parameters: marginBottom - the margin on the bottom a boolean