Add Images To PDF In Java Using iText

Chapter: iText Last Updated: 10-08-2016 18:13:40 UTC

Program:

            /* ............... START ............... */
                
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URL;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class JavaiTextAddImagesToPDF {

	public static void main(String[] args) {
		Document document = new Document();
		try {
			PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddImageExample.pdf"));
			document.open();
			document.add(new Paragraph("Image Example"));

			Image image1 = Image.getInstance("Tick.jpg");
			image1.setAbsolutePosition(100f, 550f);
			image1.scaleAbsolute(200, 200);

			document.add(image1);
			String imageUrl = "http://www.eclipse.org/xtend/images/java8_logo.png";
			Image image2 = Image.getInstance(new URL(imageUrl));
			document.add(image2);

			document.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
                /* ............... END ............... */
        

Output


Add Images To PDF In Java Using iText

Tags

Add Images To PDF, iText, Java

Similar Programs Chapter Last Updated
Java Set Background To Table Example iText 22-07-2017
Java PDF Hello World Example iText 14-08-2016
Java PDF Formatting Using iText iText 14-08-2016
Read Existing PDF In Java iText 14-08-2016
Read OR Modify PDF File In Java Using iText iText 12-08-2016
PDF With Limited Permissions In Java Using iText iText 12-08-2016
Password Protected PDF Files Using Java iText iText 12-08-2016
Styling Or Formatting PDF In Java Using iText iText 11-08-2016
Create Lists In PDF Using Java iText iText 10-08-2016
Create Tables In PDF Using Java iText iText 10-08-2016
File Attributes To PDF In Java Using iText iText 10-08-2016
PDF Creation In Java Using iText iText 10-08-2016

1