Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Font Selection 
 

Here, you will learn by trying the following example that is given ahead. This example uses the static font name for the pdf content particularly by using addFont() method of the FontSelector class.

 

Font Selection  

                         

In this section, you will learn how to design some text according to you. That means if you want to keep some text in different font like "Times TIMES_ROMAN", "ZAPFDINGBATS" etc. particularly. When you create a pdf through the Java Program then you have to decide the specific font name for the specific text from the pdf content and the font name has to be mentioned in the java code during the creation of the pdf whether it is static (hard-coded) or dynamic.

Here, you will learn by trying the following example that is given ahead. This example uses the static font name for the pdf content particularly by using addFont() method of the FontSelector class.

Code Description:

To select  font   iText provides a constructor named as FontSelector() and  the addFont() method of the FontSelector class to add the fonts for selecting and change it's font by the specified font name.

There some package used in the program for the purpose. These are as follows:

  1. import com.lowagie.text.Font;
  2. import com.lowagie.text.pdf.FontSelector;
  3. import com.lowagie.text.Phrase; 

In this example, we have taken a String type variable input that is initialized with some text and Unicode. The input variable is passed through the process() method of the FontSelector class for applying the specified font name and size on the pdf content. The Unicode is converted into symbol after processing.

All the APIs used in the code of the program are derived here:

FontSelector: This is the class of iText api used for selecting fonts for the text it extends Object class. FontSelector class comes under com.lowagie.text.pdf package.

addFont(Font f): The addFont(Font f) method is used to add font into font selector object its return type is void.

process
(String input) method: The process(String input) is use to process the font on the text .Its return type is Phrase.

Phrase:
The class Phrase is used as render of process. This class comes under the com.lowagie.text.Phrase.

The code of the program is given below:

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.FontSelector;
import com.lowagie.text.pdf.PdfWriter;
public class FontSelection {   
    public static void main(String[] args)throws Exception
               {        
            Document document = new Document();
            PdfWriter writer = PdfWriter.getInstance(document, 
new 
FileOutputStream("fontselection.pdf"));
            document.open();         
            String input = "Rose india is a  \u275d java \u275e site. 
                            Roseindia provide  "
"online \u2798 tutorial
                            \u279a of core java,j2ee,jsp and strust.\n\n"

            "\u2766\u00a0\u0ea0\u039c\u03c7\u03bd\u03b9\u0dbd \u03b1\
u03b5\u03d9\u0db4\u02b5, \u03b1\u03b5\u0311, \u03a0\u03b7\u03bb\u03b7
\u03b1\u0db1\u03b4\u03b5\u02c9 \u0391\u03c7\u03b9\u03bb\u03b7\u03bf\u03c2"
;
            FontSelector fontselector = new FontSelector();
            fontselector.addFont(new Font(Font.TIMES_ROMAN, 12));
            fontselector.addFont(new Font(Font.ZAPFDINGBATS, 12));
            fontselector.addFont(new Font(Font.SYMBOL, 12));
            Phrase ph = fontselector.process(input);
            document.add(new Paragraph(ph));
            document.close();
        
    }
}

The output of the program is given below:

Download this example.

                         

» View all related tutorials
Related Tags: c perl com pdf file data print command tutorial int ria this write prompt example to exam e il it

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 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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 | Flex 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.