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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Phrase 
 

In this section, you will learn how to design some text according to our need by use of Phrase. We can format our pdf by using Phrase() constructor.

 

Phrase   

                         

In this section, you will learn how to design some text according to our need by use of Phrase. We can format our pdf by using Phrase() constructor.
 We can add the text, Chunk and set the font size , name and style of the font.

Code Description:

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

Phrase:
The class Phrase is used as render of process. This class comes under the  com.lowagie.text.Phrase. The Phrase   extends ArrayList
 and it implements the TextElementArray . A Phrase is a series of Chunks.  A Phrase has a main Font, but some chunks within the phrase
 can have a Font that differs from the main Font. All the Chunks in a Phrase have the same leading.e.g.

// Passed as a parameter with the default leading = 16
 Phrase phrase0 = new Phrase(25, "this is a phrase with leading 16");
//Default Constructor  
 Phrase phrase1 = new Phrase();
//Passing String
 Phrase phrase2 = new Phrase("this is a phrase");
  // Font is passed (explicitely or embedded in a chunk), the default leading = 1.5 * size of the font
 Phrase phrase3 = new Phrase("this is a phrase with a red, normal font Courier, size 12", 
FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, new Color(255, 0, 0)));
//Passing Chunk 
 Phrase phrase4 = new Phrase(new Chunk("this is a phrase"));
//Passing Chunk,Font with the default leading = 18
 Phrase phrase5 = new Phrase(18, new Chunk("this is a phrase", FontFactory.getFont(FontFactory.HELVETICA,
 16, Font.BOLD, new Color(255, 0, 0)));
 


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.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class Phrases {
  public static void main(String[] args)throws Exception 
                   {
    System.out.println("Phrases");
    Document document = new Document();
    PdfWriter.getInstance(document, 
new 
FileOutputStream("Phrasespdf.pdf"));
                  document.open();
      Phrase phrase0 = new Phrase();
      Phrase phrase1 = new Phrase("This
 is a phrase\n"
);
      Phrase phrase2 = new Phrase(25,"This 
is a phrase with leading 25. \n"
);
      Phrase phrase3 = new Phrase("This is a 
phrase with a red, normal font 
Courier20"
,    FontFactory.getFont(
FontFactory.COURIER, 
20,
 Font.NORMAL,new Color
(25500)));
Phrase phrase4 = new Phrase(new 
Chunk("(4) this is a phrase\n"));
Phrase phrase5 = new Phrase(18,
new Chunk
("This is a phrase in Helvetica, bold,
 red and size 16 with a given leading 
of 18 points.\n"
,FontFactory.getFont
(
FontFactory.HELVETICA, 16,Font.BOLD, 
new Color(25500))));
      Chunk chunk = new Chunk("
 This is a font: "
);
Phrase phrase6=new Phrase();
phrase6.add(chunk);
      phrase6.add(new Chunk("Helvetica"
FontFactory.getFont
(
FontFactory.HELVETICA, 12)));
      phrase6.add(chunk);
      phrase6.add(new Chunk("ZapfDingBats",
 FontFactory.getFont
(
FontFactory.ZAPFDINGBATS, 12)));
      Phrase phrase7 = new Phrase
(
"If you don't add a newline !");
      document.add(phrase1);
      document.add(phrase2);
      document.add(phrase3);
      document.add(phrase4);
      document.add(phrase5);
      document.add(phrase6);
      document.add(phrase7);    
    document.close();
  }
}

The output of the program is given below:

Download this example.

 

                         

» View all related tutorials
Related Tags: c web pdf file stl text application import jar diff io make packages port this package itext app if tex

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.