// in_cell.java

import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class in_cell
{
    static void writeMsg(Document document, String str) throws DocumentException
    {
        Font f = new Font(Font.HELVETICA, 12);
        document.add(new Paragraph(new Chunk(str + "\n\n", f)));
    }

    static void write1(int size, Document document) throws DocumentException
    {
        writeMsg(document, "Method 1, size " + size);
        Font f1 = new Font(Font.HELVETICA, size);
        Paragraph par = new Paragraph(new Chunk("In cell\nIn cell\nIn cell", f1));
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell();
        cell.addElement(par);
        table.addCell(cell);
        table.addCell(cell);
        document.add(table);
    }

    static void write2(int size, Document document) throws DocumentException
    {
        writeMsg(document, "Method 2, size " + size);
        Font f1 = new Font(Font.HELVETICA, size);
        Paragraph par = new Paragraph(new Chunk("In cell\nIn cell\nIn cell", f1));
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell(par);
        table.addCell(cell);
        table.addCell(cell);
        document.add(table);
    }

    public static void main(String[] args)
    {
        try
        {
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            PdfWriter writer = PdfWriter.getInstance(document,
                    new FileOutputStream("in_cell.pdf"));
            document.open();
            Font f1 = new Font(Font.HELVETICA, 12);

            write1(10, document);
            write2(10, document);
            write1(36, document);
            write2(36, document);

            document.close();

            System.out.println("Done.");

        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}