java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
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: 4091
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:
 
 
 
Manipulating PDF, RTF, or HTML documents with Java E-mail
User Rating: / 12
PoorBest 

iText library allows you to create and manipulate PDF, RTF or HTML documents from Java classes at runtime. Manipulation of these types of documents are also possible with this library. com.lowagie.text.pdf package allows Java classes to manipluate PDF documents.

The example below adds a JPG image to a PDF document. Other images like bmp, gif, png or rawdata can also be added to document.

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

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.")

      Image img = Image.getInstance("image.jpg");
      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"));
      document.add(img);

    
    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.