Class DocWriter
- All Implemented Interfaces:
DocListener,ElementListener,EventListener
- Direct Known Subclasses:
PdfWriter
Writer class for documents.
DocWriter is the abstract class of several writers such
as PdfWriter and HtmlWriter.
A DocWriter can be added as a DocListener
to a certain Document by getting an instance (see method
getInstance() in the specific writer-classes).
Every Element added to the original Document
will be written to the OutputStream of the listening
DocWriter.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanCloses the stream on document closeprivate static final byteThis is some byte that is often used.private static final byteThis is some byte that is often used.private static final byteThis is some byte that is often used.protected booleanIs the writer open for writing?protected OutputStreamCounterThe outputstream of this writer.private final booleanDo we have to pause all writing actions?private static final byteThis is some byte that is often used.private static final byteThis is some byte that is often used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedDocWriter(Document document, OutputStream os) Constructs aDocWriter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSignals that anElementwas added to theDocument.voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.static final byte[]getISOBytes(String text) Converts aStringinto aBytearray according to the ISO-8859-1 codepage.booleanChecks if the stream is to be closed on document closebooleanisPaused()Checks if writing is paused.booleannewPage()Signals that an new page has to be started.voidopen()Signals that theDocumentwas opened.voidResets the footer of this document.voidResets the header of this document.voidSets the page number to 0.voidsetCloseStream(boolean closeStream) Sets the close state of the stream after document closevoidsetFooter(HeaderFooter footer) Changes the footer of this document.voidsetHeader(HeaderFooter header) Changes the header of this document.booleansetMarginMirroring(boolean MarginMirroring) Parameter that allows you to do left/right margin mirroring (odd/even pages)booleansetMarginMirroringTopBottom(boolean MarginMirroring) Parameter that allows you to do top/bottom margin mirroring (odd/even pages)booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.voidsetPageCount(int pageN) Sets the page number.booleansetPageSize(Rectangle pageSize) Sets the pagesize.private voidWrites aStringto theOutputStream.private voidWrites a key-value pair to the outputstream.
-
Field Details
-
SPACE
private static final byte SPACEThis is some byte that is often used.- See Also:
-
EQUALS
private static final byte EQUALSThis is some byte that is often used.- See Also:
-
QUOTE
private static final byte QUOTEThis is some byte that is often used.- See Also:
-
GT
private static final byte GTThis is some byte that is often used.- See Also:
-
FORWARD
private static final byte FORWARDThis is some byte that is often used.- See Also:
-
os
The outputstream of this writer. -
open
protected boolean openIs the writer open for writing? -
pause
private final boolean pauseDo we have to pause all writing actions?- See Also:
-
closeStream
private boolean closeStreamCloses the stream on document close
-
-
Constructor Details
-
DocWriter
protected DocWriter() -
DocWriter
Constructs aDocWriter.- Parameters:
document- TheDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.
-
-
Method Details
-
add
Signals that anElementwas added to theDocument.This method should be overridden in the specific
DocWriterclasses derived from this abstract class.- Specified by:
addin interfaceElementListener- Parameters:
element- A high level object to add- Returns:
false- Throws:
DocumentException- when a document isn't open yet, or has been closed
-
open
public void open()Signals that theDocumentwas opened.- Specified by:
openin interfaceDocListener
-
setPageSize
Sets the pagesize.- Specified by:
setPageSizein interfaceDocListener- Parameters:
pageSize- the new pagesize- Returns:
- a
boolean
-
setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.This does nothing. Has to be overridden if needed.
- Specified by:
setMarginsin interfaceDocListener- Parameters:
marginLeft- the margin on the leftmarginRight- the margin on the rightmarginTop- the margin on the topmarginBottom- the margin on the bottom- Returns:
false
-
newPage
public boolean newPage()Signals that an new page has to be started.This does nothing. Has to be overridden if needed.
- Specified by:
newPagein interfaceDocListener- Returns:
trueif the page was added,falseif not.
-
resetHeader
public void resetHeader()Resets the header of this document.This method should be overridden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of headers.- Specified by:
resetHeaderin interfaceDocListener
-
resetPageCount
public void resetPageCount()Sets the page number to 0.This method should be overridden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of pagenumbers.- Specified by:
resetPageCountin interfaceDocListener
-
setPageCount
public void setPageCount(int pageN) Sets the page number.This method should be overridden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of pagenumbers.- Specified by:
setPageCountin interfaceDocListener- Parameters:
pageN- the new page number
-
close
public void close()Signals that theDocumentwas closed and that no otherElementswill be added.- Specified by:
closein interfaceDocListener
-
getISOBytes
Converts aStringinto aBytearray according to the ISO-8859-1 codepage.- Parameters:
text- the text to be converted- Returns:
- the conversion result
-
isPaused
public boolean isPaused()Checks if writing is paused.- Returns:
trueif writing temporarily has to be paused,falseotherwise.
-
write
Writes aStringto theOutputStream.- Parameters:
string- theStringto write- Throws:
IOException- on error
-
write
Writes a key-value pair to the outputstream.- Parameters:
key- the name of an attributevalue- the value of an attribute- Throws:
IOException- on error
-
isCloseStream
public boolean isCloseStream()Checks if the stream is to be closed on document close- Returns:
- true if the stream is closed on document close
-
setCloseStream
public void setCloseStream(boolean closeStream) Sets the close state of the stream after document close- Parameters:
closeStream- true if the stream is closed on document close
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring) Description copied from interface:DocListenerParameter that allows you to do left/right margin mirroring (odd/even pages)- Specified by:
setMarginMirroringin interfaceDocListener- Parameters:
MarginMirroring- Margin- Returns:
- true if successful
- See Also:
-
setMarginMirroringTopBottom
public boolean setMarginMirroringTopBottom(boolean MarginMirroring) Description copied from interface:DocListenerParameter that allows you to do top/bottom margin mirroring (odd/even pages)- Specified by:
setMarginMirroringTopBottomin interfaceDocListener- Parameters:
MarginMirroring- Margin- Returns:
- true if successful
- Since:
- 2.1.6
- See Also:
-