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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Make Paragraph and Set Alignment 
 

In this example , we are going to explain how we can make paragraph and how we can gives various alignment. To make a paragraph we use Paragraph("Text") constructor . To gives alignment we use setAlignment(int alignment).

 

Make Paragraph and Set Alignment     

                         

In this example , we are going to explain how we can make paragraph and how we can gives various alignment. To make a paragraph we use Paragraph("Text") constructor . To gives alignment we use setAlignment(int alignment).

Code Description:

setAlignment(int alignment):

We can set the aligment of a Paragraph with the method setAlignment(int alignment). The alignment can be one of the following values:

  1. Element.ALIGN_LEFT
  2. Element.ALIGN_CENTER
  3. Element.ALIGN_RIGHT
  4. Element.ALIGN_JUSTIFIED
If you want the alignment to be justified, the space between the words can be stretched, as well as the space between the characters of a word. The default ratio of this word-char space is 2.5. You can change this ratio with setSpaceCharRatio. For instance, if you don't want the space between the characters of a word to be stretched, just do:
writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);

The code of the program is given below:

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class ParagraphAttributes 
                  {
    public static void main(String[] args)throws Exception 
                  {
            System.out.println("The Paragraph object");
                        Document document = new Document();
            PdfWriter.getInstance(document, new 
FileOutputStream("ParagraphAttributes.pdf"));
      document.open();
      Paragraph[] p = new Paragraph[5];
                        p[0new Paragraph("RoseIndia.net");
                        p[1new Paragraph("RoseIndia.net");
                        p[2new Paragraph("RoseIndia.net");
                        p[3new Paragraph("RoseIndia.net");
                        p[4new Paragraph("RoseIndia.net");
       for (int i = 0; i < 5; i++)
              {
              p[i].setAlignment(Element.ALIGN_JUSTIFIED);
              document.add(p[i]);
              }
                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.