Adding AWT Image to PDF : AWT Image « PDF RTF « Java






Adding AWT Image to PDF

Adding AWT Image to PDF
import java.awt.Toolkit;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class AddingAWTImagePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddingAWTImagePDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("logo.png");
      Image image = Image.getInstance(awtImage, null);
      image.setAbsolutePosition(100, 500);
      cb.addImage(image);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}

           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Adding AWT Image to PDF with ColorAdding AWT Image to PDF with Color