Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

changing Background Color

                         

In this program, we are going to tell you how you can change background color of a pdf file. You can change the background color of any chunk with the help of setBackground(Color color)

In this example, we are creating a chunk then we use setBackground(Color color) to set the background color of that chunk. Here we pass the object of Color by using
new Color(0xFF, 0xFF, 0x00). We are passing three hexadecimal values into the Color constructor. Which is used to create the object of the Color. 

Code Description:

setBackground(Color color):
 
If you want to change the background color  then we use this method. This method is used to change the color of  chunk of text into the chunk object. We use this for set the background color of any text.

setTextRise(float):
There are some methods that can be invoked on a Chunk. The method setTextRise(float f)is used to write the chunks  in super or subscript.

The code of the program is given below:

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class changeBackgroundColor {
 public static void main(String[] args)throws Exception {
    System.out.println("Background color");
           Document document = new Document();
    PdfWriter.getInstance(document,new FileOutputStream
(
"cahngeBackgroundColor.pdf"));
      document.open();
      Chunk chunk =new Chunk("RoseIndia.net")
      chunk.setBackground(new Color(0xFF0xFF0x00));
      Paragraph paragraph = new Paragraph("The following chunk is ");
      paragraph.add(chunk);
      document.add(paragraph);
      Chunk chunk2,chunk3;
      chunk2 = new Chunk("RoseIndia.net");
      chunk2.setBackground(new Color(0xb00xb00xb0));
      document.add(chunk2);
      chunk3 = new Chunk("RoseIndia.net");
      chunk3.setTextRise(8);
      chunk3.setBackground(new Color(0xFF0xDE0xAD));
                        document.add(chunk3);      
                  document.add(paragraph);
            document.close();
  }
}

The output of the program is given below:

Download this example.

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
b tree implementation
url
covertir texte to bina
pagination
free download of java1
Photoshop Digital Art
websphere portals
sample projects on jsp
oracle.jdbc.driver.Dat
use dropdownlist in js
list iteration in java
Java Bitwise XOR
login eample code usin
selection model
heap sorting
optgroup
swing close button
Class
Error handling in stru
callablestatement
action
soket programming
request_locale
relative
Statless session bean
getter setter methods
Java Count Vowels
Downloading and Instal
adding label and textb
fireTableCellUpdated
Photoshop Abstracts Ab
diff b/w function and
default path
ASP Form Processing Se
telephone
Swing component for en
tree component web jav
binary recursion
Creating a DSN for MyS
source code of game i
Action list
connection between jdb
read from file
valueChangeListener
max length 500 chars
hostname
decimal to ANSI
canonical
XML validation in Stru
jasper reports using j
source code of puzzle
game in java
primitive data types u
jsp codes
file to string
@Results annotation in
<s:text> example
Photoshop Photo Effect
jsp in ibm websphere
Initialization
request.setAttribute
jsp value to javascrip
Xml jsp ajax
default directory
struts2 radio button
displyand store the im
text editor
parse a int to string
jsp to microsoft sql
j2me Collection
ASP Database Related U
Java Write To File in
IBM MQ series
convert object into in
scroll bar
give the input text fi
byte
Combo Box operation in
Containers
input in array
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.