Share on Google+Share on Google+

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:

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.

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.

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.

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 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
 Chunk underlined = new Chunk("Rose India-->>underlined");
  underlined.setUnderline(0.2f, -2f);
  Paragraph p = new Paragraph("The following chunk is ");
  Chunk strikethru = new Chunk("Rose India-->>Strike");
  Chunk c;
  c = new Chunk("rose India-->>Multiple lines");
  c.setUnderline(new Color(0xFF0x0f0x0f)0.0f0.3f0.0f0.4f
  c.setUnderline(new Color(0x0f0xFF0x0f)5.0f0.0f0.0f, -0.5f
  c.setUnderline(new Color(0x000x0f0xFF)0.0f0.2f15.0f0.0f
  c = new Chunk("Multiple lines", FontFactory.getFont(FontFactory.
  c.setUnderline(new Color(0xFF0x0f0x00)0.0f0.3f0.0f0.4f
  c.setUnderline(new Color(0x0f0xF00x00)5.0f0.0f0.0f, -0.5f,
  c.setUnderline(new Color(0x0f0x0f0xFF)0.0f0.2f15.0f0.0f

The output of the program is given below:

Download this example.



Posted on: April 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: create Multiple Lines  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image