tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 PDF > iTEXT > Insert Image

Insert Image 

iText is a free and open source library for creating and manipulating PDF documents in Java. The following example shows inserting an image in PDF document.

File Name  :  
com/bethecoder/tutorials/itext/tests/InsertImage.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.itext.tests;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class InsertImage {

  /**
   @param args
   @throws DocumentException 
   @throws IOException 
   @throws MalformedURLException 
   */
  public static void main(String[] argsthrows DocumentException, MalformedURLException, IOException {

    Document document = new Document(PageSize.A4)
    PdfWriter.getInstance(document, new FileOutputStream("test6.pdf"));
    
    //Open the document before adding any content
    document.open();
    
    Paragraph paragraph = new Paragraph("BE THE CODER");
    document.add(paragraph);
    
    //Get image to insert
    document.add(Image.getInstance("http://www.google.com/logos/2011/first_day_school-2011-hp.jpg"));
    document.add(Image.getInstance("C:\\jfkinaugural11-hp.jpg"));
    
    //Close the document
    document.close();
  }

}
   

It gives the following output,
test6.jpg

                    Print

   


Books Recommendation

 
 
bl  br