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

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.

                         

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:
How do you sort an arr
reading and writing ex
abstrct path name of f
<form: checkbox path=
spring:html tags examp
tokenizer
frame in html
jdbc with ms access
set colours Jtree
Insert path file into
hiding message box in
sum servlets program
ASP.NET .NET Security
user registration and
puzzle game in java
multiple ajax combo
input in java
java: read string arra
Text Field Midlet Exam
text editor wiyh menu
8 puzzle game in java
how to get applicate s
C and Cpp Programming
how to apend a file
Count Records using th
Hibernate Mapping
swap arrays in java

Java I/0 Examples
blob
File size in MB
how to pass same varia
param-name
eXist
login authentication
Photoshop Abstracts Ab
Photoshop Effects Abst
rest
websphere
Database MySQL Using S
invokeLater
pdf to xml using java
toString
Hibernate with DAO
pdf
array in javascript
jasper
code to convert pdf fi
jsp bean
login eample code usin
context attribute of a
populate dropdown in j
pl/sql
different uml technolo
call ?¢????¢??¬???Â
hiding frame in jsp
jndi and java lookup
lookupDispatchAction f
h:message
SortIt
Flash Animation Animat
changepassword
Handling Multiple Subm
drop down in jsp
Hash maps in struts2
delete data in mysql d
code to store a string
ascii
array java
usebean tag in jsp
matcher
jasper report
creating com object
Submit comments in dat
code to make text box
line break in javascri
sort collection
swings tutorial
Mysql and jsp
Date
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.