java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow iText arrow Creating PDF, RTF or HTML document from a Java class at runtime
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 3947
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Creating PDF, RTF or HTML document from a Java class at runtime E-mail
User Rating: / 28
PoorBest 

iText library allows you to create PDF, RTF or HTML documents from Java classes at runtime. Manipulation of these types of documents are also possible with this library.

The example below shows you how to create PDF/RTF and HTML documents with iText (Just uncomment the appropriate line for the format you want.):

import com.lowagie.text.*;
import java.io.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.html.*;
import com.lowagie.text.rtf.*;

class  createDocument
{
  public static void main(String args[])
  {  
    Document document = new Document(PageSize.A4, 50505050);
    try 
    {
      PdfWriter pdf = PdfWriter.getInstance(document , 
        new FileOutputStream("text.pdf"));
      //HtmlWriter pdf = HtmlWriter.getInstance(document, 
      //  new FileOutputStream("text.html"));
      //RtfWriter2 pdf = RtfWriter2.getInstance(document, 
      //  new FileOutputStream("text.rtf"));
      

      document.addSubject("This is the result of a Test.")
      
      HeaderFooter header = new HeaderFooter(
        new Phrase("This is a header.")false);
      HeaderFooter footer = new HeaderFooter(
        new Phrase("This is page ")new Phrase("."));
      
      footer.setAlignment(Element.ALIGN_CENTER);

      document.setHeader(header)
      document.setFooter(footer);
      document.open();
      document.add(new Paragraph("This is test message"));
    
    catch(DocumentException de
    {
      System.err.println(de.getMessage())
    
    catch(Exception de
    {
      System.err.println(de.getMessage())
    
    document.close()
  }
}


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.