Home Java Itext different Font



different Font
Posted on: April 17, 2007 at 12:00 AM
Here, you will learn about different fount in java.

different Font 

     

In this program, we are going to give you an example that helps you for the procedure of using various fonts in a pdf document. Here, add(object) method of the Paragraph class is used to add text and it's font name with size.

Code Description:

The following method and fields are used for creating multiple colorful fonts.

add(Chunk chunk,Font font): The add method is used to add the chunk text and name of font with font size.

Following are some font name used in the given program:

  1. Font.ZAPFDINGBATS
  2. Font.TIMES_ROMAN
  3. Font.SYMBOL 

The code of the program is given below:

ing="0" bgcolor="#ffffcc">
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class exampleOfDifferentFonts{
  public static void main(String[] argsthrows Exception{  
  Document document = new Document();
  
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("differentfontspdf.pdf"));
  document.open();
  Paragraph p = new Paragraph();
  p.add(new Chunk("This text is in Times Roman. "
new 
Font(Font.TIMES_ROMAN, 12)));
  p.add(new Chunk("This is ZapfDingbats: "
new 
Font(Font.ZAPFDINGBATS, 12)));
  p.add(new Chunk(". This is font Symbol: "
new 
Font(Font.TIMES_ROMAN, 12)));
  p.add(new Chunk("This text is in Times Roman."
new Font(Font.SYMBOL, 12)));
  document.add(new Paragraph(p));
  document.close();
  }
}

The output of the program is given below:

Download this example.

 

Related Tags for different Font:
ctextparametersdiffgraphfontparameterintthisiftexexampleaddprogramtoramexamextecanparagraphusefirstinpassdifferentasmntparcaddadmehowintoproparamxaxampskisirmeterivmplgoandarxttwssrenthcondstapfepleplprndonogro


More Tutorials from this section

Ask Questions?    Discuss: different Font  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.