sujikin wrote:
But in practise draws one, draws another and never draws the previous
one..keep on drawing second one..

Any clue why so?

Because you didn't read the documentation.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;


public class CellEventTest {
        class DottedLine implements PdfPCellEvent {
                public void cellLayout(PdfPCell cell, Rectangle position,
                                PdfContentByte[] canvases) {

                        // TODO Auto-generated method stub
                        PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
                        cb.saveState();
                        cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
                        cb.setLineDash(0, 5, 1);
                        cb.moveTo(position.getLeft(), position.getBottom());
                        cb.lineTo(position.getRight(), position.getBottom());
                        cb.stroke();
                        cb.restoreState();

                }

        }

        class SimpleLine implements PdfPCellEvent {
                public void cellLayout(PdfPCell cell, Rectangle position,
                                PdfContentByte[] canvas) {
                        // TODO Auto-generated method stub
                        PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
                        cb.saveState();
                        cb.setLineWidth(0.5f);
                        cb.moveTo(position.getLeft(), position.getBottom());
                        cb.lineTo(position.getRight(), position.getBottom());
                        cb.stroke();
                        cb.restoreState();
                }

        }

        public static void main(String[] args) throws IOException,
                        DocumentException {
                Document document = new Document(PageSize.A4.rotate());
                String fileName = "test.pdf";
                PdfWriter.getInstance(document, new FileOutputStream(fileName));
                document.open();
                DottedLine dot = new CellEventTest().new DottedLine();
                SimpleLine simple = new CellEventTest().new SimpleLine();
                PdfPTable table = new PdfPTable(6);
                PdfPCell cell;
                for (int i = 1; i <= 30; i++) {
                        cell = new PdfPCell(new Phrase("day " + i));
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setBorder(Rectangle.NO_BORDER);
                        cell.setPadding(4);
                        // cell.setCellEvent(border);
                        if (i % 4 == 0)
                                cell.setCellEvent(dot);
                        else if (i % 3 == 0)
                                cell.setCellEvent(simple);
                        table.addCell(cell);
                }
                document.add(table);
                document.close();
        }

}
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to