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

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

Introduction

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

Prototype

public void setPaddingBottom(float paddingBottom) 

Source Link

Document

Setter for property paddingBottom.

Usage

From source file:biblivre3.administration.reports.AssetHoldingFullReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    AssetHoldingDto dto = (AssetHoldingDto) reportData;
    String title = "";
    if (this.topographic) {
        title = this.getText("REPORTS_TOPOGRAPHIC_TITLE");
    } else {//from  ww w.j  a v  a 2  s  .  c  o  m
        title = this.getText("REPORTS_ASSET_HOLDING_TITLE");
    }
    Paragraph p1 = new Paragraph(title);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(20);
    table.setWidthPercentage(100f);
    createHeader(table);
    PdfPCell cell;
    List<String[]> dataList = dto.getData();
    Collections.sort(dataList, this);
    for (String[] data : dataList) {
        PdfContentByte cb = getWriter().getDirectContent();

        String holdingSerial = StringUtils.leftPad(data[0], 10, "0");
        Barcode39 code39 = new Barcode39();
        code39.setExtended(true);
        code39.setCode(holdingSerial);
        code39.setStartStopText(false);

        Image image39 = code39.createImageWithBarcode(cb, null, null);
        image39.scalePercent(100f);
        cell = new PdfPCell(new Paragraph(new Phrase(new Chunk(image39, 0, 0))));
        cell.setColspan(6);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1])));
        cell.setColspan(3);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);

        Paragraph para = new Paragraph();
        para.add(new Phrase(this.getSmallFontChunk(data[2] + "\n")));
        para.add(new Phrase(this.getSmallFontChunk(data[3] + "\n")));

        if (StringUtils.isNotBlank(data[4])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_LOCATION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[4] + " ")));
        }

        if (StringUtils.isNotBlank(data[5])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_EDITION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[5] + " ")));
        }

        if (StringUtils.isNotBlank(data[6])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_DATE") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[6])));
        }

        cell = new PdfPCell(para);
        cell.setColspan(11);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setPaddingTop(5f);
        cell.setPaddingLeft(7f);
        cell.setPaddingBottom(4f);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:com.efficio.fieldbook.service.LabelPrintingServiceImpl.java

License:Open Source License

/**
 * Gets the cell height./*from   ww w.ja v a2s. c o  m*/
 *
 * @param numberOfRowsPerPage the number of rows per page
 * @param pageSizeId the page size id
 * @return the cell height
 */
/*
private float getCellHeight(int numberOfRowsPerPage, int pageSizeId){
if(pageSizeId == AppConstants.SIZE_OF_PAPER_A4){
    if(numberOfRowsPerPage == 7){
        return 108f; //ok
    }else if(numberOfRowsPerPage == 8){
        return 97f;//ok
    }else if(numberOfRowsPerPage == 10){
        return 72.5f;
    }
}else{
    if(numberOfRowsPerPage == 7){
        return 108f; //ok
    }else if(numberOfRowsPerPage == 8){
        return 98.1f;//ok
    }else if(numberOfRowsPerPage == 10){
        return 72.5f;//ok
    }
}
           
return 0f;
}
*/
/* (non-Javadoc)
 * @see com.efficio.fieldbook.service.api.LabelPrintingService#generateLabels(com.efficio.fieldbook.web.fieldmap.bean.UserFieldmap)
 */
@Override
public String generatePDFLabels(List<StudyTrialInstanceInfo> trialInstances,
        UserLabelPrinting userLabelPrinting, ByteArrayOutputStream baos) throws MiddlewareQueryException {

    // setUserLabelPrinting(form.getUserLabelPrinting());
    int pageSizeId = Integer.parseInt(userLabelPrinting.getSizeOfLabelSheet());
    int numberOfLabelPerRow = Integer.parseInt(userLabelPrinting.getNumberOfLabelPerRow());
    int numberofRowsPerPageOfLabel = Integer.parseInt(userLabelPrinting.getNumberOfRowsPerPageOfLabel());
    int totalPerPage = numberOfLabelPerRow * numberofRowsPerPageOfLabel;
    String leftSelectedFields = userLabelPrinting.getLeftSelectedLabelFields();
    String rightSelectedFields = userLabelPrinting.getRightSelectedLabelFields();
    String barcodeNeeded = userLabelPrinting.getBarcodeNeeded();

    String firstBarcodeField = userLabelPrinting.getFirstBarcodeField();
    String secondBarcodeField = userLabelPrinting.getSecondBarcodeField();
    String thirdBarcodeField = userLabelPrinting.getThirdBarcodeField();

    String currentDate = DateUtil.getCurrentDate();
    // String fileName = currentDate + ".pdf";

    String fileName = userLabelPrinting.getFilenameDLLocation();

    try {
        FileOutputStream fileOutputStream = new FileOutputStream(fileName);

        try {

            // Image image1 = Image.getInstance(imageLocation);

            // PageSize.A4
            LabelPaper paper = LabelPaperFactory.generateLabelPaper(numberOfLabelPerRow,
                    numberofRowsPerPageOfLabel, pageSizeId);

            Rectangle pageSize = PageSize.LETTER;

            if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4.getInt())
                pageSize = PageSize.A4;

            Document document = new Document(pageSize);
            /*
             * 2, 2, 33.3f, 5
             * 15, 0, 42, 5
             * 10, 0, 17, 5
             * 10, 0, 17, 5
             * 5, 0, 0, 5
             * 15, 0, 37, 5
             * 10, 0, 17, 5
            if (pageSizeId == AppConstants.SIZE_OF_PAPER_LETTER) {
            if (numberofRowsPerPageOfLabel == 7)
                document.setMargins(10, 0, 17, 5);
            else if (numberofRowsPerPageOfLabel == 8)
                document.setMargins(5, 0, 0, 5);
            else if (numberofRowsPerPageOfLabel == 10)
                document.setMargins(2, 2, 33.3f, 5);
            } else if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4) {
            if (numberofRowsPerPageOfLabel == 7)
                document.setMargins(15, 0, 42, 5);
            else if (numberofRowsPerPageOfLabel == 8)
                document.setMargins(15, 0, 37, 5);
            else if (numberofRowsPerPageOfLabel == 10)
                document.setMargins(6, 2, 17.5f, 5);
            }
            */
            //float marginLeft, float marginRight, float marginTop, float marginBottom
            document.setMargins(paper.getMarginLeft(), paper.getMarginRight(), paper.getMarginTop(),
                    paper.getMarginBottom());

            // PdfWriter writer = PdfWriter.getInstance(document, baos);
            PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
            // step 3
            document.open();
            // step 4

            PdfContentByte canvas = writer.getDirectContent();

            int i = 0;
            int fixTableRowSize = numberOfLabelPerRow;
            PdfPTable table = new PdfPTable(fixTableRowSize);

            // table.writeSelectedRows(0, -1, 10, 12, canvas);
            float columnWidthSize = 265f;// 180f;
            float[] widthColumns = new float[fixTableRowSize];

            for (int counter = 0; counter < widthColumns.length; counter++) {
                widthColumns[counter] = columnWidthSize;
            }

            table.setWidths(widthColumns);
            table.setWidthPercentage(100);
            int width = 600;
            int height = 75;

            List<File> filesToBeDeleted = new ArrayList<File>();
            //float cellHeight = getCellHeight(numberofRowsPerPageOfLabel, pageSizeId);
            float cellHeight = paper.getCellHeight();

            for (StudyTrialInstanceInfo trialInstance : trialInstances) {
                FieldMapTrialInstanceInfo fieldMapTrialInstanceInfo = trialInstance.getTrialInstance();

                Map<String, String> moreFieldInfo = new HashMap<String, String>();
                moreFieldInfo.put("locationName", fieldMapTrialInstanceInfo.getLocationName());
                moreFieldInfo.put("blockName", fieldMapTrialInstanceInfo.getBlockName());
                moreFieldInfo.put("selectedName", trialInstance.getFieldbookName());
                moreFieldInfo.put("trialInstanceNumber", fieldMapTrialInstanceInfo.getTrialInstanceNo());

                for (FieldMapLabel fieldMapLabel : fieldMapTrialInstanceInfo.getFieldMapLabels()) {

                    i++;
                    String barcodeLabel = generateBarcodeField(moreFieldInfo, fieldMapLabel, firstBarcodeField,
                            secondBarcodeField, thirdBarcodeField, barcodeNeeded);
                    if ("0".equalsIgnoreCase(barcodeNeeded)) {
                        barcodeLabel = " ";
                    }

                    BitMatrix bitMatrix = new Code128Writer().encode(barcodeLabel, BarcodeFormat.CODE_128,
                            width, height, null);
                    String imageLocation = System.getProperty("user.home") + "/" + Math.random() + ".png";
                    File imageFile = new File(imageLocation);
                    FileOutputStream fout = new FileOutputStream(imageFile);
                    MatrixToImageWriter.writeToStream(bitMatrix, "png", fout);
                    filesToBeDeleted.add(imageFile);

                    Image mainImage = Image.getInstance(imageLocation);

                    PdfPCell cell = new PdfPCell();
                    cell.setFixedHeight(cellHeight);
                    cell.setNoWrap(false);
                    cell.setPadding(5f);
                    cell.setPaddingBottom(1f);

                    PdfPTable innerImageTableInfo = new PdfPTable(1);
                    innerImageTableInfo.setWidths(new float[] { 1 });
                    innerImageTableInfo.setWidthPercentage(82);
                    PdfPCell cellImage = new PdfPCell();
                    if ("1".equalsIgnoreCase(barcodeNeeded)) {
                        cellImage.addElement(mainImage);
                    } else {
                        cellImage.addElement(new Paragraph(" "));
                    }
                    cellImage.setBorder(Rectangle.NO_BORDER);
                    cellImage.setBackgroundColor(Color.white);
                    cellImage.setPadding(1.5f);

                    innerImageTableInfo.addCell(cellImage);

                    //float fontSize = 6.8f;
                    float fontSize = paper.getFontSize();
                    //if (numberofRowsPerPageOfLabel == 10)
                    //    fontSize = 4.8f;

                    Font fontNormal = FontFactory.getFont("Arial", fontSize, Font.NORMAL);

                    // cell.addElement(mainImage);
                    cell.addElement(innerImageTableInfo);

                    cell.addElement(new Paragraph());
                    for (int row = 0; row < 5; row++) {
                        if (row == 0) {
                            PdfPTable innerDataTableInfo = new PdfPTable(1);
                            innerDataTableInfo.setWidths(new float[] { 1 });
                            innerDataTableInfo.setWidthPercentage(85);

                            Font fontNormalData = FontFactory.getFont("Arial", 5.0f, Font.NORMAL);
                            PdfPCell cellInnerData = new PdfPCell(new Phrase(barcodeLabel, fontNormalData));

                            cellInnerData.setBorder(Rectangle.NO_BORDER);
                            cellInnerData.setBackgroundColor(Color.white);
                            cellInnerData.setPaddingBottom(0.2f);
                            cellInnerData.setPaddingTop(0.2f);
                            cellInnerData.setHorizontalAlignment(Element.ALIGN_MIDDLE);

                            innerDataTableInfo.addCell(cellInnerData);
                            innerDataTableInfo.setHorizontalAlignment(Element.ALIGN_MIDDLE);
                            cell.addElement(innerDataTableInfo);
                        }
                        PdfPTable innerTableInfo = new PdfPTable(2);
                        innerTableInfo.setWidths(new float[] { 1, 1 });
                        innerTableInfo.setWidthPercentage(85);

                        String leftText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel, leftSelectedFields,
                                row);
                        PdfPCell cellInnerLeft = new PdfPCell(new Paragraph(leftText, fontNormal));

                        cellInnerLeft.setBorder(Rectangle.NO_BORDER);
                        cellInnerLeft.setBackgroundColor(Color.white);
                        cellInnerLeft.setPaddingBottom(0.5f);
                        cellInnerLeft.setPaddingTop(0.5f);

                        innerTableInfo.addCell(cellInnerLeft);

                        String rightText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel,
                                rightSelectedFields, row);
                        PdfPCell cellInnerRight = new PdfPCell(new Paragraph(rightText, fontNormal));

                        cellInnerRight.setBorder(Rectangle.NO_BORDER);
                        cellInnerRight.setBackgroundColor(Color.white);
                        cellInnerRight.setPaddingBottom(0.5f);
                        cellInnerRight.setPaddingTop(0.5f);

                        innerTableInfo.addCell(cellInnerRight);

                        cell.addElement(innerTableInfo);
                    }

                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setBackgroundColor(Color.white);

                    //cell.setBorderColor(Color.BLUE);

                    table.addCell(cell);

                    if (i % numberOfLabelPerRow == 0) {
                        // we go the next line

                        int needed = fixTableRowSize - numberOfLabelPerRow;

                        for (int neededCount = 0; neededCount < needed; neededCount++) {
                            PdfPCell cellNeeded = new PdfPCell();

                            cellNeeded.setBorder(Rectangle.NO_BORDER);
                            cellNeeded.setBackgroundColor(Color.white);

                            table.addCell(cellNeeded);
                        }

                        table.completeRow();
                        if (numberofRowsPerPageOfLabel == 10) {

                            //table.setSpacingAfter(9f);
                            table.setSpacingAfter(paper.getSpacingAfter());
                        }

                        document.add(table);

                        table = new PdfPTable(fixTableRowSize);
                        table.setWidths(widthColumns);
                        table.setWidthPercentage(100);

                    }
                    if (i % totalPerPage == 0) {
                        // we go the next page
                        document.newPage();
                    }
                    fout.flush();
                    fout.close();

                }
            }
            // we need to add the last row
            if (i % numberOfLabelPerRow != 0) {
                // we go the next line

                int needed = fixTableRowSize - numberOfLabelPerRow;
                int remaining = numberOfLabelPerRow - (i % numberOfLabelPerRow);
                for (int neededCount = 0; neededCount < remaining; neededCount++) {
                    PdfPCell cellNeeded = new PdfPCell();

                    cellNeeded.setBorder(Rectangle.NO_BORDER);
                    cellNeeded.setBackgroundColor(Color.white);

                    table.addCell(cellNeeded);
                }

                table.completeRow();
                if (numberofRowsPerPageOfLabel == 10) {

                    table.setSpacingAfter(paper.getSpacingAfter());
                }

                document.add(table);

                table = new PdfPTable(fixTableRowSize);
                table.setWidths(widthColumns);
                table.setWidthPercentage(100);

            }

            document.close();
            for (File file : filesToBeDeleted) {
                file.delete();
            }
            fileOutputStream.close();

        } catch (FileNotFoundException e) {
            LOG.error(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }

    } catch (WriterException e) {
        LOG.error(e.getMessage(), e);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return fileName;
}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void createColHeadings(String[] cols) throws DocumentException {

    createTable(cols.length);// w  w w .java 2 s  . co  m
    for (String col : cols) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(col), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(col));
        setCellPadding(c1);
        c1.setPaddingBottom(5);
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

/**
 * @param c1/*from   ww  w  .ja  v a2  s . com*/
 */
private void setCellPadding(PdfPCell c1) {
    c1.setPaddingLeft(CELLPADDING_LEFT);
    c1.setPaddingTop(CELLPADDING_TOP);
    c1.setPaddingRight(CELLPADDING_RIGHT);
    c1.setPaddingBottom(CELLPADDING_BOTTOM);
}

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

License:Open Source License

public static ByteArrayOutputStream getInvoiceForm1(String invoice) {
    ByteArrayOutputStream os = null;
    try {//from  w  w w  .  ja v a2s. 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 {/*from  w  w  w .  j av  a2 s  .c om*/
        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.krawler.esp.servlets.AppraisalDetails.java

License:Open Source License

private ByteArrayOutputStream AppraisalDetail(HttpServletRequest request, Session session, boolean isEmm)
        throws JSONException, SessionExpiredException, DocumentException, ServiceException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    String[] colHeader = { "Employee Name", "Appraisal Cycle Name", "Appraisal Cycle Start Date",
            "Appraisal Cycle End Date", "Total No. of Appraisals", "No. of Appraisals submitted",
            "Overall Self Comment", "Overall Appraiser Comments", "Overall Competency Score", "Competencies" };
    String[] dataIndex = { "empname", "appcylename", "appcylestdate", "appcylendate", "totalappraisal",
            "appraisalsubmitted", "empcomment", "mancom", "manavgwght", "" };
    String[] compHeader = { "Name", "Description", "Self Appraisal Score", "Self Appraisal Comment",
            "Appraiser Competency Score", "Appraiser Comments" };
    String[] compDataIndex = { "comptename", "comptdesc", "selfcompscore", "selfcomment", "compmanwght" };
    String[] compGoalHeader = { "Goals", "Assigned By", "Appraiser Rating", "Appraiser Comment", "Self Rating",
            "Self Comments" };
    String[] compGoalDataIndex = { "gname", "assignedby", "gmanrat", "mangoalcomment", "gemprat",
            "empgoalcomment" };
    String managerComments = "";
    String scoreAvg = "";
    String companyid = null;// w ww .j  a  v  a2  s . c  om
    Transaction tx = null;
    PdfWriter writer = null;
    try {
        Document document = new Document(PageSize.A4.rotate(), 25, 25, 25, 25);
        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new EndPage());
        document.open();
        java.awt.Color tColor = new Color(9, 9, 9);
        fontSmallBold.setColor(tColor);
        Paragraph p = new Paragraph();

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(new float[] { 55, 75 });

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

        PdfPCell headcell = null;
        headcell = new PdfPCell(new Paragraph("Appraisal Details", fontHeadingMediumBold));
        headcell.setBackgroundColor(new Color(0xEEEEEE));
        headcell.setPadding(5);
        mainTable.addCell(headcell);
        document.add(mainTable);

        String str = hrmsManager.getAppraisalReport(session, request);
        JSONObject jobjTemplate = new JSONObject(str);
        com.krawler.utils.json.base.JSONArray jarr = jobjTemplate.getJSONArray("data");
        String goalstr = "";
        User user = (User) session.get(User.class, request.getParameter("userid"));
        companyid = user.getCompany().getCompanyID();
        if (hrmsManager.checkModule("goal", session, request, companyid))
            goalstr = hrmsManager.getAppraisalReportGoalsforGrid(session, request);
        com.krawler.utils.json.base.JSONArray jarr2 = jarr.getJSONObject(0).getJSONArray("data");
        JSONObject jobjAppraisal = new JSONObject(jarr2.getString(0));
        jarr = jobjAppraisal.getJSONArray("competencies");
        int headlen = colHeader.length;
        if (jarr.length() < 1) {
            headlen = headlen - 1;
        }
        for (int i = 0; i < headlen; i++) {
            PdfPCell pcell = new PdfPCell(new Paragraph(colHeader[i], fontMediumBold));
            pcell.setBorder(0);
            if (i == 0)
                pcell.setPaddingTop(10);
            pcell.setPaddingLeft(15);
            pcell.setPaddingBottom(4);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
            pcell.setVerticalAlignment(Element.ALIGN_LEFT);
            table.addCell(pcell);

            if (!dataIndex[i].equals("mancom")) {
                pcell = new PdfPCell(new Paragraph(!dataIndex[i].equals("")
                        ? !jobjAppraisal.isNull(dataIndex[i]) ? jobjAppraisal.getString(dataIndex[i]) : ""
                        : "", fontSmallRegular));
                if (i == 0)
                    pcell.setPaddingTop(10);
                pcell.setBorder(0);
                pcell.setPaddingLeft(10);
                pcell.setPaddingBottom(4);
                pcell.setBorderColor(new Color(0xF2F2F2));
                pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
                pcell.setVerticalAlignment(Element.ALIGN_LEFT);
                table.addCell(pcell);
            } else {
                if (!jobjAppraisal.isNull(dataIndex[i])) {
                    String[] spl = jobjAppraisal.getString(dataIndex[i]).split(",");
                    String strData = "";
                    for (int counter = 0; counter < spl.length; counter++) {
                        strData += spl[counter] + " \n";
                    }
                    pcell = new PdfPCell(new Paragraph(strData, fontSmallRegular));
                    if (i == 0)
                        pcell.setPaddingTop(10);
                    pcell.setBorder(0);
                    pcell.setPaddingLeft(10);
                    pcell.setPaddingBottom(4);
                    pcell.setBorderColor(new Color(0xF2F2F2));
                    pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    pcell.setVerticalAlignment(Element.ALIGN_LEFT);
                    table.addCell(pcell);
                }
            }
        }

        document.add(table);

        PdfPTable compTable = new PdfPTable(6);
        compTable.setWidthPercentage(100);
        compTable.setWidths(new float[] { 50, 60, 30, 50, 42, 70 });
        compTable.setSpacingBefore(20);
        compTable.setHeaderRows(1);

        for (int i = 0; i < compHeader.length; i++) {
            PdfPCell pcell = new PdfPCell(new Paragraph(compHeader[i], fontMediumBold));
            pcell.setBorder(0);
            pcell.setBorder(PdfPCell.BOX);
            pcell.setPadding(4);
            pcell.setBorderColor(Color.GRAY);
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            compTable.addCell(pcell);
        }

        for (int i = 0; i < jarr.length(); i++) {
            jobjAppraisal = jarr.getJSONObject(i);
            for (int k = 0; k < compHeader.length; k++) {
                if (k != compHeader.length - 1) {
                    scoreAvg = "";
                    if (!jobjAppraisal.isNull(compDataIndex[k]) && compDataIndex[k].equals("compmanwght")) {
                        scoreAvg = jobjAppraisal.getString("nominalRat");
                        Font font = new Font(Font.HELVETICA, 8, Font.BOLD, Color.BLACK);
                        Chunk chunk1 = new Chunk(jobjAppraisal.getString(compDataIndex[k]) + "\n\n",
                                fontSmallRegular);
                        Chunk chunk2 = null;
                        if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) {
                            //                                user=(User)session.get(User.class,request.getParameter("userid"));
                            //                                companyid=user.getCompany().getCompanyID();
                            if (hrmsManager.checkModule("modaverage", session, request, companyid)) {
                                chunk2 = new Chunk("[Mod Avg:  " + scoreAvg + " ]", font);
                            } else {
                                chunk2 = new Chunk("[Avg:  " + scoreAvg + " ]", font);
                            }
                        } else {
                            if (hrmsManager.checkModule("modaverage", session, request)) {
                                chunk2 = new Chunk("[Mod Avg:  " + scoreAvg + " ]", font);
                            } else {
                                chunk2 = new Chunk("[Avg:  " + scoreAvg + " ]", font);
                            }
                        }
                        Phrase phrase1 = new Phrase();
                        phrase1.add(chunk1);
                        phrase1.add(chunk2);

                        p = new Paragraph();
                        p.add(phrase1);
                    }
                    PdfPCell pcell = new PdfPCell();
                    if (!scoreAvg.equals("")) {
                        pcell = new PdfPCell(new Paragraph(p));
                        pcell.setPadding(0);
                        pcell.setPaddingTop(2);
                        pcell.setPaddingBottom(4);
                    } else {
                        if (!jobjAppraisal.isNull(compDataIndex[k])) {
                            String htmlStr = jobjAppraisal.getString(compDataIndex[k]);
                            htmlStr = htmlStr.replaceAll("\n", "<br>");
                            StyleSheet st = new StyleSheet();
                            st.loadTagStyle("body", "face", "HELVETICA");
                            st.loadTagStyle("body", "size", "1");
                            st.loadTagStyle("body", "leading", "8,0");
                            HTMLWorker worker = new HTMLWorker(document);
                            StringReader stringReader = new StringReader(htmlStr);
                            ArrayList listStr = HTMLWorker.parseToList(stringReader, st);
                            pcell.setPadding(4);
                            for (int htmlCount = 0; htmlCount < listStr.size(); ++htmlCount) {
                                if (!listStr.get(htmlCount).toString().equals("[]"))
                                    pcell.addElement((Element) listStr.get(htmlCount));
                            }
                        } else
                            pcell = new PdfPCell(new Paragraph(
                                    !jobjAppraisal.isNull(compDataIndex[k])
                                            ? hrmsManager.serverHTMLStripper(
                                                    jobjAppraisal.getString(compDataIndex[k]))
                                            : "",
                                    fontSmallRegular));
                    }
                    pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                    pcell.setBorderColor(Color.GRAY);
                    pcell.setHorizontalAlignment(
                            compDataIndex[k].equals("comptename") || compDataIndex[k].equals("comptdesc")
                                    || compDataIndex[k].equals("selfcomment") ? Element.ALIGN_LEFT
                                            : Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(
                            compDataIndex[k].equals("comptdesc") || compDataIndex[k].equals("comptdesc")
                                    || compDataIndex[k].equals("selfcomment") ? Element.ALIGN_LEFT
                                            : Element.ALIGN_CENTER);
                    compTable.addCell(pcell);

                } else {
                    jarr2 = jobjAppraisal.getJSONArray("comments");
                    managerComments = "";
                    int commentCount = 1;
                    for (int j = jarr2.length() - 1; j >= 0; j--) {
                        jobjTemplate = jarr2.getJSONObject(j);
                        managerComments += commentCount + ")  " + jobjTemplate.getString("managercomment")
                                + "\n\n";
                        commentCount++;
                    }
                    PdfPCell pcell = new PdfPCell(new Paragraph(managerComments, fontSmallRegular));
                    pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                    pcell.setPadding(4);
                    pcell.setBorderColor(Color.GRAY);
                    pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    pcell.setVerticalAlignment(Element.ALIGN_LEFT);
                    compTable.addCell(pcell);
                }
            }
        }

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

        PdfPCell pcell = new PdfPCell(new Paragraph(
                "Mod Avg. : Average of ratings after excluding a minimum and a maximum rating. For e.g, mod average of 2, 3, 2, 4, 5, 3 is (2+3+4+3)/4",
                helpFont));
        pcell.setBorder(0);
        pcell.setPadding(4);
        pcell.setHorizontalAlignment(Element.ALIGN_LEFT);
        helpTable.addCell(pcell);

        document.add(compTable);
        if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) {
            if (hrmsManager.checkModule("modaverage", session, request, companyid)) {
                document.add(helpTable);
            }
        } else {
            if (hrmsManager.checkModule("modaverage", session, request)) {
                document.add(helpTable);
            }
        }

        if (!StringUtil.isNullOrEmpty(goalstr)) {
            PdfPTable compgTable = new PdfPTable(6);
            compgTable.setWidthPercentage(100);
            compgTable.setWidths(new float[] { 50, 60, 30, 50, 42, 70 });
            compgTable.setSpacingBefore(20);
            compgTable.setHeaderRows(1);
            for (int i = 0; i < compGoalHeader.length; i++) {
                PdfPCell pgcell = new PdfPCell(new Paragraph(compGoalHeader[i], fontMediumBold));
                pgcell.setBorder(0);
                pgcell.setBorder(PdfPCell.BOX);
                pgcell.setPadding(4);
                pgcell.setBorderColor(Color.GRAY);
                pgcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                compgTable.addCell(pgcell);
            }
            JSONObject jobjTemplates = new JSONObject(goalstr);
            com.krawler.utils.json.base.JSONArray jarr11 = jobjTemplates.getJSONArray("data");
            JSONObject jobjl = new JSONObject();
            for (int i = 0; i < jarr11.length(); i++) {
                jobjl = jarr11.getJSONObject(i);
                for (int k = 0; k < compGoalHeader.length; k++) {
                    pcell = new PdfPCell(
                            new Paragraph(
                                    !jobjl.isNull(compGoalDataIndex[k]) ? StringUtil
                                            .serverHTMLStripper(jobjl.getString(compGoalDataIndex[k])) : "",
                                    fontSmallRegular));
                    pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT);
                    pcell.setBorderColor(Color.GRAY);
                    pcell.setPadding(4);
                    pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    pcell.setVerticalAlignment(Element.ALIGN_CENTER);
                    compgTable.addCell(pcell);
                }
            }
            document.add(compgTable);

            document.newPage();
            document.close();
        }
        if (!StringUtil.isNullOrEmpty(request.getParameter("pdfEmail"))) {
            String ipaddr = "";
            if (StringUtil.isNullOrEmpty(request.getHeader("x-real-ip"))) {
                ipaddr = request.getRemoteAddr();
            } else {
                ipaddr = request.getHeader("x-real-ip");
            }
            User u = (User) session.get(User.class, request.getParameter("d"));
            User u1 = (User) session.get(User.class, request.getParameter("userid"));
            Appraisalcycle appcy = (Appraisalcycle) session.get(Appraisalcycle.class,
                    request.getParameter("appraisalcycid"));
            //AuditAction action = (AuditAction) session.load(AuditAction.class, AuditAction.Appraisal_Report_Download);
            String details = "";
            if (StringUtil.equal(request.getParameter("d"), request.getParameter("userid"))) {
                details = "User " + u.getFirstName() + " " + u.getLastName() + " has downloaded self"
                        + " appraisal report for appraisal cycle " + appcy.getCyclename()
                        + " through email link";
            } else {
                details = "Reviewer " + u.getFirstName() + " " + u.getLastName() + " has downloaded "
                        + u1.getFirstName() + " " + u1.getLastName() + "'s"
                        + " appraisal report for appraisal cycle " + appcy.getCyclename()
                        + " through email link";
            }
            tx = session.beginTransaction();
            //@@ProfileHandler.insertAuditLog(session, action, details, ipaddr, u);
            tx.commit();
        } else {
            String details = "";
            User u = null;
            String appCycleID = request.getParameter("appraisalcycid");
            Appraisalcycle appcy = (Appraisalcycle) session.get(Appraisalcycle.class, appCycleID);
            String userID = request.getParameter("userid");
            if (StringUtil.isNullOrEmpty(userID)) {
                userID = AuthHandler.getUserid(request);
                u = (User) session.get(User.class, userID);
                details = "User " + AuthHandler.getFullName(u) + " has downloaded self"
                        + " appraisal report for appraisal cycle " + appcy.getCyclename()
                        + " through Deskera HRMS";
            } else {
                u = (User) session.get(User.class, userID);

                details = "Reviewer "
                        + AuthHandler
                                .getFullName((User) session.get(User.class, AuthHandler.getUserid(request)))
                        + " has downloaded " + AuthHandler.getFullName(u) + "'s"
                        + " appraisal report for appraisal cycle " + appcy.getCyclename()
                        + " through Deskera HRMS";
            }
            tx = session.beginTransaction();
            //@@ProfileHandler.insertAuditLog(session, AuditAction.Appraisal_Report_Download,details,request);
            tx.commit();
        }
    } catch (DocumentException ex) {
        throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", ex);
    } catch (JSONException e) {
        throw ServiceException.FAILURE("AppraisalDetails.AppraisalDetail", e);
    } catch (Exception ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw ServiceException.FAILURE(ex.getMessage(), ex);
    } finally {
        writer.close();
    }
    return baos;

}

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 w  w w  .j a  va 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.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);/*  w w w.  ja va 2  s . co  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(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.ExportServlet.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  w  w w  .  ja  va  2s  .c om
    java.util.Date dt = new java.util.Date();
    String date = "yyyy-MM-dd";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(date);
    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   -----------
}