In this core java tutorial we will learn How To UnderLine Text In Pdf in java using iText library - core java tutorial with program and examples.
Follow these steps to UnderLine Text In Pdf in java using iText library >
- Create new Chunk (Chunk textUnderline = new Chunk("UnderLine Text"));
- Then use textUnderline.setUnderline(0.8f, -1f);
Where, 0.8f is the thickness of underline and -1f is the position of y axis, i.e. where underline will be drawn.
How to create Bar Chart In Pdf in java - iText java tutorial
Create Pie Chart In Pdf in java using itext - iText java tutorial
How to Modify - Add Text To Existing PDF in java - iText java tutorial example
Download jars required to execute program >
Program/Example How To UnderLine Text In Pdf in java - Using iText library
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* How To UnderLine Text In Pdf Using Itext Example -
* Using iText library - core java tutorial
*
*/
public class UnderLineTextInPdfUsingItextExample {
public static void main(String[] args) throws Exception {
String pdfFilePath = "e:/UnderLine Text in Pdf Using Itext Example.pdf";
OutputStream fos = new FileOutputStream(new File(pdfFilePath));
Document document = new Document();
PdfWriter.getInstance(document, fos);
document.open();
document.add(new Paragraph("This is UnderLine Text in Pdf Example"));
Chunk textUnderline = new Chunk("UnderLine Text");
textUnderline.setUnderline(0.8f, -1f); // 0.8f is the thickness of underline
//and -1f is the position of y axis, i.e. where underline will be drawn.
//Just for information
//If you use 2.5f then it form Strikethrough text, try it.
//If you use 10f then it form line above text, try this one too..
document.add(textUnderline);
document.close();
fos.close();
System.out.println("PDF created in >> " + pdfFilePath);
}
}
/* OUTPUT of above program/Example -
PDF created in >> e:/UnderLine Text in Pdf Using Itext Example.pdf
*/
|
PDF formed after executing above java program will look like this >
Summary -
So in this core java tutorial we learned How To UnderLine Text In Pdf in java using iText library - core java tutorial with program and examples.
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
References >
RELATED LINKS>
iText library tutorial in java - How to Create and work with PDF files in java
HEADER and FOOTER in pdf in java - iText tutorial >
How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial
BAR AND PIE CHARTS in pdf in java - iText tutorial >
How to create Bar Chart In Pdf in java - iText java tutorial
Create Pie Chart In Pdf in java using itext - iText java tutorial
MODIFY/ EDIT pdf in java - iText tutorial >
How to Modify - Add Text To Existing PDF in java - iText java tutorial example
How To Read And Add Image To Existing Pdf in java Example - iText java tutorial
Solve common Exceptions in itext in java - iText tutorial >
How to solve the Document Has No Pages IOException in iText in java
Alternates to itext in java - iText tutorial >
What are alternatives to iText library for creating Pdf in java?
Labels:
Core Java
iText Pdf tutorial