Home » iText-2.1.7 » com.lowagie » text » [javadoc | source]
com.lowagie.text
public class: Document [javadoc | source]
java.lang.Object
   com.lowagie.text.Document

All Implemented Interfaces:
    DocListener

Direct Known Subclasses:
    PdfDocument

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
public static  boolean compress    Allows the pdf documents to be produced without compression for debugging purposes. 
public static  boolean plainRandomAccess    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. 
public static  float wmfFontCorrection    Scales the WMF font size. The default value is 0.86. 
protected  boolean open    Is the document open or not? 
protected  boolean close    Has the document already been closed? 
protected  Rectangle pageSize    The size of the page. 
protected  float marginLeft    margin in x direction starting from the left 
protected  float marginRight    margin in x direction starting from the right 
protected  float marginTop    margin in y direction starting from the top 
protected  float marginBottom    margin in y direction starting from the bottom 
protected  boolean marginMirroring    mirroring of the left/right margins 
protected  boolean marginMirroringTopBottom    mirroring of the top/bottom margins
    since: 2.1.6 -
 
protected  String javaScript_onLoad    Content of JavaScript onLoad function 
protected  String javaScript_onUnLoad    Content of JavaScript onUnLoad function 
protected  String htmlStyleClass    Style class in HTML body tag 
protected  int pageN    Current pagenumber 
protected  HeaderFooter header    This is the textual part of a Page; it can contain a header 
protected  HeaderFooter footer    This is the textual part of the footer 
protected  int chapternumber    This is a chapter number in case ChapterAutoNumber is used. 
Constructor:
 public Document() 
 public Document(Rectangle pageSize) 
    Constructs a new Document -object.
    Parameters:
    pageSize - the pageSize
 public Document(Rectangle pageSize,
    float marginLeft,
    float marginRight,
    float marginTop,
    float marginBottom) 
    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 from com.lowagie.text.Document Summary:
add,   addAuthor,   addCreationDate,   addCreator,   addDocListener,   addHeader,   addKeywords,   addProducer,   addSubject,   addTitle,   bottom,   bottom,   bottomMargin,   close,   getHtmlStyleClass,   getJavaScript_onLoad,   getJavaScript_onUnLoad,   getPageNumber,   getPageSize,   getProduct,   getRelease,   getVersion,   isMarginMirroring,   isOpen,   left,   left,   leftMargin,   newPage,   open,   removeDocListener,   resetFooter,   resetHeader,   resetPageCount,   right,   right,   rightMargin,   setFooter,   setHeader,   setHtmlStyleClass,   setJavaScript_onLoad,   setJavaScript_onUnLoad,   setMarginMirroring,   setMarginMirroringTopBottom,   setMargins,   setPageCount,   setPageSize,   top,   top,   topMargin
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.lowagie.text.Document Detail:
 public boolean add(Element element) throws DocumentException 
    Adds an Element to the Document.
 public boolean addAuthor(String author) 
    Adds the author to a Document.
 public boolean addCreationDate() 
    Adds the current date and time to a Document.
 public boolean addCreator(String creator) 
    Adds the creator to a Document.
 public  void addDocListener(DocListener listener) 
    Adds a DocListener to the Document.
 public boolean addHeader(String name,
    String content) 
    Adds a user defined header to the document.
 public boolean addKeywords(String keywords) 
    Adds the keywords to a Document.
 public boolean addProducer() 
    Adds the producer to a Document.
 public boolean addSubject(String subject) 
    Adds the subject to a Document.
 public boolean addTitle(String title) 
    Adds the title to a Document.
 public float bottom() 
    Returns the lower left y-coordinate.
 public float bottom(float margin) 
    Returns the lower left y-coordinate, considering a given margin.
 public float bottomMargin() 
    Returns the bottom margin.
 public  void close() 
    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.

 public String getHtmlStyleClass() 
    Gets the style class of the HTML body tag
 public String getJavaScript_onLoad() 
    Gets the JavaScript onLoad command.
 public String getJavaScript_onUnLoad() 
    Gets the JavaScript onUnLoad command.
 public int getPageNumber() 
    Returns the current page number.
 public Rectangle getPageSize() 
    Gets the pagesize.
 public static final String getProduct() 
    Gets the product name. This method may only be changed by Paulo Soares and/or Bruno Lowagie.
 public static final String getRelease() 
    Gets the release number. This method may only be changed by Paulo Soares and/or Bruno Lowagie.
 public static final String getVersion() 
    Gets the iText version. This method may only be changed by Paulo Soares and/or Bruno Lowagie.
 public boolean isMarginMirroring() 
    Gets the margin mirroring flag.
 public boolean isOpen() 
    Checks if the document is open.
 public float left() 
    Returns the lower left x-coordinate.
 public float left(float margin) 
    Returns the lower left x-coordinate considering a given margin.
 public float leftMargin() 
    Returns the left margin.
 public boolean newPage() 
    Signals that an new page has to be started.
 public  void open() 
    Opens the document.

    Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.

 public  void removeDocListener(DocListener listener) 
    Removes a DocListener from the Document.
 public  void resetFooter() 
    Resets the footer of this document.
 public  void resetHeader() 
    Resets the header of this document.
 public  void resetPageCount() 
    Sets the page number to 0.
 public float right() 
    Returns the upper right x-coordinate.
 public float right(float margin) 
    Returns the upper right x-coordinate, considering a given margin.
 public float rightMargin() 
    Return the right margin.
 public  void setFooter(HeaderFooter footer) 
    Changes the footer of this document.
 public  void setHeader(HeaderFooter header) 
    Changes the header of this document.
 public  void setHtmlStyleClass(String htmlStyleClass) 
    Adds a style class to the HTML body tag
 public  void setJavaScript_onLoad(String code) 
    Adds a JavaScript onLoad function to the HTML body tag
 public  void setJavaScript_onUnLoad(String code) 
    Adds a JavaScript onUnLoad function to the HTML body tag
 public boolean setMarginMirroring(boolean marginMirroring) 
    Set the margin mirroring. It will mirror right/left margins for odd/even pages.

    Note: it will not work with Table .

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

    Note: it will not work with Table .

 public boolean setMargins(float marginLeft,
    float marginRight,
    float marginTop,
    float marginBottom) 
    Sets the margins.
 public  void setPageCount(int pageN) 
    Sets the page number.
 public boolean setPageSize(Rectangle pageSize) 
    Sets the pagesize.
 public float top() 
    Returns the upper right y-coordinate.
 public float top(float margin) 
    Returns the upper right y-coordinate, considering a given margin.
 public float topMargin() 
    Returns the top margin.