Example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell

List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable1(Paragraph preface, String[] Header, String[] Text, String[] Value)
        throws BadElementException {

    Context _con = null;//from   w ww  .  ja v a2 s .  co  m

    PdfPTable table = new PdfPTable(new float[] { 2, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length == Value.length) {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell(Value[i]);
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
            cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    } else {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell("");
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        }
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable2(Paragraph preface, String[] Header, String[] Text, String[] Source,
        String[] Value) throws BadElementException {

    Context _con = null;//  ww  w  . j a  v a 2 s.com

    PdfPTable table = new PdfPTable(new float[] { 2, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length == Value.length) {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell(Source[i]);
            table.addCell(Value[i]);
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
            cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
            cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    } else {
        for (int i = 0; i < Value.length; i++) {
            Phrase phrase = new Phrase();
            phrase.add(new Chunk(Text[i], subFont));
            table.addCell(phrase);
            table.addCell("");
            table.addCell("");
            PdfPCell[] cells1 = table.getRow(i + 1).getCells();
            cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        }
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable3(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2) throws BadElementException {

    Context _con = null;//  www.ja v a  2 s. co  m

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable4(Paragraph preface, String[] Header, String Text, String Value)
        throws BadElementException {

    Context _con = null;//from   www . ja  v  a 2s  . c  om

    PdfPTable table = new PdfPTable(new float[] { 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);

    if (Text.length() > 0 && Value.length() > 0) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell(Value);
        PdfPCell[] cells1 = table.getRow(1).getCells();
        cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell("");
        PdfPCell[] cells1 = table.getRow(1).getCells();
        cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable5(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2, String[] Value3) throws BadElementException {

    Context _con = null;/*from  www .j a v  a  2 s .c  o  m*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
                table.addCell(Value3[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable6(Paragraph preface, String[] Header, String[] Text, String[] Value,
        String[] Value1, String[] Value2, String[] Value3, String[] Value4) throws BadElementException {

    Context _con = null;/*  w  w w .  java2s .  co m*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2, 1, 1, 1, 1 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    table.setHeaderRows(1);

    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));
    }

    dataprovider = new DataProvider(_con);

    if (Text != null && Text.length > 0) {
        if (Text.length == Value.length) {
            for (int i = 0; i < Value.length; i++) {
                table.addCell(Text[i]);
                table.addCell(Value[i]);
                table.addCell(Value1[i]);
                table.addCell(Value2[i]);
                table.addCell(Value3[i]);
                table.addCell(Value4[i]);
            }
        } else {
            for (int i = 0; i < Value.length; i++) {
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
                table.addCell("");
            }
        }
    } else {
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void createTable7(Paragraph preface, String Text, String Value) throws BadElementException {

    Context _con = null;/*from w w  w . j ava  2 s.  c  om*/

    PdfPTable table = new PdfPTable(new float[] { 1, 2 });
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    for (int i = 0; i < 2; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase());
        table.addCell(c1);
    }
    PdfPCell[] cells = table.getRow(0).getCells();
    //        for (int j=0;j<cells.length;j++){
    cells[0].setHorizontalAlignment(Element.ALIGN_LEFT);
    //        }

    dataprovider = new DataProvider(_con);

    if (Text.length() > 0 && Value.length() > 0) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell(Value);
    } else {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(Text, subFont));
        table.addCell(phrase);
        table.addCell("");
    }

    preface.add(table);

}

From source file:com.planning.project.controller.CreatePDF.java

private static void createTable(Document document) throws DocumentException, IOException {
    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);/* w  w  w . j a v  a2 s.  c  om*/

    Paragraph paragraph = new Paragraph();
    paragraph.setFont(font);
    creteEmptyLine(paragraph, 2);
    document.add(paragraph);
    PdfPTable table = new PdfPTable(7);

    paragraph.add("");

    PdfPCell c1 = new PdfPCell(new Phrase("asasas", font));

    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("/?", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("?", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    TbActivity ac = new TbActivity();

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("", font));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    paragraph.add("");

    for (int i = 0; i < 7; i++) {
        table.setWidthPercentage(100);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(paragraph);

    }

    document.add(table);
}

From source file:com.planning.project.controller.CreatePDF.java

public static PdfPTable createtableTargetGroup(TbTargetgroup targetGroup) throws DocumentException, Exception {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);//from w  ww .  j av a 2s .  c  o m

    PdfPTable table = new PdfPTable(3);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    PdfPCell cell = new PdfPCell(new Phrase("? ", font));
    cell.setColspan(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("?()", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(
            " ()", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutMana(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinMana(), font)));

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutTeach(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinTeach(), font)));

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutEmp(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinEmp(), font)));

    table.addCell(new PdfPCell(new Phrase("??", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutStu(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinStu(), font)));

    table.addCell(new PdfPCell(new Phrase("/?", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutCommu(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinCommu(), font)));

    table.addCell(
            new PdfPCell(new Phrase("?/?", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutDisable(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinDisable(), font)));

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutOther(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinOther(), font)));

    return table;
}

From source file:com.planning.project.controller.CreatePDF.java

public static PdfPTable createtableTargetGroup2(TbTargetgroup targetGroup) throws DocumentException, Exception {

    Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    font.setSize(16);/*from   w  w  w.j  a va  2 s  .  c o  m*/

    PdfPTable table = new PdfPTable(3);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    PdfPCell cell = new PdfPCell(new Phrase("?", font));
    cell.setColspan(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase("?()", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(
            " ()", font));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActoutMana(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActinMana(), font)));

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActoutTeach(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActinTeach(), font)));

    table.addCell(new PdfPCell(new Phrase("", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActoutEmp(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActinEmp(), font)));

    table.addCell(new PdfPCell(new Phrase("??", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActoutStu(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinStu(), font)));

    table.addCell(new PdfPCell(new Phrase("?", font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActoutLect(), font)));
    table.addCell(new PdfPCell(new Phrase(targetGroup.getActinLect(), font)));

    return table;

}