Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

 

                         

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 
Latest Searches:
Photoshop Text Effects
validate radio button
drop down in jsp
TextField
flex datagrids
sum of rows and coloum
display
multiple submit button
user registration
jsp bean
java example program t
populate drop down fro
vector in java
Struts Validator Frame
java xml
Get Array List in a JS
Add listener to compon
distinct
game in java
how to pass same varia
jQuery To Hide the Div
rotate
Why Virtual Dedicated
runnable
how to execute update
helloe world servlet
t:htmltag
JSP:File Input Paramet
Check Box (Form Tag) E
FCKediter
2 tier ,3 tier ,n tier
user registration and
pthread.h
where we place plug-in
create table in struts
if not null condition
abstrct path name of f
howtodeclareanarrayinj
JPOX
dynamic insert value J
How to show expression
populate drop down fro
file input output
dwr reverse ajax
b tree implementation
jboss seam
iBatis Stored Procedur
Photoshop Effects Sig
using set in java
date of birth
swing
session jsp
find and replace bytes
Photoshop Color Colori
<c:if
Passing Parameters in
width
ASP EXAMPLE and 1=2
Photoshop Text Effects
Get Image
MULTIPLE SELECT COMBO
dojo debug
call ejb j2ee5
JSF tree collapse
spring MVC application
strating a thread in j
jar entry
objective
set colors to Jtree
Java Database Related
*copyvalueof
DOWNLOAD JAVA HOME DIR
flex
count the number of di
java nodequeue tutoria
myfaces tomahawk
java date compare exam
Developing JSP files
read hexadecimal from
free source jsp n serv
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.