Class Document

java.lang.Object
com.lowagie.text.Document
All Implemented Interfaces:
DocListener, ElementListener, AutoCloseable, EventListener
Direct Known Subclasses:
PdfDocument

@Deprecated public class Document extends Object implements DocListener
Deprecated.
A generic Document class.

All kinds of Text-elements can be added to a HTMLDocument. The Document signals all the listeners when an element has been added.

Remark:

  1. Once a document is created you can add some meta information.
  2. You can also set the headers/footers.
  3. You have to open the document before you can write content.
  4. You can only write content (no more meta-formation!) once a document is opened.
  5. When you change the header/footer on a certain page, this will be effective starting on the next page.
  6. After closing the document, every listener (as well as its OutputStream) is closed too.
Example:
// creation of the document with a certain size and certain margins
 Document document = new Document(PageSize.A4, 50, 50, 50, 50);
  try {
 // creation of the different writers HtmlWriter.getInstance(document , System.out);
 PdfWriter.getInstance(document , new FileOutputStream("text.pdf")); // we add some meta information
 to the document
 document.addAuthor("Bruno Lowagie"); 
 document.addSubject("This is the result of a Test."); 
 // we open the document for writing
 document.open(); 
 document.add(new Paragraph("Hello world"));
 } catch(DocumentException de) { System.err.println(de.getMessage()); }
 document.close();
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    Deprecated.
    This is a chapter number in case ChapterAutoNumber is used.
    protected boolean
    Deprecated.
    Has the document already been closed?
    static boolean
    Deprecated.
    Allows the pdf documents to be produced without compression for debugging purposes.
    protected HeaderFooter
    Deprecated.
    This is the textual part of the footer
    protected HeaderFooter
    Deprecated.
    This is the textual part of a Page; it can contain a header
    protected String
    Deprecated.
    Style class in HTML body tag
    protected String
    Deprecated.
    Content of JavaScript onLoad function
    protected String
    Deprecated.
    Content of JavaScript onUnLoad function
    protected float
    Deprecated.
    margin in y direction starting from the bottom
    protected float
    Deprecated.
    margin in x direction starting from the left
    protected boolean
    Deprecated.
    mirroring of the left/right margins
    protected boolean
    Deprecated.
    mirroring of the top/bottom margins
    protected float
    Deprecated.
    margin in x direction starting from the right
    protected float
    Deprecated.
    margin in y direction starting from the top
    protected boolean
    Deprecated.
    Is the document open or not?
    protected int
    Deprecated.
    Current pagenumber
    protected Rectangle
    Deprecated.
    The size of the page.
    static boolean
    Deprecated.
    When true the file access is not done through a memory mapped file.
    static float
    Deprecated.
    Scales the WMF font size.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Constructs a new Document -object with the default page size as PageSize.A4 .
    Document(Rectangle pageSize)
    Deprecated.
    Constructs a new Document -object using the given rectangle as page size and default margin of 36.
    Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
    Deprecated.
    Constructs a new Document -object.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(Element element)
    Deprecated.
    Adds an Element to the Document.
    boolean
    addAuthor(String author)
    Deprecated.
    Adds the author to a Document.
    boolean
    Deprecated.
    Adds the current date and time to a Document.
    boolean
    Deprecated.
    Adds the current date and time to a Document.
    boolean
    addCreator(String creator)
    Deprecated.
    Adds the creator to a Document.
    void
    Deprecated.
    Adds a DocListener to the Document.
    boolean
    addHeader(String name, String content)
    Deprecated.
    Adds a user defined header to the document.
    boolean
    addKeywords(String keywords)
    Deprecated.
    Adds the keywords to a Document.
    boolean
    Deprecated.
    Adds the current date and time to a Document.
    boolean
    Deprecated.
    Adds the current date and time to a Document.
    boolean
    Deprecated.
    Adds the producer to a Document.
    boolean
    addProducer(String producer)
    Deprecated.
    Adds the provided value as the producer to a Document.
    boolean
    addSubject(String subject)
    Deprecated.
    Adds the subject to a Document.
    boolean
    Deprecated.
    Adds the title to a Document.
    float
    Deprecated.
    Returns the lower left y-coordinate.
    float
    bottom(float margin)
    Deprecated.
    Returns the lower left y-coordinate, considering a given margin.
    float
    Deprecated.
    Returns the bottom margin.
    void
    Deprecated.
    Closes the document.
    Deprecated.
    The default language of the document.
    Deprecated.
    Gets the style class of the HTML body tag
    Deprecated.
    Gets the JavaScript onLoad command.
    Deprecated.
    Gets the JavaScript onUnLoad command.
    int
    Deprecated.
    Returns the current page number.
    Deprecated.
    Gets the pagesize.
    static String
    Deprecated.
    Gets the product name.
    static String
    Deprecated.
    Gets the release number.
    Deprecated.
    Gets the text rendering options.
    static String
    Deprecated.
    Gets the iText version.
    boolean
    Deprecated.
    Returns the glyph substitution enabled flag.
    boolean
    Deprecated.
    Gets the margin mirroring flag.
    boolean
    Deprecated.
    Checks if the document is open.
    float
    Deprecated.
    Returns the lower left x-coordinate.
    float
    left(float margin)
    Deprecated.
    Returns the lower left x-coordinate considering a given margin.
    float
    Deprecated.
    Returns the left margin.
    boolean
    Deprecated.
    Signals to all listeners, that a new page has to be started.
    void
    Deprecated.
    Opens the document.
    void
    Deprecated.
    Removes a DocListener from the Document.
    void
    Deprecated.
    Resets the footer of this document.
    void
    Deprecated.
    Resets the header of this document.
    void
    Deprecated.
    Sets the page number to 0.
    float
    Deprecated.
    Returns the upper right x-coordinate.
    float
    right(float margin)
    Deprecated.
    Returns the upper right x-coordinate, considering a given margin.
    float
    Deprecated.
    Return the right margin.
    void
    setDocumentLanguage(String documentLanguage)
    Deprecated.
    The new document language.
    void
    Deprecated.
    Changes the footer of this document.
    void
    setGlyphSubstitutionEnabled(boolean glyphSubstitutionEnabled)
    Deprecated.
    Set a flag that determine whether glyph substion is enabled when FOP is available.
    void
    Deprecated.
    Changes the header of this document.
    void
    setHtmlStyleClass(String htmlStyleClass)
    Deprecated.
    Adds a style class to the HTML body tag
    void
    Deprecated.
    Adds a JavaScript onLoad function to the HTML body tag
    void
    Deprecated.
    Adds a JavaScript onUnLoad function to the HTML body tag
    boolean
    setMarginMirroring(boolean marginMirroring)
    Deprecated.
    Set the margin mirroring.
    boolean
    setMarginMirroringTopBottom(boolean marginMirroringTopBottom)
    Deprecated.
    Set the margin mirroring.
    boolean
    setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
    Deprecated.
    Sets the margins.
    void
    setPageCount(int pageN)
    Deprecated.
    Sets the page number.
    boolean
    Deprecated.
    Sets the pagesize.
    void
    Deprecated.
    Sets the text rendering options.
    float
    top()
    Deprecated.
    Returns the upper right y-coordinate.
    float
    top(float margin)
    Deprecated.
    Returns the upper right y-coordinate, considering a given margin.
    float
    Deprecated.
    Returns the top margin.

    Methods inherited from class java.lang.Object

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

    • compress

      public static boolean compress
      Deprecated.
      Allows the pdf documents to be produced without compression for debugging purposes.
    • plainRandomAccess

      public static boolean plainRandomAccess
      Deprecated.
      When true the file access is not done through a memory mapped file. Use it if the file is too big to be mapped in your address space.
    • wmfFontCorrection

      public static float wmfFontCorrection
      Deprecated.
      Scales the WMF font size. The default value is 0.86.
    • open

      protected boolean open
      Deprecated.
      Is the document open or not?
    • close

      protected boolean close
      Deprecated.
      Has the document already been closed?
    • pageSize

      protected Rectangle pageSize
      Deprecated.
      The size of the page.
    • marginLeft

      protected float marginLeft
      Deprecated.
      margin in x direction starting from the left
    • marginRight

      protected float marginRight
      Deprecated.
      margin in x direction starting from the right
    • marginTop

      protected float marginTop
      Deprecated.
      margin in y direction starting from the top
    • marginBottom

      protected float marginBottom
      Deprecated.
      margin in y direction starting from the bottom
    • marginMirroring

      protected boolean marginMirroring
      Deprecated.
      mirroring of the left/right margins
    • marginMirroringTopBottom

      protected boolean marginMirroringTopBottom
      Deprecated.
      mirroring of the top/bottom margins
      Since:
      2.1.6
    • javaScript_onLoad

      protected String javaScript_onLoad
      Deprecated.
      Content of JavaScript onLoad function
    • javaScript_onUnLoad

      protected String javaScript_onUnLoad
      Deprecated.
      Content of JavaScript onUnLoad function
    • htmlStyleClass

      protected String htmlStyleClass
      Deprecated.
      Style class in HTML body tag
    • pageN

      protected int pageN
      Deprecated.
      Current pagenumber
    • chapternumber

      protected int chapternumber
      Deprecated.
      This is a chapter number in case ChapterAutoNumber is used.
  • Constructor Details

    • Document

      public Document()
      Deprecated.
      Constructs a new Document -object with the default page size as PageSize.A4 .
    • Document

      public Document(Rectangle pageSize)
      Deprecated.
      Constructs a new Document -object using the given rectangle as page size and default margin of 36.
      Parameters:
      pageSize - the pageSize
    • Document

      public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom)
      Deprecated.
      Constructs a new Document -object.
      Parameters:
      pageSize - the pageSize
      marginLeft - the margin on the left
      marginRight - the margin on the right
      marginTop - the margin on the top
      marginBottom - the margin on the bottom
  • Method Details

    • getProduct

      public static String getProduct()
      Deprecated.
      Gets the product name.
      Returns:
      the product name
      Since:
      2.1.6
    • getRelease

      public static String getRelease()
      Deprecated.
      Gets the release number.
      Returns:
      the product name
      Since:
      2.1.6
    • getVersion

      public static String getVersion()
      Deprecated.
      Gets the iText version.
      Returns:
      iText version
    • addDocListener

      public void addDocListener(DocListener listener)
      Deprecated.
      Adds a DocListener to the Document.
      Parameters:
      listener - the new DocListener.
    • removeDocListener

      public void removeDocListener(DocListener listener)
      Deprecated.
      Removes a DocListener from the Document.
      Parameters:
      listener - the DocListener that has to be removed.
    • add

      public boolean add(Element element) throws DocumentException
      Deprecated.
      Adds an Element to the Document.
      Specified by:
      add in interface ElementListener
      Parameters:
      element - the Element to add
      Returns:
      true if the element was added, false if not
      Throws:
      DocumentException - when a document isn't open yet, or has been closed
    • open

      public void open()
      Deprecated.
      Opens the document.

      Once the document is opened, you can't write any meta-information anymore. If you change the header/footer after opening the document, the change will be effective starting from the second page. You have to open the document before you can begin to add content to the body of the document.

      Specified by:
      open in interface DocListener
    • setPageSize

      public boolean setPageSize(Rectangle pageSize)
      Deprecated.
      Sets the pagesize.

      This change will be effective starting from the next page. If you want to change the page size of the first page, you need to set it before opening the document.

      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)
      Deprecated.
      Sets the margins.

      This change will be effective starting from the next page. If you want to change margins on the first page, you need to set it before opening the document.

      A new page is created when you call:

      • Document.open()
      • Document.newPage(), only if the current page has some content, otherwise no new page will be created

      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:
      a boolean
    • newPage

      public boolean newPage()
      Deprecated.
      Signals to all listeners, that a new page has to be started. New pages can only be added on already opened and not yet closed documents.
      Specified by:
      newPage in interface DocListener
      Returns:
      true if the page was added, false if not.
    • setHeader

      public void setHeader(HeaderFooter header)
      Deprecated.
      Changes the header of this document.

      This change will be effective starting from the next page. If you want to have a header on the first page, you need to set it before opening the document.

      Specified by:
      setHeader in interface DocListener
      Parameters:
      header - the new header
    • resetHeader

      public void resetHeader()
      Deprecated.
      Resets the header of this document.

      This change will be effective starting from the next page.

      Specified by:
      resetHeader in interface DocListener
    • setFooter

      public void setFooter(HeaderFooter footer)
      Deprecated.
      Changes the footer of this document.

      This change will be effective starting from the next page. If you want to have a footer on the first page, you need to set it before opening the document.

      Specified by:
      setFooter in interface DocListener
      Parameters:
      footer - the new footer
    • resetFooter

      public void resetFooter()
      Deprecated.
      Resets the footer of this document.

      This change will be effective starting from the next page.

      Specified by:
      resetFooter in interface DocListener
    • resetPageCount

      public void resetPageCount()
      Deprecated.
      Sets the page number to 0.

      This change will be effective starting from the next page.

      Specified by:
      resetPageCount in interface DocListener
    • setPageCount

      public void setPageCount(int pageN)
      Deprecated.
      Sets the page number.

      This change will be effective starting from the next page.

      The page number of the next new page will be: pageN + 1

      Specified by:
      setPageCount in interface DocListener
      Parameters:
      pageN - the new page number
    • getPageNumber

      public int getPageNumber()
      Deprecated.
      Returns the current page number.
      Returns:
      the current page number
    • close

      public void close()
      Deprecated.
      Closes the document.

      Once all the content has been written in the body, you have to close the body. After that nothing can be written to the body anymore.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DocListener
    • addHeader

      public boolean addHeader(String name, String content)
      Deprecated.
      Adds a user defined header to the document.

      Shortcut method to call: add(new Header(name, content))

      Parameters:
      name - the name of the header
      content - the content of the header
      Returns:
      true if successful, false otherwise
    • addTitle

      public boolean addTitle(String title)
      Deprecated.
      Adds the title to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as the title meta tag in the HEAD part of the file.

      Shortcut method to call: add(new Meta(Element.TITLE, title))

      Parameters:
      title - the title
      Returns:
      true if successful, false otherwise
    • addSubject

      public boolean addSubject(String subject)
      Deprecated.
      Adds the subject to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as the subject meta tag in the HEAD part of the file.

      Parameters:
      subject - the subject
      Returns:
      true if successful, false otherwise
    • addKeywords

      public boolean addKeywords(String keywords)
      Deprecated.
      Adds the keywords to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as the keywords meta tag in the HEAD part of the file.

      Parameters:
      keywords - adds the keywords to the document
      Returns:
      true if successful, false otherwise
    • addAuthor

      public boolean addAuthor(String author)
      Deprecated.
      Adds the author to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as the author meta tag in the HEAD part of the file.

      Parameters:
      author - the name of the author
      Returns:
      true if successful, false otherwise
    • addCreator

      public boolean addCreator(String creator)
      Deprecated.
      Adds the creator to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as comment in the HEAD part of the file.

      Parameters:
      creator - the name of the creator
      Returns:
      true if successful, false otherwise
    • addProducer

      public boolean addProducer()
      Deprecated.
      Adds the producer to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as comment in the HEAD part of the file.

      Returns:
      true if successful, false otherwise
    • addProducer

      public boolean addProducer(String producer)
      Deprecated.
      Adds the provided value as the producer to a Document.

      The default producer is OpenPDF XX.YY.ZZ where XX.YY.ZZ is the version of the OpenPDF library used to produce the document

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as comment in the HEAD part of the file.

      Parameters:
      producer - new producer line value
      Returns:
      true if successful, false otherwise
    • addCreationDate

      public boolean addCreationDate()
      Deprecated.
      Adds the current date and time to a Document.

      In case of a PDF this will be visible in the document properties panel.

      In case of a HTML file this will be visible as comment in the HEAD part of the file.

      Returns:
      true if successful, false otherwise
    • addCreationDate

      public boolean addCreationDate(PdfDate date)
      Deprecated.
      Adds the current date and time to a Document.
      Returns:
      true if successful, false otherwise
    • addModificationDate

      public boolean addModificationDate()
      Deprecated.
      Adds the current date and time to a Document.
      Returns:
      true if successful, false otherwise
    • addModificationDate

      public boolean addModificationDate(PdfDate date)
      Deprecated.
      Adds the current date and time to a Document.
      Returns:
      true if successful, false otherwise
    • leftMargin

      public float leftMargin()
      Deprecated.
      Returns the left margin.
      Returns:
      the left margin
    • rightMargin

      public float rightMargin()
      Deprecated.
      Return the right margin.
      Returns:
      the right margin
    • topMargin

      public float topMargin()
      Deprecated.
      Returns the top margin.
      Returns:
      the top margin
    • bottomMargin

      public float bottomMargin()
      Deprecated.
      Returns the bottom margin.
      Returns:
      the bottom margin
    • left

      public float left()
      Deprecated.
      Returns the lower left x-coordinate.
      Returns:
      the lower left x-coordinate
    • right

      public float right()
      Deprecated.
      Returns the upper right x-coordinate.
      Returns:
      the upper right x-coordinate
    • top

      public float top()
      Deprecated.
      Returns the upper right y-coordinate.
      Returns:
      the upper right y-coordinate
    • bottom

      public float bottom()
      Deprecated.
      Returns the lower left y-coordinate.
      Returns:
      the lower left y-coordinate
    • left

      public float left(float margin)
      Deprecated.
      Returns the lower left x-coordinate considering a given margin.
      Parameters:
      margin - a margin
      Returns:
      the lower left x-coordinate
    • right

      public float right(float margin)
      Deprecated.
      Returns the upper right x-coordinate, considering a given margin.
      Parameters:
      margin - a margin
      Returns:
      the upper right x-coordinate
    • top

      public float top(float margin)
      Deprecated.
      Returns the upper right y-coordinate, considering a given margin.
      Parameters:
      margin - a margin
      Returns:
      the upper right y-coordinate
    • bottom

      public float bottom(float margin)
      Deprecated.
      Returns the lower left y-coordinate, considering a given margin.
      Parameters:
      margin - a margin
      Returns:
      the lower left y-coordinate
    • getPageSize

      public Rectangle getPageSize()
      Deprecated.
      Gets the pagesize.
      Returns:
      the page size
    • isOpen

      public boolean isOpen()
      Deprecated.
      Checks if the document is open.
      Returns:
      true if the document is open
    • getJavaScript_onLoad

      public String getJavaScript_onLoad()
      Deprecated.
      Gets the JavaScript onLoad command.
      Returns:
      the JavaScript onLoad command
    • setJavaScript_onLoad

      public void setJavaScript_onLoad(String code)
      Deprecated.
      Adds a JavaScript onLoad function to the HTML body tag
      Parameters:
      code - the JavaScript code to be executed on load of the HTML page
    • getJavaScript_onUnLoad

      public String getJavaScript_onUnLoad()
      Deprecated.
      Gets the JavaScript onUnLoad command.
      Returns:
      the JavaScript onUnLoad command
    • setJavaScript_onUnLoad

      public void setJavaScript_onUnLoad(String code)
      Deprecated.
      Adds a JavaScript onUnLoad function to the HTML body tag
      Parameters:
      code - the JavaScript code to be executed on unload of the HTML page
    • getHtmlStyleClass

      public String getHtmlStyleClass()
      Deprecated.
      Gets the style class of the HTML body tag
      Returns:
      the style class of the HTML body tag
    • setHtmlStyleClass

      public void setHtmlStyleClass(String htmlStyleClass)
      Deprecated.
      Adds a style class to the HTML body tag
      Parameters:
      htmlStyleClass - the style class for the HTML body tag
    • setMarginMirroring

      public boolean setMarginMirroring(boolean marginMirroring)
      Deprecated.
      Set the margin mirroring. It will mirror right/left margins for odd/even pages.

      Note: it will not work with Table.

      Specified by:
      setMarginMirroring in interface DocListener
      Parameters:
      marginMirroring - true to mirror the margins
      Returns:
      always true
    • setMarginMirroringTopBottom

      public boolean setMarginMirroringTopBottom(boolean marginMirroringTopBottom)
      Deprecated.
      Set the margin mirroring. It will mirror top/bottom margins for odd/even pages.

      Note: it will not work with Table.

      Specified by:
      setMarginMirroringTopBottom in interface DocListener
      Parameters:
      marginMirroringTopBottom - true to mirror the margins
      Returns:
      always true
      Since:
      2.1.6
    • isMarginMirroring

      public boolean isMarginMirroring()
      Deprecated.
      Gets the margin mirroring flag.
      Returns:
      the margin mirroring flag
    • getDocumentLanguage

      public String getDocumentLanguage()
      Deprecated.
      The default language of the document. Can be set to values like "en_US". This language is used in FopGlyphProcessor to determine which glyphs are to be substituted.

      The default "dflt" means that all glyphs which can be replaced will be substituted.

      Returns:
      the current document language
    • setDocumentLanguage

      public void setDocumentLanguage(String documentLanguage)
      Deprecated.
      The new document language. This language is used in FopGlyphProcessor to determine which glyphs are to be substituted.

      The default "dflt" means that all glyphs which can be replaced will be substituted.

      Parameters:
      documentLanguage - the wanted language
    • isGlyphSubstitutionEnabled

      public boolean isGlyphSubstitutionEnabled()
      Deprecated.
      Returns the glyph substitution enabled flag.
      Returns:
      the glyph substitution enabled flag
      See Also:
    • setGlyphSubstitutionEnabled

      public void setGlyphSubstitutionEnabled(boolean glyphSubstitutionEnabled)
      Deprecated.
      Set a flag that determine whether glyph substion is enabled when FOP is available.
      Parameters:
      glyphSubstitutionEnabled - the glyph substitution enabled flag
      See Also:
    • getTextRenderingOptions

      public TextRenderingOptions getTextRenderingOptions()
      Deprecated.
      Gets the text rendering options.
      Returns:
      the text rendering options
      See Also:
    • setTextRenderingOptions

      public void setTextRenderingOptions(TextRenderingOptions textRenderingOptions)
      Deprecated.
      Sets the text rendering options.
      Parameters:
      textRenderingOptions - the text rendering options
      See Also: