Java Programing laungage

iText Projects

iText Project 1

adplus-dvertising
Change Background Color in PDF file
Previous Home Next

By the help of this program I am trying to show you how we can change the background color in PDF file. For performing this task firstly we are import to the iText.jar file and some packages like com.lowagie.text.pdf.*, com.lowagie.text.*.

After import of the package we are going to initialized to the document into the PDF file. Then apply the setBackground(Color color) method for changing the color.

Example:

package r4r;
import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class changebackgroundtest 
	{
public static void main(String[] args)throws Exception 
	{
System.out.println("The Background color is");
Document doc = new Document();
PdfWriter.getInstance(doc,new FileOutputStream
("cahngeBackgroundtest.pdf"));

doc.open();
Chunk ch =new Chunk("Welcome in java world"); 
ch.setBackground(new Color(0xFE, 0xFE, 0x00));
Paragraph par = new Paragraph("The chunk is ");
par.add(ch);
doc.add(par);
Chunk ch2,ch3;
ch2 = new Chunk("Welcome in R4R tutorials");
ch2.setBackground(new Color(0xb0, 0xb0, 0xb0));
doc.add(ch2);
ch3 = new Chunk("Hello");
ch3.setTextRise(10);
ch3.setBackground(new Color(0xFF, 0xDE, 0xAD));
doc.add(ch3);
doc.add(par);
doc.close();
}
}
Previous Home Next