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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
create Multiple Lines 
 

In this section, you will see how to create multiple lines in java.

 

Create Multiple Lines   

                         

iText APIs provides facility to  make the lines. In this program we are going to tell you how you can make single  lines and how you can make multiple lines on the text in pdf files. You can make multiple lines and also make colorful lines by using this example.

In this example we are making an object of Chunk. Then set under line, using setUnderLine( float f, float f) method. For new line we use Chunk.NEWLINE. We are also creating colorful lines.

Code Description:

Following methods are used for creating multiple and colorful lines:

Chunk.NEWLINE:
This method is used to a make new line.

Chunk.setUnderLine(Color color, float thickness, float thicknessmul, float y, float ymul, int cap):
This method is used to create a colorful line. You can set thickness and y position of the text where the line will be seen. When you increase it's value then the line will be seen towards the top of the text and the line will be seen towards the bottom of the text when you decrease the value. You can understand better changing it's value. Inside the method, parameter thicknessmul is used for setting line thickness according to the font size. You can also set ypositionmul for setting the line position on text towards the top or bottom. It is also a multiplication factor with the font size. Integer type value cap is used to set the line at beginning and ending point of the line.

PdfContentByte.LINE_CAP_PROJECTING_SQUARE:
This is projecting square cap. The stroke continues beyond the endpoint of the line. It's value is equal to 2 that is of integer type.

PdfContentByte.LINE_CAP_BUTT:
This is Butt Cap. This stoke is squared off the endpoint of line. There is no projection beyond the end of the line. It's value is equal to 0 that is of integer type.

PdfContentByte.LINE_CAP_ROUND:
This is Round Cap. A semicircular arc with a diameter equal to the width is drawn around the endpoint and filled in. It's value is 1 that is of integer type.

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.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class Lines
 {
  public static void main(String[] args)throws Exception
               {
    System.out.println("Underline, Strike through,...");    
    Document document = new Document();      
    PdfWriter.getInstance(document,new FileOutputStream
(
"Linespdf.pdf"));
      document.open();
             Chunk underlined = new Chunk("Rose India-->>underlined");
      underlined.setUnderline(0.2f, -2f);
      Paragraph p = new Paragraph("The following chunk is ");
      p.add(underlined);
      document.add(p);
      Chunk strikethru = new Chunk("Rose India-->>Strike");
      strikethru.setUnderline(0.5f3f);  
      document.add(strikethru);
      document.add(Chunk.NEWLINE);
      document.add(Chunk.NEWLINE);
      document.add(Chunk.NEWLINE);
      Chunk c;
      c = new Chunk("rose India-->>Multiple lines");
      c.setUnderline(new Color(0xFF0x0f0x0f)0.0f0.3f0.0f0.4f
PdfContentByte.LINE_CAP_ROUND
);
      c.setUnderline(new Color(0x0f0xFF0x0f)5.0f0.0f0.0f, -0.5f
PdfContentByte.LINE_CAP_PROJECTING_SQUARE
);
      c.setUnderline(new Color(0x000x0f0xFF)0.0f0.2f15.0f0.0f
PdfContentByte.LINE_CAP_BUTT
);
      document.add(c);
      document.add(Chunk.NEWLINE);
      document.add(Chunk.NEWLINE);
      document.add(Chunk.NEWLINE);
      c = new Chunk("Multiple lines", FontFactory.getFont(FontFactory.
HELVETICA, 
24));
      c.setUnderline(new Color(0xFF0x0f0x00)0.0f0.3f0.0f0.4f
PdfContentByte.LINE_CAP_ROUND
);
      c.setUnderline(new Color(0x0f0xF00x00)5.0f0.0f0.0f, -0.5f,
 PdfContentByte.LINE_CAP_PROJECTING_SQUARE
);
      c.setUnderline(new Color(0x0f0x0f0xFF)0.0f0.2f15.0f0.0f
PdfContentByte.LINE_CAP_BUTT
);
      document.add(c);
      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.