Hi again.
 Because of the mail size constraint, i am not able to attach the code in my
previous post.
Following is the code:


import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Adds a table to a page twice.
 */
public class Tables {

 /**
  * Adds a table to a page twice.
  *
  * @param args
  *            no arguments needed
  */
 public static void main(String[] args) {

  Font font8 = FontFactory.getFont(FontFactory.HELVETICA, 8);

  // step 1
  Document document=new Document(PageSize.LETTER, 30, 40, 168, 100);

  try {
   // step 2
   PdfWriter writer = PdfWriter.getInstance(document,
     new FileOutputStream("tables.pdf"));

   //float width = document.getPageSize().getWidth();
   //float height = document.getPageSize().getHeight();

   float width = 300;
   float height = 500;
   // step 3
   document.open();
   writer.setPageEvent(new testHeaderFooter());
   // step 4
   float[] columnDefinitionSize = { 33.33F,33.33F, 33.33F, 33.33F };

   float pos = height / 2;
   PdfPTable table = null;
   PdfPCell cell = null;

   table = new PdfPTable(columnDefinitionSize);
   //table.getDefaultCell().setBorder(1);
   table.setHorizontalAlignment(0);
   table.setTotalWidth(width - 72);
   table.setLockedWidth(true);
   table.getDefaultCell().setColspan(4);
   table.getDefaultCell().setBorderWidth(1);
   table.addCell(new Phrase("Table added with writeSelectedRows"));



   table.getDefaultCell().setColspan(0);
   //table.getDefaultCell().setBorder(1);
   table.getDefaultCell().setBorderWidth(1);
   table.addCell(new Phrase("Name"));
   table.addCell(new Phrase("Degree"));
   table.addCell(new Phrase("College"));
   table.addCell(new Phrase("Completed In"));
   table.setHeaderRows(2);
   int pageNumber = 1;
   String[] arr= {"Ramesh","Srinivas"};
   for(int i=0;i<arr.length;i++)
   {
    pageNumber = document.getPageNumber();
    table.getDefaultCell().setColspan(0);
    //table.getDefaultCell().setBorder(Rectangle.RIGHT);
    //table.getDefaultCell().setBorderWidth(1);
    table.addCell(new Phrase(arr[i]));
    table.getDefaultCell().setColspan(3);
    table.getDefaultCell().setBorderWidth(1);
    //table.setHeaderRows(1);
    PdfPTable subTable = new PdfPTable(3);
    for(int j = 0;j<4;j++)
    {

     System.out.println("before i is "+i+" j is "+j+" txt is "+arr[i]);
     System.out.println("docu pageNumber is "+document.getPageNumber()+"
pageNumber is "+pageNumber);
     System.out.println("after i is "+i+" j is "+j+" txt is "+arr[i]);
     subTable.getDefaultCell().setBorder(Rectangle.RIGHT);
     subTable.getDefaultCell().setBorderWidth(1);
     subTable.addCell(new Phrase("MSc(I.T)", font8));
     subTable.addCell(new Phrase("DR.M.G.R Engg.College", font8));
     subTable.addCell(new Phrase("2002-04-
alksdfjsadfsajdfklasdjflksadjfskladfjlaskdjfklsadjfsdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsflaskdfjlaskdfjlaskdjflaskfjlkasjdflskajflksajflkasjflkasjlkasjdflkasjdflkasjdflksdjflsakfjlaskdfjlaskdjflskadjflaksdfjlkasjflkasdjflaskdjflsakdjf",
font8));
     PdfPCell newspace = new PdfPCell();
     newspace.setBorder(Rectangle.RIGHT);
     newspace.setBorderWidth(1);
     subTable.addCell(newspace);
     subTable.addCell(newspace);
     subTable.addCell(newspace);

    }
    table.addCell(subTable);
   }
   document.add(table);




   //table.writeSelectedRows(0, -1, 50, pos, writer.getDirectContent());

  }

  catch (DocumentException de) {
   System.err.println(de.getMessage());
  } catch (IOException ioe) {
   System.err.println(ioe.getMessage());
  }
  // step 5
  document.close();
 }

 private static class testHeaderFooter extends PdfPageEventHelper
 {

  public void onEndPage(PdfWriter writer, Document document){
    document=new Document(PageSize.LETTER, 22, 40, 125, 130);
   try{
    PdfPTable testHeader = new PdfPTable(2);
    testHeader.setWidthPercentage(100);
    testHeader.setTotalWidth(document.getPageSize().width() -
document.leftMargin() - document.rightMargin());
    testHeader.addCell(new Phrase("Ramesh"));
    testHeader.addCell(new Phrase("Soma"));
    System.out.println("left "+document.leftMargin()+" up
"+document.topMargin());
    testHeader.writeSelectedRows(0, -1, document.leftMargin()-15, 750,
writer.getDirectContent());
    //document.add(testHeader);


    PdfPTable testFooter = new PdfPTable(1);
    testFooter.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    testFooter.addCell(new Phrase("Page End"));
    testFooter.setTotalWidth(document.getPageSize().width() -
document.leftMargin() - document.rightMargin());
    testFooter.writeSelectedRows(0, -1, document.leftMargin(),
document.bottomMargin()+10, writer.getDirectContent());
    //document.add(testFooter);
   }catch(Exception e)
   {
    e.printStackTrace();
   }
  }

 }
}



On 3/14/08, Ramesh Soma <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I am new to the iText.
> I have a scenerio, like For a person, we have to show up his education
> history.
> In a table of 4 columns(Name,Degree,College/School,Completed In), Name of
> the student will appear in one column and i want the rest of the cells will
> be filled by his education history. Name of the student will be displayed
> one time for all his eduction history.
>
>  Please refer the attached ppt for my problem. I am not able to explain
> what i need. I explained clearly in the attached ppt.
>
> Appriciate your help.
>
> Thanks.
>
>
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to