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, 50, 50, 50, 50);
    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(); 
  }
}