Package org.openpdf.text
Class DocWriter
java.lang.Object
org.openpdf.text.DocWriter
- All Implemented Interfaces:
AutoCloseable,EventListener,DocListener,ElementListener
- Direct Known Subclasses:
PdfWriter
An abstract
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 TypeFieldDescriptionprotected booleanCloses the stream on document closeprotected DocumentThis is the document that has to be written.protected booleanIs the writer open for writing?protected OutputStreamCounterThe outputstream of this writer.protected RectangleThe pageSize.protected booleanDo we have to pause all writing actions?static final byteThis is some byte that is often used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDocWriter(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.voidflush()Flushes theBufferedOutputStream.static final byte[]getISOBytes(String text) Converts aStringinto aBytearray according to the ISO-8859-1 codepage.booleanisPaused()Checks if writing is paused.booleannewPage()Signals that an new page has to be started.voidopen()Signals that theDocumentwas opened.booleansetMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) Sets the margins.booleansetPageSize(Rectangle pageSize) Sets the pagesize.
-
Field Details
-
QUOTE
public static final byte QUOTEThis is some byte that is often used.- See Also:
-
pageSize
The pageSize. -
document
This is the document that has to be written. -
os
The outputstream of this writer. -
open
protected boolean openIs the writer open for writing? -
pause
protected boolean pauseDo we have to pause all writing actions? -
closeStream
protected boolean closeStreamCloses the stream on document close
-
-
Constructor Details
-
DocWriter
Constructs aDocWriter.- Parameters:
document- TheDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.
-
-
Method Details
-
getISOBytes
Converts aStringinto aBytearray according to the ISO-8859-1 codepage.- Parameters:
text- the text to be converted- Returns:
- the conversion result
-
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.
-
close
public void close()Signals that theDocumentwas closed and that no otherElementswill be added.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDocListener
-
isPaused
public boolean isPaused()Checks if writing is paused.- Returns:
trueif writing temporarily has to be paused,falseotherwise.
-
flush
public void flush()Flushes theBufferedOutputStream.
-