tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 PDF > iTEXT > Font Style

Font Style 

iText is a free and open source library for creating and manipulating PDF documents in Java. The following example shows adding styled font to PDF document.

File Name  :  
com/bethecoder/tutorials/itext/tests/FontTests.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.itext.tests;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class FontTests {

  /**
   @param args
   @throws DocumentException 
   @throws FileNotFoundException 
   */
  public static void main(String[] argsthrows FileNotFoundException, DocumentException {

    Document document = new Document(PageSize.A4)
    PdfWriter.getInstance(document, new FileOutputStream("test4.pdf"));
    
    //Open the document before adding any content
    document.open();
    
    Font myFonColor = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24, Font.BOLD, BaseColor.GREEN);
    Paragraph paragraph = new Paragraph("BE THE CODER", myFonColor);
    document.add(paragraph);
    
    //Close the document
    document.close();
  }

}
   

It gives the following output,
test4.jpg


 
  


  
bl  br