Hi..

I am trying to create a table with round corners.
i got the desired out put. but once i tried to set the header for the table, i am getting a square header which is not fitting to the round corners of the table.  Kindly look into this and give me solutions for the same.  i am sending the code also.



    public static void main(String args[]) {
        try {
            Document doc = new Document ();

            PdfWriter pwriter=PdfWriter.getInstance(doc, new FileOutputStream("MyRectangle.pdf"));

            doc.open ();

            PdfPTable mainTable = new PdfPTable(1);

            PdfPTable table = new PdfPTable(5);

            table.getDefaultCell().setBorder(0);


            mainTable.getDefaultCell().setBorder(0);
          

            addReportHeader("Campaign",mainTable,25);

            mainTable.setHeaderRows(1);

            ExecutiveSummaryTableEventHelper event = new ExecutiveSummaryTableEventHelper();

            mainTable.setTableEvent(event);

            for (int k = 1; k <= 100; ++k) {
                table.addCell("The number " + k);
            }

            mainTable.addCell(table);

            doc.add(mainTable);

            doc.close ();

        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
    }
    /**
     * @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
     */
    public void tableLayout(PdfPTable table, float[][] width, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {

        // widths of the different cells of the first row
        float widths[] = width[0];
        PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
        cb.saveState();
        // border for the complete table
        cb.setLineWidth(1);

        cb.setRGBColorStroke(0, 0, 0);
        cb.roundRectangle(widths[0], heights[heights.length - 1], widths[widths.length - 1] - widths[0], heights[0] - heights[heights.length - 1],7f);
        cb.stroke();
        cb.restoreState();

    }
    static void addReportHeader(String value, PdfPTable table,
             float height)
             {

        PdfPCell cell = new PdfPCell(new Phrase(value, new Font(Font.HELVETICA,
                10, Font.BOLD, Color.RED)));

     cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBackgroundColor(Color.LIGHT_GRAY);

        cell.setFixedHeight(height);
        cell.setBorder(5);


        table.addCell(cell);
    }

}


Reply via email to