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

Chunk Example 

iText is a free and open source library for creating and manipulating PDF documents in Java. The following example shows adding a Chunk to PDF document which is the smallest unit of text that can be added to a PDF.

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


import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
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 ChunkExample {

   @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("test22.pdf"));
    //Open the document before adding any content;
    Paragraph paragraph = new Paragraph("BE THE CODER");
    paragraph.add("\n");  //new line
    //the smallest significant part of text that can be added to a document
    Chunk chunk = new Chunk("be the coder",
        FontFactory.getFont(FontFactory.COURIER, 16
            Font.ITALIC, BaseColor.BLUE));
    //Close the document


It gives the following output,


bl  br