Class DocWriter
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.DocWriter
-
- All Implemented Interfaces:
DocListener
,ElementListener
,java.util.EventListener
- Direct Known Subclasses:
PdfWriter
public abstract class DocWriter extends java.lang.Object implements DocListener
An abstractWriter
class for documents.DocWriter
is the abstract class of several writers such asPdfWriter
andHtmlWriter
. ADocWriter
can be added as aDocListener
to a certainDocument
by getting an instance (see methodgetInstance()
in the specific writer-classes). EveryElement
added to the originalDocument
will be written to theOutputStream
of the listeningDocWriter
.- See Also:
Document
,DocListener
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
closeStream
Closes the stream on document closestatic byte
EQUALS
This is some byte that is often used.static byte
FORWARD
This is some byte that is often used.static byte
GT
This is some byte that is often used.static byte
LT
This is some byte that is often used.protected boolean
m_pause
Do we have to pause all writing actions?static byte
NEWLINE
This is some byte that is often used.boolean
open
Is the writer open for writing?OutputStreamCounter
os
The outputstream of this writer.protected Rectangle
pageSize
The pageSize.static byte
QUOTE
This is some byte that is often used.static byte
SPACE
This is some byte that is often used.static byte
TAB
This is some byte that is often used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Element element)
Signals that anElement
was added to theDocument
.protected void
addTabs(int indent)
Writes a number of tabs.void
clearTextWrap()
Clears text wrapping around images (if applicable).void
close()
Signals that theDocument
was closed and that no otherElements
will be added.void
flush()
Flushes theBufferedOutputStream
.static byte[]
getISOBytes(java.lang.String text)
Converts aString
into aByte
array according to the ISO-8859-1 codepage.protected static boolean
hasMarkupAttributes(Element element)
Returnstrue
if the specifiedElement
implementsMarkupAttributes
and has one or more attributes to write.boolean
isCloseStream()
Checks if the stream is to be closed on document closeboolean
newPage()
Signals that an new page has to be started.void
open()
Signals that theDocument
was opened.void
pause()
Let the writer know that all writing has to be paused.void
resetFooter()
Resets the footer of this document.void
resetHeader()
Resets the header of this document.void
resetPageCount()
Sets the page number to 0.void
resume()
Let the writer know that writing may be resumed.void
setCloseStream(boolean closeStream)
Sets the close state of the stream after document closeboolean
setMarginMirroring(boolean MarginMirroring)
Parameter that allows you to do margin mirroring (odd/even pages)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.protected void
write(java.lang.String string)
Writes aString
to theOutputStream
.protected void
write(java.lang.String key, java.lang.String value)
Writes a key-value pair to the outputstream.protected void
writeEnd()
Writes an endtag to the outputstream.protected void
writeEnd(java.lang.String tag)
Writes an endtag to the outputstream.protected boolean
writeMarkupAttributes(MarkupAttributes mAtt)
Writes the markup attributes of the specifiedMarkupAttributes
object to theOutputStream
.protected void
writeStart(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.
-
os
public OutputStreamCounter os
The outputstream of this writer.
-
open
public boolean open
Is the writer open for writing?
-
m_pause
protected boolean m_pause
Do we have to pause all writing actions?
-
closeStream
protected boolean closeStream
Closes the stream on document close
-
-
Method Detail
-
add
public boolean add(Element element) throws DocumentException
Signals that anElement
was added to theDocument
.This method should be overriden in the specific
DocWriter
classes derived from this abstract class.
- Specified by:
add
in 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 theDocument
was opened.- Specified by:
open
in interfaceDocListener
-
setPageSize
public boolean setPageSize(Rectangle pageSize)
Sets the pagesize.- Specified by:
setPageSize
in 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:
setMargins
in 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() throws DocumentException
Signals that an new page has to be started.This does nothing. Has to be overridden if needed.
- Specified by:
newPage
in interfaceDocListener
- Returns:
true
if the page was added,false
if not.- Throws:
DocumentException
- when a document isn't open yet, or has been closed
-
resetHeader
public void resetHeader()
Resets the header of this document.This method should be overriden in the specific
DocWriter
classes derived from this abstract class if they actually support the use of headers.
-
resetFooter
public void resetFooter()
Resets the footer of this document.This method should be overriden in the specific
DocWriter
classes derived from this abstract class if they actually support the use of footers.
-
resetPageCount
public void resetPageCount()
Sets the page number to 0.This method should be overriden in the specific
DocWriter
classes derived from this abstract class if they actually support the use of pagenumbers.
- Specified by:
resetPageCount
in interfaceDocListener
-
setPageCount
public void setPageCount(int pageN)
Sets the page number.This method should be overriden in the specific
DocWriter
classes derived from this abstract class if they actually support the use of pagenumbers.
- Specified by:
setPageCount
in interfaceDocListener
- Parameters:
pageN
- the new page number
-
close
public void close()
Signals that theDocument
was closed and that no otherElements
will be added.- Specified by:
close
in interfaceDocListener
-
getISOBytes
public static final byte[] getISOBytes(java.lang.String text)
Converts aString
into aByte
array 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.
-
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.IOException
Writes aString
to theOutputStream
.- Parameters:
string
- theString
to write- Throws:
java.io.IOException
-
addTabs
protected void addTabs(int indent) throws java.io.IOException
Writes 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.IOException
Writes 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.IOException
Writes 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.IOException
Writes an endtag to the outputstream.- Parameters:
tag
- the name of the tag- Throws:
java.io.IOException
-
writeEnd
protected void writeEnd() throws java.io.IOException
Writes an endtag to the outputstream.- Throws:
java.io.IOException
-
writeMarkupAttributes
protected boolean writeMarkupAttributes(MarkupAttributes mAtt) throws java.io.IOException
Writes the markup attributes of the specifiedMarkupAttributes
object to theOutputStream
.- Parameters:
mAtt
- theMarkupAttributes
to write.- Returns:
- true, if writing the markup attributes succeeded
- Throws:
java.io.IOException
-
hasMarkupAttributes
protected static boolean hasMarkupAttributes(Element element)
Returnstrue
if the specifiedElement
implementsMarkupAttributes
and has one or more attributes to write.- Parameters:
element
- theElement
to check.- Returns:
boolean
.
-
isCloseStream
public boolean isCloseStream()
Checks if the stream is to be closed on document close- Returns:
- true if the stream is closed on documnt 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
-
clearTextWrap
public void clearTextWrap() throws DocumentException
Description copied from interface:DocListener
Clears text wrapping around images (if applicable). Method suggested by Pelikan Stephan- Specified by:
clearTextWrap
in interfaceDocListener
- Throws:
DocumentException
- See Also:
DocListener.clearTextWrap()
-
setMarginMirroring
public boolean setMarginMirroring(boolean MarginMirroring)
Description copied from interface:DocListener
Parameter that allows you to do margin mirroring (odd/even pages)- Specified by:
setMarginMirroring
in interfaceDocListener
- Returns:
- true if succesfull
- See Also:
DocListener.setMarginMirroring(boolean)
-
-