Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell PdfPCell.

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colHeader, Document document) throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
    fontSmallBold.setColor(tColor);//from w w w  .j  a  va 2s  .c  om

    com.krawler.utils.json.base.JSONObject colWidth = config.getJSONObject("colWidth");
    JSONArray widths = colWidth.getJSONArray("data");
    ArrayList arr = new ArrayList();
    PdfPTable table;
    float[] f = new float[widths.length() + 1];//[(stpcol - stcol) + 1];
    float[] tcol = new float[(stpcol - stcol) + 1];

    if (widths.length() == 0) {
        f[0] = 10;
        for (int k = 1; k < f.length; k++) {
            f[k] = 20;
        }
        tcol[0] = 10;
    } else {
        for (int i = 0; i < widths.length(); i++) {
            JSONObject temp = widths.getJSONObject(i);
            arr.add(temp.getInt("width"));
        }

        f[0] = 30;
        for (int k = 1; k < f.length; k++) {
            if (!config.getBoolean("landscape") && (Integer) arr.get(k - 1) > 550) {
                f[k] = 550;
            } else {
                f[k] = (Integer) arr.get(k - 1);
            }
        }
        //            table = new PdfPTable(f);
        //            table.setTotalWidth(90);
        // table.setWidthPercentage(f,document.getPageSize());
        tcol[0] = 30;
    }
    int i = 1;
    for (int k = stcol; k < stpcol; k++) {
        tcol[i] = f[k + 1];
        i++;
    }

    table = new PdfPTable(tcol);
    table.setTotalWidth(90);
    table.setWidthPercentage(tcol, document.getPageSize());

    table.setSpacingBefore(15);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    PdfPCell h2 = new PdfPCell(new Paragraph("No.", fontSmallBold));
    if (config.getBoolean("gridBorder")) {
        h2.setBorder(PdfPCell.BOX);
    } else {
        h2.setBorder(0);
    }
    h2.setPadding(4);
    h2.setBorderColor(Color.GRAY);
    h2.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colHeader[hcol], fontSmallBold));
        h1.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (config.getBoolean("gridBorder")) {
            h1.setBorder(PdfPCell.BOX);
        } else {
            h1.setBorder(0);
        }
        h1.setBorderColor(Color.GRAY);
        h1.setPadding(4);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        h2 = new PdfPCell(new Paragraph(String.valueOf(row + 1), f1));
        if (config.getBoolean("gridBorder")) {
            h2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(4);
        h2.setBorderColor(Color.GRAY);
        h2.setHorizontalAlignment(Element.ALIGN_CENTER);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);

        for (int col = stcol; col < stpcol; col++) {
            Paragraph para = null;
            if (store.getJSONObject(row).has(colwidth2[col]))
                para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            else
                para = new Paragraph("", f1);
            //                    Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            PdfPCell h1 = new PdfPCell(para);
            if (config.getBoolean("gridBorder")) {
                h1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(4);
            h1.setBorderColor(Color.GRAY);
            h1.setHorizontalAlignment(Element.ALIGN_CENTER);
            h1.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h1);
        }

    }
    document.add(table);
    document.newPage();

    /* add instance of OnStartPage*/
    if (widths.length() != 0) {
        if (stpcol != colwidth2.length) {
            float twidth = 0;
            stpcol1 = stpcol;

            int docwidth;
            if (config.getBoolean("landscape"))
                docwidth = 800;
            else
                docwidth = 600;

            while (twidth < docwidth && stpcol1 < f.length) {
                twidth += f[stpcol1];
                stpcol1++;
            }
            stpcol1--;

            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document);
        }

    } else {
        if (stpcol != colwidth2.length) {
            if ((colwidth2.length - stpcol) > showColumns) { // column limit
                stpcol1 = stpcol + 5;
            } else {
                stpcol1 = (colwidth2.length - stpcol) + stpcol;
            }
            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colHeader, document);
        }
    }
    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

public void getHeaderFooter(Document document) throws JSONException {
    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));
    fontSmallRegular.setColor(tColor);/*from  ww w . j av  a 2  s  . c  o  m*/

    java.util.Date dt = new java.util.Date();
    String dformat = "yyyy-MM-d";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(dformat);
    String DateStr = dtf.format(dt);

    // -------- header ----------------
    header = new PdfPTable(3);
    String HeadDate = "";
    if (config.getBoolean("headDate"))
        HeadDate = DateStr;
    PdfPCell headerDateCell = new PdfPCell(new Phrase(HeadDate, fontSmallRegular));
    headerDateCell.setBorder(0);
    headerDateCell.setPaddingBottom(4);
    header.addCell(headerDateCell);

    PdfPCell headerNotecell = new PdfPCell(new Phrase(config.getString("headNote"), fontSmallRegular));
    headerNotecell.setBorder(0);
    headerNotecell.setPaddingBottom(4);
    headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    header.addCell(headerNotecell);

    String HeadPager = "";
    if (config.getBoolean("headPager"))
        HeadPager = String.valueOf(document.getPageNumber());//current page no
    PdfPCell headerPageNocell = new PdfPCell(new Phrase(HeadPager, fontSmallRegular));
    headerPageNocell.setBorder(0);
    headerPageNocell.setPaddingBottom(4);
    headerPageNocell.setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
    header.addCell(headerPageNocell);

    PdfPCell headerSeparator = new PdfPCell(new Phrase(""));
    headerSeparator.setBorder(PdfPCell.BOX);
    headerSeparator.setPadding(0);
    headerSeparator.setColspan(3);
    header.addCell(headerSeparator);
    // -------- header end ----------------

    // -------- footer  -------------------
    footer = new PdfPTable(3);
    PdfPCell footerSeparator = new PdfPCell(new Phrase(""));
    footerSeparator.setBorder(PdfPCell.BOX);
    footerSeparator.setPadding(0);
    footerSeparator.setColspan(3);
    footer.addCell(footerSeparator);

    String PageDate = "";
    if (config.getBoolean("footDate"))
        PageDate = DateStr;
    PdfPCell pagerDateCell = new PdfPCell(new Phrase(PageDate, fontSmallRegular));
    pagerDateCell.setBorder(0);
    footer.addCell(pagerDateCell);

    PdfPCell footerNotecell = new PdfPCell(new Phrase(config.getString("footNote"), fontSmallRegular));
    footerNotecell.setBorder(0);
    footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    footer.addCell(footerNotecell);

    String FootPager = "";
    if (config.getBoolean("footPager"))
        FootPager = String.valueOf(document.getPageNumber());//current page no
    PdfPCell footerPageNocell = new PdfPCell(new Phrase(FootPager, fontSmallRegular));
    footerPageNocell.setBorder(0);
    footerPageNocell.setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
    footer.addCell(footerPageNocell);
    // -------- footer end   -----------
}

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

private int addTableTimeLine(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        int maxlevel, Document document) throws JSONException, DocumentException {
    float[] f = new float[(stpcol - stcol) + 1];
    for (int k = 0; k < f.length; k++) {
        f[k] = 20;//w  w w.j  av  a2 s  . co m
    }
    f[0] = f[0] + 10 * maxlevel;
    PdfPTable table = new PdfPTable(f);

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));

    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, tColor);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    Font f1;

    table.setWidthPercentage(90);
    PdfPCell h2 = new PdfPCell(new Paragraph("Name", font)); // new
    if (config.getBoolean("gridBorder"))
        h2.setBorder(PdfPCell.BOX);
    else
        h2.setBorder(0);
    h2.setPadding(2);
    //                h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED);
    // Paragraph(colwidth2[hcol],font);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        if (config.getBoolean("gridBorder"))
            h1.setBorder(PdfPCell.BOX);
        else
            h1.setBorder(0);
        h1.setPadding(2);
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        if (row % 62 == 61) {
            document.add(table);
            table.deleteBodyRows();
            table.setSkipFirstHeader(true);
        }
        if (store.getJSONObject(row).getBoolean("flag"))
            f1 = font;
        else
            f1 = font1;
        if (store.getJSONObject(row).getString("info").compareTo("") != 0) {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        } else {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingTop(9);
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        }

        //                h2.setBorder(0);
        //                h2.setPadding(1);
        //                Color bColor = Color.decode("DDDDDD");

        if (config.getBoolean("gridBorder")) {
            if (store.getJSONObject(row).getBoolean("flag")) {
                h2.setBackgroundColor(new Color(0xEEEEEE));
                h2.setBorder(PdfPCell.LEFT | PdfPCell.BOTTOM);
            } else
                h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(2);
        h2.setBorderColor(Color.GRAY);
        if (store.getJSONObject(row).getBoolean("flag"))
            h2.setHorizontalAlignment(Element.ALIGN_LEFT);
        else
            h2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        for (int col = stcol; col < stpcol; col++) {
            Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            PdfPCell h1 = new PdfPCell(para);
            //                    h1.setBorder(0);
            //                    h1.setPadding(1);

            h1.setMinimumHeight(15);
            h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
            h1.setVerticalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                if (store.getJSONObject(row).getBoolean("flag")) {
                    h1.setBorder(PdfPCell.BOTTOM);
                    h1.setBackgroundColor(new Color(0xEEEEEE));
                    if (col == stpcol - 1)
                        h1.setBorder(PdfPCell.BOTTOM | PdfPCell.RIGHT);
                } else
                    h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(2);
            h1.setBorderColor(Color.GRAY);
            table.addCell(h1);
            //               table.addCell(new Paragraph(store.getJSONObject(row)
            //                     .getString(colwidth2[col]), f1));
        }

    }
    document.add(table);
    document.newPage();
    if (stpcol != colwidth2.length) {
        if ((colwidth2.length - stpcol) > 5) // column limit
            stpcol1 = stpcol + 5;
        else
            stpcol1 = (colwidth2.length - stpcol) + stpcol;
        addTableTimeLine(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document);
    }

    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java

License:Open Source License

private static void addComponyLogo(Document d, HttpServletRequest request)
        throws ConfigurationException, DocumentException {
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setWidthPercentage(50);//  w w w.ja v  a  2 s . com
    PdfPCell cell = null;
    try {
        imgPath = com.krawler.esp.utils.ConfigReader.getinstance().get("platformURL") + "b/" + companySubDomain
                + "/images/store/?company=true";
        Image img = Image.getInstance(imgPath);
        cell = new PdfPCell(img);
    } catch (Exception e) {
        cell = new PdfPCell(new Paragraph(companyName, fontBig));
    }
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(cell);
    d.add(table);
}

From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java

License:Open Source License

private static void addTitleSubtitle(Document d) throws DocumentException, JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontBold.setColor(tColor);//  w  w w  . ja v  a2 s .  co m
    fontRegular.setColor(tColor);
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.util.Date today = new java.util.Date();

    table.setWidthPercentage(100);
    table.setSpacingBefore(6);

    //Report Title
    PdfPCell cell = new PdfPCell(new Paragraph("Project Summary", fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    //Sub-title(s)
    cell = new PdfPCell(new Paragraph("(on comparison with " + baseName + ")", fontRegular));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    //Separator line
    PdfPTable line = new PdfPTable(1);
    line.setWidthPercentage(100);
    PdfPCell cell1 = null;
    cell1 = new PdfPCell(new Paragraph(""));
    cell1.setBorder(PdfPCell.BOTTOM);
    line.addCell(cell1);
    d.add(table);
    d.add(line);
}

From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java

License:Open Source License

public void getHeaderFooter(Document document) throws JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallRegular.setColor(tColor);//from w w  w. java2 s  .  c om

    java.util.Date dt = new java.util.Date();
    String dformat = "yyyy-MM-d";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(dformat);
    String DateStr = dtf.format(dt);

    // -------- header ----------------

    header = new PdfPTable(1);
    PdfPCell headerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    headerNotecell.setBorder(0);
    headerNotecell.setPaddingBottom(4);
    headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    header.addCell(headerNotecell);

    PdfPCell headerSeparator = new PdfPCell(new Phrase(""));
    headerSeparator.setBorder(PdfPCell.BOX);
    headerSeparator.setPadding(0);
    headerSeparator.setColspan(1);
    header.addCell(headerSeparator);
    // -------- header end ----------------

    // -------- footer  -------------------
    footer = new PdfPTable(3);
    PdfPCell footerSeparator = new PdfPCell(new Phrase(""));
    footerSeparator.setBorder(PdfPCell.BOX);
    footerSeparator.setPadding(0);
    footerSeparator.setColspan(3);
    footer.addCell(footerSeparator);

    PdfPCell emptyCell = new PdfPCell(new Phrase("", fontSmallRegular));
    emptyCell.setBorder(0);
    emptyCell.setColspan(1);
    emptyCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT);
    footer.addCell(emptyCell);

    PdfPCell footerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    footerNotecell.setBorder(0);
    footerNotecell.setColspan(1);
    footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    footer.addCell(footerNotecell);

    PdfPCell pagerDateCell = new PdfPCell(new Phrase(DateStr, fontSmallRegular));
    pagerDateCell.setBorder(0);
    pagerDateCell.setColspan(1);
    pagerDateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    footer.addCell(pagerDateCell);

    // -------- footer end   -----------
}

From source file:com.krawler.esp.servlets.ExportProjectSummaryServlet.java

License:Open Source License

private void addTable(JSONArray store, String[] res, String[] colIndex, String[] colHeader, String[] mainHeader,
        String[] val, Document document) throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallBold.setColor(tColor);/*from www.  j ava 2  s  . c  o m*/
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);

    float[] colw = new float[4];
    for (int x = 0; x < 4; x++) {
        colw[x] = 150;
    }
    int col = 0;

    for (int x = 0; x < mainHeader.length; x++) {
        //table start
        PdfPTable table = new PdfPTable(colw);
        table.setTotalWidth(88);
        table.setWidthPercentage(colw, document.getPageSize());
        //table.setSpacingBefore(10);

        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setTotalWidth(90);
        mainTable.setWidthPercentage(100);
        mainTable.setSpacingBefore(20);

        //header cell for mainTable
        PdfPCell headcell = null;
        headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold));
        headcell.setBackgroundColor(new Color(0xEEEEEE));
        headcell.setPadding(padding);
        mainTable.addCell(headcell);
        document.add(mainTable);

        //header cell added to mainTable
        int row = 3;
        if (x == 0 || x == 4) {
            row = 4;
        } else if (x == 5) {
            row = 0;
        }
        for (; row > 0; row--) {
            for (int y = 1; y < colw.length + 1; y++) {// for each column add the colHeader and value cell
                if (col != colHeader.length) {
                    if (y % 2 != 0) {
                        Paragraph p = new Paragraph(colHeader[col], f1);
                        if (colHeader[col].contains("Variance")) {
                            p = new Paragraph(colHeader[col], fontSmallBold);
                        }
                        PdfPCell pcell = new PdfPCell(p);
                        if (gridBorder) {
                            pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                        } else {
                            pcell.setBorder(0);
                        }
                        pcell.setPadding(padding);
                        pcell.setBorderColor(new Color(0xF2F2F2));
                        pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                        table.addCell(pcell);
                    } else {
                        Paragraph p;
                        p = new Paragraph(val[col], f1);
                        if (colHeader[col].contains("Start Variance")
                                || colHeader[col].contains("End Variance")) {
                            p = new Paragraph(val[col] + " days", fontSmallBold);
                        } else if (colHeader[col].contains("Duration")) {
                            if (colHeader[col].contains("Duration Variance"))
                                p = new Paragraph(val[col] + " days", fontSmallBold);
                            else
                                p = new Paragraph(val[col] + " days", f1);
                        } else if (colHeader[col].contains("Work")) {
                            if (colHeader[col].contains("Work Variance"))
                                p = new Paragraph(val[col] + " hrs", fontSmallBold);
                            else
                                p = new Paragraph(val[col] + " hrs", f1);
                        } else if (colHeader[col].contains("Cost")) {
                            if (colHeader[col].contains("Cost Variance"))
                                p = new Paragraph(currSymbol + " " + val[col], fontSmallBold);
                            else
                                p = new Paragraph(currSymbol + " " + val[col], f1);
                        } else if (colHeader[col].contains("Percent Complete")) {
                            p = new Paragraph(val[col] + " %", f1);
                        }
                        PdfPCell pcell = new PdfPCell(p);
                        if (gridBorder) {
                            pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                        } else {
                            pcell.setBorder(0);
                        }
                        pcell.setPadding(padding);
                        pcell.setBorderColor(new Color(0xF2F2F2));
                        pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                        table.addCell(pcell);
                        col++;
                    }
                }
            }
        }
        if (x == 5) {
            int y = 0;
            row = res.length / 4;
            for (; row > 0; row--) {
                for (int c = 0; c < 2; c++) {
                    Paragraph p = new Paragraph(res[y], f1);
                    PdfPCell pcell = new PdfPCell(p);
                    if (gridBorder) {
                        pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                    } else {
                        pcell.setBorder(0);
                    }
                    pcell.setPadding(padding);
                    pcell.setBorderColor(new Color(0xF2F2F2));
                    pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                    table.addCell(pcell);
                    p = new Paragraph(res[y + 1], f1);
                    pcell = new PdfPCell(p);
                    if (gridBorder) {
                        pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
                    } else {
                        pcell.setBorder(0);
                    }
                    pcell.setPadding(padding);
                    pcell.setBorderColor(new Color(0xF2F2F2));
                    pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                    table.addCell(pcell);
                    y += 2;
                }
            }
        }
        document.add(table);
    }
}

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private static void prepare(Document d, HeaderFooter hfFooter) {
    PdfPTable table = new PdfPTable(1);
    try {//from  w  w w.  j ava2  s.  c  om
        d.setFooter(hfFooter);
        d.open();
        imgPath = StorageHandler.GetProfileImgStorePath() + StorageHandler.GetFileSeparator() + imgPath;
        //                  imgPath = "/home/krawler-user/logo.jpg";                
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setWidthPercentage(50);
        PdfPCell cell = null;
        try {
            Image img = Image.getInstance(imgPath);
            cell = new PdfPCell(img);
        } catch (Exception e) {
            cell = new PdfPCell(new Paragraph(companyName, fontBig));
        }
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        d.add(table);
    } catch (Exception e) {
        Logger.getLogger(ExportProjectReportServlet.class.getName()).log(Level.SEVERE, null, e);
    }
}

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private static void addCenter(Document d) throws DocumentException {

    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    table.setWidthPercentage(50);/*  w w  w .j  a v a 2  s.  c om*/
    table.setSpacingBefore(10);
    PdfPCell cell = null;
    cell = new PdfPCell(new Paragraph(ProjectName, fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph(ReportName, fontRegular));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);
    // For tasks which prompt user for a start and end date
    if (!(StringUtil.isNullOrEmpty(RepStartDate) && StringUtil.isNullOrEmpty(RepEndDate))) {
        cell = new PdfPCell(new Paragraph("From:" + RepStartDate + " To:" + RepEndDate, fontSmallRegular));
        cell.setBorder(0);
        cell.setBorderWidth(0);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
    }
    table.setSpacingAfter(10);
    d.add(table);
}

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        int maxlevel, Document document) {
    float[] f = new float[(stpcol - stcol) + 1];
    for (int k = 0; k < f.length; k++) {
        f[k] = 20;//from w  w w. j  a va 2  s .c  o m
    }
    f[0] = f[0] + 10 * maxlevel;
    PdfPTable table = new PdfPTable(f);
    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK);
    Font f1;
    PdfPCell h2 = new PdfPCell(new Paragraph("", font)); // new
    h2.setBorder(0);
    h2.setPadding(1);
    //                h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED);                                       
    // Paragraph(colwidth2[hcol],font);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        h1.setBorder(0);
        h1.setPadding(1);
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);
    try {
        for (int row = strow; row < stprow; row++) {
            if (row % 62 == 61) {
                document.add(table);
                table.deleteBodyRows();
                table.setSkipFirstHeader(true);
            }
            if (store.getJSONObject(row).getBoolean("flag"))
                f1 = font;
            else
                f1 = font1;
            if (store.getJSONObject(row).getString("info").compareTo("") != 0) {
                h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
                h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
            } else {
                h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
                h2.setPaddingTop(9);
                h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
            }
            h2.setBorder(0);
            h2.setPadding(1);
            if (store.getJSONObject(row).getBoolean("flag"))
                h2.setHorizontalAlignment(Element.ALIGN_LEFT);
            else
                h2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            h2.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h2);
            for (int col = stcol; col < stpcol; col++) {
                Paragraph para = null;
                if (store.getJSONObject(row).has(colwidth2[col]))
                    para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
                else
                    para = new Paragraph("", f1);
                //                    Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
                PdfPCell h1 = new PdfPCell(para);
                h1.setBorder(0);
                h1.setPadding(1);
                h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                h1.setVerticalAlignment(Element.ALIGN_CENTER);
                table.addCell(h1);
                //               table.addCell(new Paragraph(store.getJSONObject(row)
                //                     .getString(colwidth2[col]), f1));
            }

        }
        document.add(table);
        document.newPage();
        if (stpcol != colwidth2.length) {
            if ((colwidth2.length - stpcol) > 5) // column limit
                stpcol1 = stpcol + 5;
            else
                stpcol1 = (colwidth2.length - stpcol) + stpcol;
            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document);
        }

    } catch (com.krawler.utils.json.base.JSONException j) {
        KrawlerLog.op.warn("Problem During Creating JSON Object :" + j.toString());
    } catch (com.lowagie.text.DocumentException de) {
        KrawlerLog.op.warn("Problem While Creating PDF :" + de.toString());
    }
    return stpcol;
}