Java Programing laungage

iText Projects

iText Project 1

Font type using iText for PDF File
Previous Home Next

By the help of this program I am trying to show you how we can set the Font type in PDF file. This means that if we want to set the different font type like "times new roman", "Arial", "verdana" etc.

On a page with different line of text in PDF file, so the iText jar file provide this facility. For performing this task firstly we are import to the iText.jar file and some packages like com.lowagie.text.pdf.FontSelector;, com.lowagie.text.Font; and com.lowagie.text.phrase;. After import of the package we are going to initialized to the document into the PDF file. Then apply for font type.


package r4r;
import com.lowagie.text.*;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.FontSelector;
import com.lowagie.text.pdf.PdfWriter;

public class fonttypetest 
public static void main(String[] args)throws Exception
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, 
new FileOutputStream("fontselection.pdf"));; 
String input = "R4R is free tutorials site for the java professonals";
FontSelector fontselector = new FontSelector();
fontselector.addFont(new Font(Font.COURIER, 10));
fontselector.addFont(new Font(Font.TIMES_ROMAN, 10));
fontselector.addFont(new Font(Font.SYMBOL, 10));
Phrase ph = fontselector.process(input);
document.add(new Paragraph(ph));
Previous Home Next