create Multiple Lines

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

create Multiple Lines

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

create Multiple Lines

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.