Class DocWriter

java.lang.Object
com.gitlab.pdftk_java.com.lowagie.text.DocWriter
All Implemented Interfaces:
DocListener, ElementListener, EventListener
Direct Known Subclasses:
PdfWriter

public abstract class DocWriter extends Object implements DocListener
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

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Closes the stream on document close
    static final byte
    This is some byte that is often used.
    static final byte
    This is some byte that is often used.
    static final byte
    This is some byte that is often used.
    static final byte
    This is some byte that is often used.
    protected boolean
    Do we have to pause all writing actions?
    static final byte
    This is some byte that is often used.
    boolean
    Is the writer open for writing?
    The outputstream of this writer.
    protected Rectangle
    The pageSize.
    static final byte
    This is some byte that is often used.
    static final byte
    This is some byte that is often used.
    static final byte
    This is some byte that is often used.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    Constructs a DocWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(Element element)
    Signals that an Element was added to the Document.
    protected void
    addTabs(int indent)
    Writes a number of tabs.
    void
    Clears text wrapping around images (if applicable).
    void
    Signals that the Document was closed and that no other Elements will be added.
    void
    Flushes the BufferedOutputStream.
    static final byte[]
    Converts a String into a Byte array according to the ISO-8859-1 codepage.
    protected static boolean
    Returns true if the specified Element implements MarkupAttributes and has one or more attributes to write.
    boolean
    Checks if the stream is to be closed on document close
    boolean
    Signals that an new page has to be started.
    void
    Signals that the Document was opened.
    void
    Let the writer know that all writing has to be paused.
    void
    Resets the footer of this document.
    void
    Resets the header of this document.
    void
    Sets the page number to 0.
    void
    Let the writer know that writing may be resumed.
    void
    setCloseStream(boolean closeStream)
    Sets the close state of the stream after document close
    boolean
    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
    Sets the pagesize.
    protected void
    write(String string)
    Writes a String to the OutputStream.
    protected void
    write(String key, String value)
    Writes a key-value pair to the outputstream.
    protected void
    Writes an endtag to the outputstream.
    protected void
    Writes an endtag to the outputstream.
    protected boolean
    Writes the markup attributes of the specified MarkupAttributes object to the OutputStream.
    protected void
    Writes a starttag to the outputstream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NEWLINE

      public static final byte NEWLINE
      This is some byte that is often used.
      See Also:
    • TAB

      public static final byte TAB
      This is some byte that is often used.
      See Also:
    • LT

      public static final byte LT
      This is some byte that is often used.
      See Also:
    • SPACE

      public static final byte SPACE
      This is some byte that is often used.
      See Also:
    • EQUALS

      public static final byte EQUALS
      This is some byte that is often used.
      See Also:
    • QUOTE

      public static final byte QUOTE
      This is some byte that is often used.
      See Also:
    • GT

      public static final byte GT
      This is some byte that is often used.
      See Also:
    • FORWARD

      public static final byte FORWARD
      This is some byte that is often used.
      See Also:
    • pageSize

      protected Rectangle pageSize
      The pageSize.
    • 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
  • Constructor Details

    • DocWriter

      protected DocWriter()
    • DocWriter

      protected DocWriter(OutputStream os)
      Constructs a DocWriter.
      Parameters:
      document - The Document that has to be written
      os - The OutputStream the writer has to write to.
  • Method Details

    • add

      public boolean add(Element element) throws DocumentException
      Signals that an Element was added to the Document.

      This method should be overriden in the specific DocWriter classes derived from this abstract class.

      Specified by:
      add in interface ElementListener
      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 the Document was opened.
      Specified by:
      open in interface DocListener
    • setPageSize

      public boolean setPageSize(Rectangle pageSize)
      Sets the pagesize.
      Specified by:
      setPageSize in interface DocListener
      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 interface DocListener
      Parameters:
      marginLeft - the margin on the left
      marginRight - the margin on the right
      marginTop - the margin on the top
      marginBottom - 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 interface DocListener
      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 interface DocListener
    • 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 interface DocListener
      Parameters:
      pageN - the new page number
    • close

      public void close()
      Signals that the Document was closed and that no other Elements will be added.
      Specified by:
      close in interface DocListener
    • getISOBytes

      public static final byte[] getISOBytes(String text)
      Converts a String into a Byte 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 the BufferedOutputStream.
    • write

      protected void write(String string) throws IOException
      Writes a String to the OutputStream.
      Parameters:
      string - the String to write
      Throws:
      IOException
    • addTabs

      protected void addTabs(int indent) throws IOException
      Writes a number of tabs.
      Parameters:
      indent - the number of tabs to add
      Throws:
      IOException
    • write

      protected void write(String key, String value) throws IOException
      Writes a key-value pair to the outputstream.
      Parameters:
      key - the name of an attribute
      value - the value of an attribute
      Throws:
      IOException
    • writeStart

      protected void writeStart(String tag) throws IOException
      Writes a starttag to the outputstream.
      Parameters:
      tag - the name of the tag
      Throws:
      IOException
    • writeEnd

      protected void writeEnd(String tag) throws IOException
      Writes an endtag to the outputstream.
      Parameters:
      tag - the name of the tag
      Throws:
      IOException
    • writeEnd

      protected void writeEnd() throws IOException
      Writes an endtag to the outputstream.
      Throws:
      IOException
    • writeMarkupAttributes

      protected boolean writeMarkupAttributes(MarkupAttributes mAtt) throws IOException
      Writes the markup attributes of the specified MarkupAttributes object to the OutputStream.
      Parameters:
      mAtt - the MarkupAttributes to write.
      Returns:
      true, if writing the markup attributes succeeded
      Throws:
      IOException
    • hasMarkupAttributes

      protected static boolean hasMarkupAttributes(Element element)
      Returns true if the specified Element implements MarkupAttributes and has one or more attributes to write.
      Parameters:
      element - the Element 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 interface DocListener
      Throws:
      DocumentException
      See Also:
    • 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 interface DocListener
      Returns:
      true if succesfull
      See Also: