- java.lang.Object
-
- com.itextpdf.text.DocWriter
-
- All Implemented Interfaces:
DocListener,ElementListener,java.util.EventListener
- Direct Known Subclasses:
HtmlWriter,PdfWriter
public abstract class DocWriter extends java.lang.Object implements DocListener
An abstractWriterclass for documents.DocWriteris the abstract class of several writers such asPdfWriterandHtmlWriter. ADocWritercan be added as aDocListenerto a certainDocumentby getting an instance (see methodgetInstance()in the specific writer-classes). EveryElementadded to the originalDocumentwill be written to theOutputStreamof the listeningDocWriter.- See Also:
Document,DocListener
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancloseStreamCloses the stream on document closeprotected DocumentdocumentThis is the document that has to be written.static byteEQUALSThis is some byte that is often used.static byteFORWARDThis is some byte that is often used.static byteGTThis is some byte that is often used.static byteLTThis is some byte that is often used.static byteNEWLINEThis is some byte that is often used.protected booleanopenIs the writer open for writing?protected OutputStreamCounterosThe outputstream of this writer.protected RectanglepageSizeThe pageSize.protected booleanpauseDo we have to pause all writing actions?static byteQUOTEThis is some byte that is often used.static byteSPACEThis is some byte that is often used.static byteTABThis is some byte that is often used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Element element)Signals that anElementwas added to theDocument.protected voidaddTabs(int indent)Writes a number of tabs.voidclose()Signals that theDocumentwas closed and that no otherElementswill be added.voidflush()Flushes theBufferedOutputStream.static byte[]getISOBytes(java.lang.String text)Converts aStringinto aBytearray according to the ISO-8859-1 codepage.booleanisCloseStream()Checks 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.voidpause()Let the writer know that all writing has to be paused.voidresetFooter()Resets the footer of this document.voidresetHeader()Resets the header of this document.voidresetPageCount()Sets the page number to 0.voidresume()Let the writer know that writing may be resumed.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.protected voidwrite(java.lang.String string)Writes aStringto theOutputStream.protected voidwrite(java.lang.String key, java.lang.String value)Writes a key-value pair to the outputstream.protected voidwriteEnd()Writes an endtag to the outputstream.protected voidwriteEnd(java.lang.String tag)Writes an endtag to the outputstream.protected booleanwriteMarkupAttributes(java.util.Properties markup)Writes the markup attributes of the specifiedMarkupAttributesobject to theOutputStream.protected voidwriteStart(java.lang.String tag)Writes a starttag to the outputstream.
-
-
-
Field Detail
-
NEWLINE
public static final byte NEWLINE
This is some byte that is often used.- See Also:
- Constant Field Values
-
TAB
public static final byte TAB
This is some byte that is often used.- See Also:
- Constant Field Values
-
LT
public static final byte LT
This is some byte that is often used.- See Also:
- Constant Field Values
-
SPACE
public static final byte SPACE
This is some byte that is often used.- See Also:
- Constant Field Values
-
EQUALS
public static final byte EQUALS
This is some byte that is often used.- See Also:
- Constant Field Values
-
QUOTE
public static final byte QUOTE
This is some byte that is often used.- See Also:
- Constant Field Values
-
GT
public static final byte GT
This is some byte that is often used.- See Also:
- Constant Field Values
-
FORWARD
public static final byte FORWARD
This is some byte that is often used.- See Also:
- Constant Field Values
-
pageSize
protected Rectangle pageSize
The pageSize.
-
document
protected Document document
This is the document that has to be written.
-
os
protected OutputStreamCounter os
The outputstream of this writer.
-
open
protected boolean open
Is the writer open for writing?
-
pause
protected boolean pause
Do we have to pause all writing actions?
-
closeStream
protected boolean closeStream
Closes the stream on document close
-
-
Constructor Detail
-
DocWriter
protected DocWriter()
-
DocWriter
protected DocWriter(Document document, java.io.OutputStream os)
Constructs aDocWriter.- Parameters:
document- TheDocumentthat has to be writtenos- TheOutputStreamthe writer has to write to.
-
-
Method Detail
-
add
public boolean add(Element element) throws DocumentException
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
public boolean setPageSize(Rectangle pageSize)
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.
-
setHeader
public void setHeader(HeaderFooter header)
Changes 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:
setHeaderin interfaceDocListener- Parameters:
header- the new header
-
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
-
setFooter
public void setFooter(HeaderFooter footer)
Changes the footer of this document.This method should be overridden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of footers.- Specified by:
setFooterin interfaceDocListener- Parameters:
footer- the new footer
-
resetFooter
public void resetFooter()
Resets the footer of this document.This method should be overridden in the specific
DocWriterclasses derived from this abstract class if they actually support the use of footers.- Specified by:
resetFooterin 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
public static final byte[] getISOBytes(java.lang.String text)
Converts aStringinto aBytearray according to the ISO-8859-1 codepage.- Parameters:
text- the text to be converted- Returns:
- the conversion result
-
pause
public void pause()
Let the writer know that all writing has to be paused.
-
isPaused
public boolean isPaused()
Checks if writing is paused.- Returns:
trueif writing temporarily has to be paused,falseotherwise.
-
resume
public void resume()
Let the writer know that writing may be resumed.
-
flush
public void flush()
Flushes theBufferedOutputStream.
-
write
protected void write(java.lang.String string) throws java.io.IOExceptionWrites aStringto theOutputStream.- Parameters:
string- theStringto write- Throws:
java.io.IOException
-
addTabs
protected void addTabs(int indent) throws java.io.IOExceptionWrites a number of tabs.- Parameters:
indent- the number of tabs to add- Throws:
java.io.IOException
-
write
protected void write(java.lang.String key, java.lang.String value) throws java.io.IOExceptionWrites a key-value pair to the outputstream.- Parameters:
key- the name of an attributevalue- the value of an attribute- Throws:
java.io.IOException
-
writeStart
protected void writeStart(java.lang.String tag) throws java.io.IOExceptionWrites a starttag to the outputstream.- Parameters:
tag- the name of the tag- Throws:
java.io.IOException
-
writeEnd
protected void writeEnd(java.lang.String tag) throws java.io.IOExceptionWrites an endtag to the outputstream.- Parameters:
tag- the name of the tag- Throws:
java.io.IOException
-
writeEnd
protected void writeEnd() throws java.io.IOExceptionWrites an endtag to the outputstream.- Throws:
java.io.IOException
-
writeMarkupAttributes
protected boolean writeMarkupAttributes(java.util.Properties markup) throws java.io.IOExceptionWrites the markup attributes of the specifiedMarkupAttributesobject to theOutputStream.- Parameters:
markup- aPropertiescollection to write.- Returns:
- true, if writing the markup attributes succeeded
- Throws:
java.io.IOException
-
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- Returns:
- true if successful
- See Also:
DocListener.setMarginMirroring(boolean)
-
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- Returns:
- true if successful
- Since:
- 2.1.6
- See Also:
DocListener.setMarginMirroring(boolean)
-
-