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

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

Introduction

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

Prototype

public void setFixedHeight(float fixedHeight) 

Source Link

Document

Set a fixed height for the cell.

Usage

From source file:com.huateng.system.util.PdfUtil.java

License:Open Source License

public static void create(String mchtId, String selMchtId, String path, List<Object[]> list,
        LinkedHashMap<String, List<Object[]>> map, Set<String> set) throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    ///*from w  w  w.jav a 2s  . co m*/
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font9 = new Font(bfChinese, 9, Font.NORMAL);
    Font font9Bold = new Font(bfChinese, 9, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.35f, 0.1f, 0.1f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph(mchtId, font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph(InformationUtil.getMchtName(mchtId), font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    String point = InformationUtil.getCurPaperPoint(selMchtId);
    PdfPCell cellPoint;
    cellPoint = new PdfPCell(new Paragraph(point, font8Red));
    cellPoint.setBorder(PdfPCell.NO_BORDER);
    cellPoint.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellLevel;
    String level = InformationUtil.getCurPaperLevel(selMchtId);
    if (Integer.valueOf(point) >= 60) {
        cellLevel = new PdfPCell(new Paragraph(level, font8Green));
    } else {
        cellLevel = new PdfPCell(new Paragraph(level, font8Red));
    }
    cellLevel.setBorder(PdfPCell.NO_BORDER);
    cellLevel.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(5);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(5);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellPoint);

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");
    table.addCell(new Paragraph(": ", font8));
    table.addCell(cellLevel);

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font9Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            if (set.contains(o[0])) {
                opt += "? ";
                opt += o[1].toString();
                opt += "         ";
            } else {
                opt += " ";
                opt += o[1].toString();
                opt += "         ";
            }
        }
        c.addElement(new Paragraph(opt.trim(), font9));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");
}

From source file:com.huateng.system.util.PdfUtil.java

License:Open Source License

public static void create(String path, List<Object[]> list, LinkedHashMap<String, List<Object[]>> map)
        throws Exception {

    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

    ///*from  w w  w  .  ja  va2 s .  c  o  m*/
    Font font17 = new Font(bfChinese, 17, Font.BOLD);
    Font font8 = new Font(bfChinese, 8, Font.NORMAL);
    Font font10 = new Font(bfChinese, 10, Font.NORMAL);
    Font font10Bold = new Font(bfChinese, 10, Font.BOLD);
    Font font8Red = new Font(bfChinese, 8, Font.NORMAL);
    font8Red.setColor(Color.RED);
    Font font8Green = new Font(bfChinese, 8, Font.NORMAL);
    font8Green.setColor(Color.GREEN);

    logger.info("Starting build document...");

    Document document = new Document(PageSize.A4, 36, 36, 36, 36);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
    document.open();
    LINECANVAS border = new LINECANVAS();

    //
    float[] widths = { 0.1f, 0.35f, 0.55f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.getDefaultCell().setFixedHeight(12);

    //CELL
    PdfPCell cellMchntId = new PdfPCell(new Paragraph("XXXXXXXXXXXXXXX", font8));
    cellMchntId.setBorder(PdfPCell.BOTTOM);
    cellMchntId.setHorizontalAlignment(Element.ALIGN_CENTER);

    PdfPCell cellMchntName = new PdfPCell(new Paragraph("?", font8));
    cellMchntName.setBorder(PdfPCell.BOTTOM);
    cellMchntName.setHorizontalAlignment(Element.ALIGN_CENTER);

    //
    Image img = Image.getInstance(
            ServletActionContext.getServletContext().getResource("/ext/resources/images/Title_logo.gif"));
    img.scalePercent(70);
    float w = img.getScaledWidth();
    float h = img.getScaledHeight();
    writer.getDirectContent().addImage(img, w, 0, 0, h, 36, PageSize.A4.getHeight() - 36 - h);

    //
    PdfPCell cell = new PdfPCell(new Paragraph("?", font17));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(3);
    cell.setFixedHeight(h);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setFixedHeight(20);
    cell.setColspan(3);
    cell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(cell);

    table.addCell(new Paragraph("?", font8));
    table.addCell(cellMchntId);
    table.addCell(" ");

    table.addCell(new Paragraph("??", font8));
    table.addCell(cellMchntName);
    table.addCell(" ");

    document.add(table);
    document.add(new Paragraph("\n\n"));

    //?
    PdfPTable t = new PdfPTable(1);

    Iterator<Object[]> it0 = list.iterator();
    int i = 1;
    while (it0.hasNext()) {
        Object[] obj = it0.next();
        PdfPCell c = new PdfPCell();
        c.addElement(new Paragraph("Q" + String.valueOf(i++) + "" + obj[1].toString(), font10Bold));
        List<Object[]> opts = map.get(obj[0].toString());
        String opt = "";
        Iterator<Object[]> it1 = opts.iterator();
        while (it1.hasNext()) {
            Object[] o = it1.next();
            opt += " ";
            opt += o[1].toString();
            opt += "         ";
        }
        c.addElement(new Paragraph(opt.trim(), font10));
        c.setBorder(PdfPCell.NO_BORDER);
        if (i - 1 != list.size()) {
            c.setCellEvent(border);
        }
        t.addCell(c);
    }

    PdfPTable oTable = new PdfPTable(1);
    oTable.setWidthPercentage(100);
    PdfPCell ce = new PdfPCell(t);
    ce.setBorderColor(Color.GRAY);
    oTable.addCell(ce);

    document.add(oTable);

    document.close();

    logger.info("Finish build document...");
}

From source file:com.krawler.esp.handlers.PdfGenHandler.java

License:Open Source License

public static ByteArrayOutputStream getInvoiceForm1(String invoice) {
    ByteArrayOutputStream os = null;
    try {//from  ww w .  j  ava  2  s .c om
        os = new ByteArrayOutputStream();
        Document document = new Document(PageSize.A4, 15, 15, 15, 15);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
        Font font10 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK);
        HeaderFooter temp = new HeaderFooter(new Phrase(
                String.format("Note: This is a computer generated document and does not require signature"),
                font7), false);
        temp.setAlignment(Element.ALIGN_CENTER);
        document.setFooter(temp);
        document.open();
        JSONObject jbj = new JSONObject(invoice);
        String currency = "";
        com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items");
        String ids[] = { "name", "address", "invoiceno", "paymentdate" };
        String uinfo[] = new String[ids.length];
        for (int i = 0; i < uinfo.length; i++) {
            uinfo[i] = jbj.getString(ids[i]);
        }
        PdfPTable tableinfo = new PdfPTable(1);
        PdfPTable table = new PdfPTable(2);
        Font font1 = FontFactory.getFont("Helvetica", 24, Font.BOLD, Color.BLACK);
        String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png";
        PdfPCell cell1 = null;
        try {
            Image img = Image.getInstance(cnxt);
            cell1 = new PdfPCell(img);
        } catch (Exception e) {
            cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png";
            Image img = Image.getInstance(cnxt);
            cell1 = new PdfPCell(img);
        }
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableinfo.addCell(cell1);
        tableinfo = addspace(1, tableinfo);
        tableinfo = addspace(4, tableinfo);
        cell1 = new PdfPCell(new Paragraph("INVOICE", font10));
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableinfo.addCell(cell1);
        tableinfo = addspace(2, tableinfo);
        table = addspace(1, table);
        //            cell1 = new PdfPCell(new Paragraph(uinfo[uinfo.length - 1],font9));
        //            cell1.setBorder(0);
        //            cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        //            tableinfo.addCell(cell1);
        //            tableinfo = addspace(1, tableinfo);
        //            tableinfo = addspace(2, tableinfo);
        cell1 = new PdfPCell(tableinfo);
        cell1.setBorder(0);
        table.addCell(cell1);
        PdfPTable tb = new PdfPTable(1);
        document.add(new Paragraph("\u00a0"));
        tableinfo = addspace(1, tableinfo);

        Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK);
        Font font2 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK);
        //Font font3 = FontFactory.getFont("Helvetica", 8, Font.ITALIC, Color.BLACK);
        Font font11 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK);
        PdfPCell c1 = null;
        c1 = new PdfPCell(new Paragraph("Bill To :", font2));
        c1.setBorder(0);
        tb.addCell(c1);
        for (int i = 0; i < 2; i++) {
            PdfPCell c = null;
            if (i == 0)
                c = new PdfPCell(new Paragraph(uinfo[i], font11));
            else
                c = new PdfPCell(new Paragraph(uinfo[i]));
            //c.(20);
            c.setBorder(0);
            tb.addCell(c);
        }
        PdfPCell c = new PdfPCell(tb);
        c.setBorder(0);
        table.addCell(c);
        PdfPTable tb1 = new PdfPTable(1);
        for (int i = 2; i < 4; i++) {
            PdfPTable nested1 = new PdfPTable(3);
            c = new PdfPCell();
            c.setBorder(0);
            c.setPaddingRight(5);
            nested1.addCell(c);
            c = new PdfPCell(new Paragraph(invoiceheadings[i], font));
            c.setBorder(0);

            nested1.addCell(c);
            c = new PdfPCell(new Paragraph(uinfo[i], font2));
            c.setBorder(0);
            c.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //c.setPaddingLeft(5);
            nested1.addCell(c);

            c = new PdfPCell(nested1);
            c.setBorder(0);
            tb1.addCell(c);
        }
        PdfPCell c2 = new PdfPCell(tb1);
        c2.setBorder(0);
        table.addCell(c2);
        PdfPTable tb2 = new PdfPTable(new float[] { 60, 40 });

        /*  for (int i = 6; i < 7; i++) {
        PdfPTable tb3 = new PdfPTable(2);//new float[]{20, 40});
        tb3.setWidths(new int[]{1, 3});
        c2 = new PdfPCell(new Paragraph(invoiceheadings[i], font));
        c2.setBorder(0);
        tb3.addCell(c2);
        c2 = new PdfPCell(new Paragraph(uinfo[i]));
        c2.setBorder(0);
        tb3.addCell(c2);
        c2 = new PdfPCell(tb3);
        c2.setBorder(0);
        c2.setHorizontalAlignment(Element.ALIGN_LEFT);
        tb2.addCell(c2);
        tb2 = addspace(1, tb2);
          }
        */
        PdfPTable maintable = new PdfPTable(1);
        c2 = new PdfPCell(table);
        c2.setBorder(0);
        maintable.addCell(c2);
        maintable = addspace(0, maintable);
        c2 = new PdfPCell(tb2);
        c2.setBorder(0);
        maintable.addCell(c2);
        document.add(maintable);
        //for (int i = 0; i < 2; i++) {
        document.add(new Paragraph("\u00a0"));
        //}
        String[] colwidth2 = { "Subscription date", "Description", "Rate ($/Project)", "Amount ($)" };

        PdfPTable table1 = new PdfPTable(4);
        table1.setWidths(new float[] { 2, 3, 1, 1 });
        for (int i = 0; i < colwidth2.length; i++) {
            PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font));
            cell.setBorder(0);
            if (i != 1) {
                cell.setBorderWidthLeft(1);
                cell.setBorderWidthRight(1);
            }
            if (i == 3) {
                cell.setBorderWidthLeft(0);
                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            } else {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            cell.setBorderWidthTop(1);
            cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f));
            cell.setBorderWidthBottom(1);
            cell.setPaddingBottom(5);
            cell.setPaddingTop(5);
            table1.addCell(cell);
        }
        //table1.setHeaderRows(1);
        double d = 0;
        String[] di = { "billdate", "description", "rate", "amount" };
        java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
        for (int i = 0; i < gridinfo.length(); i++) {
            currency = "USD";//gridinfo.getJSONObject(i).getString("currency");
            PdfPCell cell = null;
            for (int j = 0; j < di.length; j++) {
                if (j == 3) {
                    cell = new PdfPCell(new Paragraph(
                            df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(di[j]))), font2));
                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                } else {
                    cell = new PdfPCell(new Paragraph(gridinfo.getJSONObject(i).getString(di[j]), font2));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                }
                cell.setBorder(0);
                if (j != 1) {
                    cell.setBorderWidthLeft(1);
                    cell.setBorderWidthRight(1);
                }
                if (j == 3) {
                    cell.setBorder(0);
                    cell.setBorderWidthRight(1);
                }
                cell.setPaddingTop(10);
                cell.setFixedHeight(100);
                table1.addCell(cell);
            }
            d += Double.parseDouble(gridinfo.getJSONObject(i).getString(di[3]));

        }
        PdfPCell cell = null;
        cell = new PdfPCell(new Paragraph(" ", font));
        cell.setBorder(0);
        cell.setBorderWidthTop(1);
        cell.setBorderWidthBottom(1);
        cell.setBorderWidthLeft(1);
        cell.setBorderWidthRight(0);
        table1.addCell(cell);
        cell = new PdfPCell(new Paragraph("    ", font));
        cell.setBorder(0);
        cell.setBorderWidthTop(1);
        cell.setBorderWidthBottom(1);
        cell.setBorderWidthLeft(0);
        cell.setBorderWidthRight(0);
        table1.addCell(cell);
        cell = new PdfPCell(new Paragraph("     Total", font));
        cell.setBorder(0);
        cell.setBorderWidthTop(1);
        cell.setBorderWidthBottom(1);
        cell.setBorderWidthLeft(0);
        cell.setBorderWidthRight(0);
        cell.setPaddingBottom(5);
        table1.addCell(cell);
        cell = new PdfPCell(new Paragraph(" " + df.format(d), font));
        cell.setBorder(0);
        cell.setBorderWidthTop(1);
        cell.setBorderWidthBottom(1);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorderWidthLeft(0);
        cell.setBorderWidthRight(1);
        cell.setPaddingBottom(5);
        table1.addCell(cell);

        EnglishDecimalFormat f1 = new EnglishDecimalFormat();
        if (currency.equals("USD")) {
            cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font));
        } else {
            cell = new PdfPCell(new Paragraph(CurrencyConvert(currency, d), font));
        }
        cell.setColspan(4);
        cell.setBorder(0);
        //cell.setBorderWidthTop(1);
        cell.setBorderWidthBottom(1);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidthLeft(1);
        cell.setBorderWidthRight(1);
        cell.setPaddingBottom(5);
        table1.addCell(cell);
        document.add(table1);
        document.add(new Paragraph("\u00a0"));
        PdfPTable inst = new PdfPTable(1);
        //            for (int i = 0; i < Inst1.length; i++) {
        //                c2 = new PdfPCell(new Paragraph(Inst1[i]));
        //                c2.setBorder(0);
        //                inst.addCell(c2);
        //            }
        document.add(inst);
        document.close();
        writer.close();
        os.close();

    }
    //        catch (ConfigurationException ex) {
    //            Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex);
    //        }
    catch (JSONException ex) {
        Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception exp) {
        Logger.getLogger(PdfGenHandler.class.getName()).log(Level.SEVERE, null, exp);
    }
    return os;
}

From source file:com.krawler.esp.handlers.PdfGenHandler.java

License:Open Source License

public static ByteArrayOutputStream getReceiptAcc1(String ackrecp) {
    ByteArrayOutputStream os = null;
    try {// ww  w .  j  a v  a 2s  . c  o m
        os = new ByteArrayOutputStream();
        JSONObject jbj = new JSONObject(ackrecp);
        com.krawler.utils.json.base.JSONArray gridinfo = jbj.getJSONArray("items");
        String ginfo[] = new String[gridinfo.length() * 2];
        String ids[] = { "name", "receiptno", "paymentdate", "address" };
        String currency = "USD";
        //            String address = jbj.getString("address");
        String uinfo[] = new String[ids.length];
        for (int i = 0; i < uinfo.length; i++) {
            uinfo[i] = jbj.getString(ids[i]);
        }
        Font font = FontFactory.getFont("Helvetica", 10, Font.BOLD, Color.BLACK);
        Font font1 = FontFactory.getFont("Helvetica", 14, Font.BOLD, Color.BLACK);
        Font font3 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK);
        //Font font4 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK);
        Font font7 = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
        Font font10 = FontFactory.getFont("Helvetica", 12, Font.BOLD, Color.BLACK);
        Font font11 = FontFactory.getFont("Helvetica", 12, Font.NORMAL, Color.BLACK);
        Font font12 = FontFactory.getFont("Helvetica", 10, Font.NORMAL, Color.BLACK);
        Document document1 = new Document(PageSize.A4, 15, 15, 15, 15);
        PdfWriter writer = PdfWriter.getInstance(document1, os);
        HeaderFooter temp = new HeaderFooter(new Phrase(
                String.format("Note: This is a computer generated document and does not require signature"),
                font7), false);
        temp.setAlignment(Element.ALIGN_CENTER);
        document1.setFooter(temp);
        document1.open();
        PdfPTable tableHinfo = new PdfPTable(1);
        PdfPTable table = new PdfPTable(1);
        font3.setStyle(Font.UNDERLINE);
        String cnxt = "";//StorageHandler.getProfileStorePath() + "/inceif-200.png";
        PdfPCell cell1 = null;
        try {
            Image img = Image.getInstance(cnxt);
            //                img.scalePercent(90);
            cell1 = new PdfPCell(img);
        } catch (Exception e) {
            cnxt = StorageHandler.GetProfileImgStorePath() + "/140-logo.png";
            Image img = Image.getInstance(cnxt);
            cell1 = new PdfPCell(img);
        }
        cell1.setBorder(0);
        cell1.setPaddingTop(18);
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableHinfo.addCell(cell1);
        tableHinfo = addspace(1, tableHinfo);
        tableHinfo = addspace(4, tableHinfo);
        cell1 = new PdfPCell(new Paragraph("RECEIPT", font1));
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableHinfo.addCell(cell1);
        tableHinfo = addspace(0, tableHinfo);
        //            cell1 = new PdfPCell(new Paragraph(uinfo[4], font11));
        //            cell1.setBorder(0);
        //            cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        //            tableHinfo.addCell(cell1);
        document1.add(tableHinfo);
        PdfPTable tableUinfo = new PdfPTable(1);

        cell1 = new PdfPCell(new Paragraph(receiptheading[0], font12));
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableUinfo.addCell(cell1);
        cell1 = new PdfPCell(new Paragraph(uinfo[0], font10));
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableUinfo.addCell(cell1);
        cell1 = new PdfPCell(new Paragraph(uinfo[3], font11));
        cell1.setBorder(0);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableUinfo.addCell(cell1);

        document1.add(new Paragraph("\u00a0"));
        tableUinfo = addspace(1, tableUinfo);
        String hed[] = { "", "Receipt No : ", "Date : ", "" };

        PdfPTable tableDinfo = new PdfPTable(1);
        //tableDinfo.setTotalWidth(100);
        for (int j = 1; j < 3; j++) {
            PdfPTable nested1 = new PdfPTable(3);
            cell1 = new PdfPCell();
            cell1.setBorder(0);
            nested1.addCell(cell1);

            cell1 = new PdfPCell(new Paragraph(hed[j], font));
            cell1.setBorder(0);
            nested1.addCell(cell1);

            cell1 = new PdfPCell(new Paragraph(uinfo[j], font12));
            cell1.setBorder(0);
            cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
            nested1.addCell(cell1);

            cell1 = new PdfPCell(nested1);
            cell1.setBorder(0);
            tableDinfo.addCell(cell1);
        }
        PdfPTable container = new PdfPTable(2);
        cell1 = new PdfPCell(tableUinfo);
        cell1.setBorder(0);
        cell1.setPaddingBottom(15);
        container.addCell(cell1);
        cell1 = new PdfPCell(tableDinfo);
        cell1.setBorder(0);
        container.addCell(cell1);
        document1.add(container);
        PdfPTable table1 = new PdfPTable(2);
        String[] colwidth2 = { "Invoice No.", "Amount Paid($)" };
        for (int i = 0; i < colwidth2.length; i++) {
            PdfPCell cell = new PdfPCell(new Paragraph(colwidth2[i], font));
            if (i == 1) {
                cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                cell.setBorderWidthLeft(0);
            } else {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setBorderWidthLeft(1);
            }
            cell.setBackgroundColor(Color.getHSBColor(0f, 0f, 0.9f));
            cell.setPaddingBottom(5);
            cell.setBorderWidthRight(1);
            cell.setBorderWidthTop(1);
            table1.addCell(cell);
        }
        table1.setHeaderRows(1);
        double d = 0;
        colwidth2 = new String[] { "invoicenum", "amount" };
        java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
        for (int i = 0; i < gridinfo.length(); i++) {
            for (int j = 0; j < colwidth2.length; j++) {
                PdfPCell cell = null;
                if (j == 1) {
                    cell = new PdfPCell(new Paragraph(
                            df.format(Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]))),
                            font12));
                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    cell.setBorderWidthLeft(0);
                } else {
                    cell = new PdfPCell(
                            new Paragraph(gridinfo.getJSONObject(i).getString(colwidth2[j]), font12));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBorderWidthLeft(1);
                }
                //cell.setMinimumHeight(25);
                cell.setBorderWidthRight(1);
                cell.setPaddingTop(5);
                cell.setFixedHeight(100);
                table1.addCell(cell);
                if (j == colwidth2.length - 1) {
                    d += Double.parseDouble(gridinfo.getJSONObject(i).getString(colwidth2[j]));
                }
            }
        }
        //            EnglishDecimalFormat f1 = new EnglishDecimalFormat();
        PdfPCell cell = new PdfPCell(new Paragraph("", font));
        cell.setBorderWidthBottom(1);
        cell.setBorderWidthRight(0);
        cell.setBorderWidthLeft(1);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table1.addCell(cell);
        cell = new PdfPCell(new Paragraph("Total              " + df.format(d), font));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        //cell.setPaddingBottom(15);
        cell.setPaddingLeft(15);
        cell.setPaddingBottom(5);
        cell.setBorderWidthBottom(1);
        cell.setBorderWidthLeft(0);
        cell.setBorderWidthRight(1);
        table1.addCell(cell);
        PdfPTable table3 = new PdfPTable(1);
        cell = new PdfPCell(new Paragraph("Amount in words : " + CurrencyConvert(currency, d), font));
        //cell.setPaddingBottom(15);
        cell.setBorder(0);
        cell.setColspan(4);
        cell.setBorderWidthBottom(1);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorderWidthLeft(1);
        cell.setBorderWidthRight(1);
        cell.setPaddingBottom(5);
        table3.addCell(cell);
        document1.add(table1);
        document1.add(table3);
        document1.add(new Paragraph("\u00a0"));

        cell = new PdfPCell(new Paragraph(String.format(
                "All payments are non-refundable and non-transferable. \nThis Receipt is valid subject to clearance of the payments."),
                font11));
        //cell.setPaddingLeft(5);
        cell.setBorder(0);
        table.addCell(cell);

        //            String delFlag = jbj.getString("delflag");
        //            if(delFlag.compareTo("2")==0){
        //                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
        //                PdfContentByte cb = writer.getDirectContentUnder();
        //                cb.saveState();
        //                cb.setColorFill(Color.BLACK);
        //                cb.beginText();
        //                cb.setFontAndSize(bf, 48);
        //                cb.showTextAligned(Element.ALIGN_CENTER, "Canceled Payment", document1.getPageSize().getWidth() / 2, document1.getPageSize().getHeight() / 2, 45);
        //                cb.endText();
        //                cb.restoreState();
        //            }   

        document1.add(table);
        document1.close();
        writer.close();
        os.close();
    } catch (Exception e) {
        System.out.println(e);
    }
    return os;
}

From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) {
    try {//from  w w  w.  j  av a 2 s  .c o  m
        String activity = "";
        if (step.getResolvedState() != null) {
            State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState());
            activity = resolvedState.getLabel(getRole(), getLanguage());
        }

        String sAction = null;
        try {
            if ("#question#".equals(step.getAction())) {
                sAction = getString("processManager.question");
            } else if ("#response#".equals(step.getAction())) {
                sAction = getString("processManager.response");
            } else if ("#reAssign#".equals(step.getAction())) {
                sAction = getString("processManager.reAffectation");
            } else {
                Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction());
                sAction = action.getLabel(getRole(), getLanguage());
            }
        } catch (WorkflowException we) {
            sAction = "##";
        }

        String actor = getBestUserDetail().getDisplayedName();

        String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage());

        String header = "";
        if (StringUtil.isDefined(activity)) {
            header += activity + " - ";
        }
        header += sAction + " (" + actor + " - " + date + ")";

        Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL);

        PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader));
        pCell.setFixedHeight(28);
        pCell.setBackgroundColor(new Color(239, 239, 239));
        pCell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPTable pTable = new PdfPTable(1);
        pTable.setWidthPercentage(100);
        pTable.addCell(pCell);

        document.add(pTable);
    } catch (Exception e) {
        SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e);
    }
}

From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java

License:Open Source License

private void formatZelle(final int zeile, final int spalte, final PdfPCell cell) {
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorderColor(new Color(//
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.red")), //
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.green")), //
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.blue"))));

    if (isEvenBlockIndex(zeile, spalte)) {
        cell.setBackgroundColor(new Color(//
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.red")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.green")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.blue"))));
    } else {/*  w  w w.ja  va2 s  . c o m*/
        cell.setBackgroundColor(new Color(//
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.red")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.green")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.blue"))));
    }
    cell.setBorderWidth(PdfConstants.RAHMEN_DUENN);
    if (BoxUtils.isFirstRowInBlock(zeile, getSudokuSize())) {
        cell.setBorderWidthTop(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthTop(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isLastColumnInRow(spalte, getSudokuSize())) {
        cell.setBorderWidthRight(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthRight(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isLastRowInColumn(zeile, getSudokuSize())) {
        cell.setBorderWidthBottom(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthBottom(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isFirstColumnInBlock(spalte, getSudokuSize())) {
        cell.setBorderWidthLeft(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthLeft(PdfConstants.RAHMEN_DUENN);
    }
    cell.setFixedHeight(27f);
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

private List<ColumnText> fillTable(float height) {
    // copy text for simulation
    List<ColumnText> tt = null;
    if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
        // more column breaks than available column
        // we try not to lose content
        // but results may be different than in open office
        // anyway it is logical error made by document creator
        tt = new ArrayList<ColumnText>();
        ColumnText t = createColumnText();
        tt.add(t);//  ww w .ja  v  a2s .c om
        for (int i = 0; i < texts.size(); i++) {
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100.0f);
            PdfPCell cell = new PdfPCell();
            cell.setBorder(Table.NO_BORDER);
            cell.setPadding(0.0f);
            cell.setColumn(ColumnText.duplicate(texts.get(i)));
            table.addCell(cell);
            t.addElement(table);
        }
    } else {
        tt = new ArrayList<ColumnText>(texts);
        for (int i = 0; i < tt.size(); i++) {
            tt.set(i, ColumnText.duplicate(tt.get(i)));
        }
    }
    // clear layout table
    clearTable(layoutTable, true);
    setWidthIfNecessary();

    // try to fill cells with text
    ColumnText t = tt.get(0);
    for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        cell.setColumn(ColumnText.duplicate(t));
        //
        t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(),
                height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
        int res = 0;
        try {
            res = t.go(true);
        } catch (DocumentException e) {
            throw new ODFConverterException(e);
        }
        if (!ColumnText.hasMoreText(res)) {
            // no overflow in current column
            if (tt.size() == 1) {
                // no more text
                return null;
            } else {
                // some text waiting for new column
                tt.remove(0);
                t = tt.get(0);
            }
        }
    }
    return tt;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static SectionPdfPTable createLayoutTable(float width, float height,
        List<StyleColumnProperties> columnPropertiesList) {
    // create one row table which will layout section text
    int colCount = columnPropertiesList.size();
    int relativeWidths[] = new int[colCount];
    SectionPdfPTable table = new SectionPdfPTable(colCount);
    // add cells/*www .ja  v a 2  s . c o m*/
    for (int i = 0; i < colCount; i++) {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Table.NO_BORDER);
        cell.setPadding(0.0f);
        cell.setColumn(createColumnText());
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        // apply styles to cell
        StyleColumnProperties columnProperties = columnPropertiesList.get(i);
        relativeWidths[i] = columnProperties.getRelWidth();
        cell.setPaddingLeft(
                columnProperties.getStartIndent() != null ? columnProperties.getStartIndent() : 0.0f);
        cell.setPaddingRight(columnProperties.getEndIndent() != null ? columnProperties.getEndIndent() : 0.0f);
        table.addCell(cell);
    }
    replaceTableCells(table);
    // set width
    try {
        table.setWidths(relativeWidths);
    } catch (DocumentException e) {
        throw new ODFConverterException(e);
    }
    table.setTotalWidth(width);
    table.setLockedWidth(true);
    return table;
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java

License:Open Source License

public static void clearTable(PdfPTable table, boolean resetFixedHeight) {
    for (PdfPCell cell : table.getRow(0).getCells()) {
        cell.setColumn(createColumnText());
        if (resetFixedHeight) {
            cell.setFixedHeight(-1.0f);
        }//from w ww  . j  av a  2  s .c  o  m
    }
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.elements.StylableDocumentSection.java

License:Open Source License

private List<ColumnText> fillTable(float height) {
    // copy text for simulation
    List<ColumnText> tt = null;
    if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) {
        // more column breaks than available column
        // we try not to lose content
        // but results may be different than in open office
        // anyway it is logical error made by document creator
        tt = new ArrayList<ColumnText>();
        ColumnText t = createColumnText();
        tt.add(t);/*from  ww w .j  a v a  2 s .  c om*/
        for (int i = 0; i < texts.size(); i++) {
            PdfPTable table = new PdfPTable(1);
            table.setWidthPercentage(100.0f);
            PdfPCell cell = new PdfPCell();
            cell.setBorder(Table.NO_BORDER);
            cell.setPadding(0.0f);
            cell.setColumn(ColumnText.duplicate(texts.get(i)));
            table.addCell(cell);
            t.addElement(table);
        }
    } else {
        tt = new ArrayList<ColumnText>(texts);
        for (int i = 0; i < tt.size(); i++) {
            tt.set(i, ColumnText.duplicate(tt.get(i)));
        }
    }
    // clear layout table
    clearTable(layoutTable, true);
    setWidthIfNecessary();

    // try to fill cells with text
    ColumnText t = tt.get(0);
    for (PdfPCell cell : layoutTable.getRow(0).getCells()) {
        cell.setFixedHeight(height >= 0.0f ? height : -1.0f);
        cell.setColumn(ColumnText.duplicate(t));
        //
        t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(),
                height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0);
        int res = 0;
        try {
            res = t.go(true);
        } catch (DocumentException e) {
            throw new XWPFConverterException(e);
        }
        if (!ColumnText.hasMoreText(res)) {
            // no overflow in current column
            if (tt.size() == 1) {
                // no more text
                return null;
            } else {
                // some text waiting for new column
                tt.remove(0);
                t = tt.get(0);
            }
        }
    }
    return tt;
}