Class DocWriter

java.lang.Object
org.openpdf.text.DocWriter
All Implemented Interfaces:
AutoCloseable, EventListener, DocListener, ElementListener
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
    protected Document
    This is the document that has to be written.
    protected boolean
    Is the writer open for writing?
    The outputstream of this writer.
    protected Rectangle
    The pageSize.
    protected boolean
    Do we have to pause all writing actions?
    static final byte
    This is some byte that is often used.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    boolean
    add(Element element)
    Signals that an Element was added to the Document.
    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.
    boolean
    Checks if writing is paused.
    boolean
    Signals that an new page has to be started.
    void
    Signals that the Document was opened.
    boolean
    setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
    Sets the margins.
    boolean
    Sets the pagesize.

    Methods inherited from class java.lang.Object

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

    • QUOTE

      public static final byte QUOTE
      This is some byte that is often used.
      See Also:
    • 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 Details

    • DocWriter

      protected DocWriter(Document document, 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

    • 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
    • add

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

      This method should be overridden 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()
      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.
    • close

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

      public boolean isPaused()
      Checks if writing is paused.
      Returns:
      true if writing temporarily has to be paused, false otherwise.
    • flush

      public void flush()
      Flushes the BufferedOutputStream.