Example usage for com.itextpdf.text Chunk NEWLINE

List of usage examples for com.itextpdf.text Chunk NEWLINE

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk NEWLINE.

Prototype

Chunk NEWLINE

To view the source code for com.itextpdf.text Chunk NEWLINE.

Click Source Link

Document

This is a Chunk containing a newline.

Usage

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void addQuestionText(Paragraph paragraph, Question question, int questionnumber) throws IOException {
    String fixedFonts = question.questiontext.replace("font-size: 12pt", "font-size: 10pt");

    fixedFonts = fixedFonts.replace("face=\"courier new\"", "face=\"Courier\"");

    fixedFonts = fixedFonts.replace("src=\"media/", getPathToMedia());

    ArrayList<Element> htmllist = (ArrayList<Element>) HTMLWorker.parseToList(new StringReader(fixedFonts),
            null);//  w  w  w.j  av a2s .c  om

    ArrayList<Paragraph> codeParagraphs = new ArrayList<Paragraph>();

    for (int i = 0; i < htmllist.size(); i++) {
        Element e = htmllist.get(i);
        if (e instanceof Paragraph) {
            Paragraph p = (Paragraph) e;
            if (i == 0) {
                p.setIndentationLeft(INDENTATION);
                p.getFont().setSize(OVERALLFONTSIZE);
                p.add(0, getQuestionNumberChunk(p.getFont(), questionnumber));
                p.add(getPointsChunk(p.getFont(), question));
                paragraph.add(p);
            } else {
                codeParagraphs.add(p);
            }
        }
    }
    if (codeParagraphs.size() > 0) {
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(90);
        table.setKeepTogether(true);

        Paragraph codeParagraph = new Paragraph();

        for (Paragraph p : codeParagraphs) {
            p.setIndentationLeft(INDENTATION);
            p.getFont().setSize(OVERALLFONTSIZE);
            codeParagraph.add(p);
            fixFonts(p);
        }
        codeParagraph.add(Chunk.NEWLINE);

        PdfPCell cell = new PdfPCell();
        cell.addElement(codeParagraph);
        cell.setBorderColor(BaseColor.BLACK);
        table.addCell(cell);

        paragraph.add(Chunk.NEWLINE);
        paragraph.add(table);
    }
}

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void addAnswerTexts(Paragraph paragraph, boolean showCorrectAnswer, Question question) {
    if (question.basetype == BaseType.IDENTIFIER) {
        List list = new List(false, 20);

        list.setListSymbol(SQUARE_CHUNK);
        for (String key : question.answers.keySet()) {
            String answer = question.answers.get(key);

            Double points = question.points.get(key);
            points = points == null ? 0 : points;
            if (showCorrectAnswer) {
                ListItem item = new ListItem(answer);
                item.getFont().setSize(OVERALLFONTSIZE);

                if (points > 0) {
                    item.getFont().setColor(39, 158, 35);
                } else {
                    // item.getFont().setColor(255, 0, 0);
                }// www . j  a v  a 2  s .c  o m
                list.add(item);
            } else {
                ListItem item = new ListItem(answer);
                item.getFont().setSize(OVERALLFONTSIZE);
                list.add(item);
            }
        }

        paragraph.add(Chunk.NEWLINE);
        paragraph.add(list);
    } else if (question.basetype == BaseType.STRING) {
        paragraph.add(Chunk.NEWLINE);
        paragraph.add(Chunk.NEWLINE);

        if (showCorrectAnswer) {
            String key = question.points.keySet().iterator().next();
            Double points = question.points.get(key);

            paragraph.add(new Phrase(getXes(points) + " " + LocaleStrings.getString("answer") + " " + key));
        } else {
            paragraph.add(new Phrase(LocaleStrings.getString("answerLine")));
        }
    }
}

From source file:com.hris.payroll.reports.AdvancesReportPdf.java

public AdvancesReportPdf(int branchId, Date payrollDate, String reportType) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;
    this.reportType = reportType;

    Document document = null;/* w  w w.  j  a  va 2  s.  com*/
    Rectangle pageSize = new Rectangle(318, 825);

    try {
        document = new Document(PageSize.A4.rotate(), 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        int tradeId = cs.getTradeIdByBranchId(branchId);
        int corporateId = cs.getCorporateIdByTradeId(tradeId);

        Paragraph reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase(cs.getCorporateById(corporateId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Trade: " + cs.getTradeById(tradeId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Branch: " + cs.getBranchById(getBranchId()).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Advances Type: " + getReportType(), content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Payroll Period: " + CommonUtil.changeDateFormat(
                ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate()).getPayrollDate().toString()),
                content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Cut-off Date: "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodFrom().toString())
                + " - "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodTo().toString()),
                content));
        document.add(reportHeader);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(3);
        //            table.setWidthPercentage(100);
        table.setTotalWidth(new float[] { 180, 120, 300 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        PdfPCell cellLabel = new PdfPCell();
        Paragraph parLabel = new Paragraph();
        parLabel.add(new Phrase("EMPLOYEE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("AMOUNT", boldFont));
        parLabel.setAlignment(Element.ALIGN_RIGHT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("PARTICULARS", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        String middlename;
        double grandTotalAmount = 0;
        double subTotalAmount;
        int prCounter = 0;
        int advancesCounter;
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            if (pr.getMiddlename().isEmpty() || pr.getMiddlename() == null) {
                middlename = "";
            } else {
                middlename = pr.getMiddlename().toUpperCase();
            }
            String employee = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " "
                    + middlename;
            subTotalAmount = 0;
            advancesCounter = 0;
            for (Advances a : as.findByPayroll(pr.getPayrollId(), getReportType())) {
                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                if (advancesCounter == 0) {
                    parLabel.add(new Phrase(employee, content));
                } else {
                    parLabel.add(new Phrase("", content));
                }
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(CommonUtil.formatNumValue(a.getAmount()), content));
                parLabel.setAlignment(Element.ALIGN_RIGHT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                subTotalAmount = subTotalAmount + a.getAmount();
                advancesCounter++;
                if (advancesCounter == as.findByPayroll(pr.getPayrollId(), getReportType()).size()) {
                    cellLabel.setBorder(Rectangle.BOTTOM);
                } else {
                    cellLabel.setBorder(Rectangle.NO_BORDER);
                }
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getParticulars(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);
            }

            if (subTotalAmount != 0) {
                subTotal(table, subTotalAmount);
            }

            grandTotalAmount = grandTotalAmount + subTotalAmount;
            prCounter++;
        }

        grandTotal(table, grandTotalAmount);
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AdvancesReportPdf.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }

}

From source file:com.hris.payroll.reports.AdvancesSummaryReportPdf.java

public AdvancesSummaryReportPdf(int branchId, Date payrollDate) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;

    Document document = null;/*from   www  .  jav  a2  s.com*/
    Rectangle pageSize = new Rectangle(318, 825);

    try {
        document = new Document(PageSize.A4.rotate(), 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        int tradeId = cs.getTradeIdByBranchId(branchId);
        int corporateId = cs.getCorporateIdByTradeId(tradeId);

        Paragraph reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase(cs.getCorporateById(corporateId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Trade: " + cs.getTradeById(tradeId).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Branch: " + cs.getBranchById(getBranchId()).toUpperCase(), header));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Advances Summary", content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Payroll Period: " + CommonUtil.changeDateFormat(
                ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate()).getPayrollDate().toString()),
                content));
        document.add(reportHeader);

        reportHeader = new Paragraph();
        reportHeader.setAlignment(Element.ALIGN_LEFT);
        reportHeader.add(new Phrase("Cut-off Date: "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodFrom().toString())
                + " - "
                + CommonUtil.changeDateFormat(ps.findPayrollRegisterByBranch(getBranchId(), getPayrollDate())
                        .getAttendancePeriodTo().toString()),
                content));
        document.add(reportHeader);

        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(4);
        //            table.setWidthPercentage(100);
        table.setTotalWidth(new float[] { 180, 120, 130, 300 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

        PdfPCell cellLabel = new PdfPCell();
        Paragraph parLabel = new Paragraph();
        parLabel.add(new Phrase("EMPLOYEE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("AMOUNT", boldFont));
        parLabel.setAlignment(Element.ALIGN_RIGHT);
        cellLabel.addElement(parLabel);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("ADVANCES TYPE", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        cellLabel = new PdfPCell();
        parLabel = new Paragraph();
        parLabel.add(new Phrase("PARTICULARS", boldFont));
        parLabel.setAlignment(Element.ALIGN_LEFT);
        cellLabel.addElement(parLabel);
        cellLabel.setPaddingLeft(20);
        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellLabel.setBorder(Rectangle.BOTTOM);
        table.addCell(cellLabel);

        String middlename;
        double grandTotalAmount = 0;
        double subTotalAmount;
        int prCounter = 0;
        int advancesCounter;
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            if (pr.getMiddlename().isEmpty() || pr.getMiddlename() == null) {
                middlename = "";
            } else {
                middlename = pr.getMiddlename().toUpperCase();
            }
            String employee = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " "
                    + middlename;
            subTotalAmount = 0;
            advancesCounter = 0;
            for (Advances a : as.findByPayroll(pr.getPayrollId())) {
                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                if (advancesCounter == 0) {
                    parLabel.add(new Phrase(employee, content));
                } else {
                    parLabel.add(new Phrase("", content));
                }
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(CommonUtil.formatNumValue(a.getAmount()), content));
                parLabel.setAlignment(Element.ALIGN_RIGHT);
                cellLabel.addElement(parLabel);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                subTotalAmount = subTotalAmount + a.getAmount();
                advancesCounter++;
                if (advancesCounter == as.findByPayroll(pr.getPayrollId()).size()) {
                    cellLabel.setBorder(Rectangle.BOTTOM);
                } else {
                    cellLabel.setBorder(Rectangle.NO_BORDER);
                }
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getAdvanceType(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);

                cellLabel = new PdfPCell();
                parLabel = new Paragraph();
                parLabel.add(new Phrase(a.getParticulars(), content));
                parLabel.setAlignment(Element.ALIGN_LEFT);
                cellLabel.addElement(parLabel);
                cellLabel.setPaddingLeft(20);
                cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellLabel.setBorder(Rectangle.NO_BORDER);
                table.addCell(cellLabel);
            }

            if (subTotalAmount != 0) {
                subTotal(table, subTotalAmount);
            }

            grandTotalAmount = grandTotalAmount + subTotalAmount;
            prCounter++;
        }

        grandTotal(table, grandTotalAmount);
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AdvancesReportPdf.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

From source file:com.hrms.struts.Reportsaction.java

public String employeePdf() {
    HttpServletResponse res = ServletActionContext.getResponse();
    Rectangle envelope = new Rectangle(1300, 1300);
    Document d = new Document(envelope, 10f, 10f, 100f, 0f);
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    d.addTitle("Salary Abstract For the Month of JUNE 2016");
    Font ffont = new Font(Font.FontFamily.TIMES_ROMAN, 25, Font.BOLD);

    try {//from   w  w w  .  j  a  v a 2  s.co m
        String date = object.getEmpdate();
        System.out.println("ssdff" + date);
        SimpleDateFormat s1 = new SimpleDateFormat("dd-MM-yy");
        Date d1 = s1.parse(date);
        System.out.println("Date is [[[[[[[[[[[[[[[" + d1);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        System.out.println("Incentives year year isssssssss" + year);

        String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August",
                "September", "October", "November", "December" };
        String newmonth = monthNames[month - 1];

        Chunk reportTitle = new Chunk("Pay Sheet  For the Month of " + newmonth + year, ffont);

        Phrase p = new Phrase(reportTitle);
        //  p.add(reportTitle);
        Paragraph para = new Paragraph();
        para.add(p);
        para.setAlignment(Element.ALIGN_CENTER);
        PdfWriter.getInstance(d, b);

        Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD);
        //     Phrase  zzz=new Phrase("S. No",boldFont);
        Phrase one = new Phrase("Dept Name", boldFont);
        Phrase two = new Phrase("Days", boldFont);
        Phrase five = new Phrase("Wage", boldFont);
        Phrase four = new Phrase("Earn", boldFont);
        Phrase three = new Phrase("Inc", boldFont);
        Phrase six = new Phrase("Gross Salary", boldFont);
        Phrase seven = new Phrase("PF", boldFont);
        Phrase seven2 = new Phrase("Salary Advance", boldFont);
        Phrase eight = new Phrase("Cash Loan", boldFont);
        Phrase nine = new Phrase("Gas Loan", boldFont);
        Phrase ten = new Phrase("Tra Loan", boldFont);
        Phrase ten4 = new Phrase("Power", boldFont);
        Phrase ten5 = new Phrase("Meals", boldFont);
        Phrase ten6 = new Phrase("Tiffin", boldFont);
        Phrase ten7 = new Phrase("Tea", boldFont);
        Phrase ten8 = new Phrase("Store", boldFont);
        Phrase ten9 = new Phrase("Medicines", boldFont);
        Phrase ten11 = new Phrase("Cable", boldFont);
        Phrase one1 = new Phrase("Gas", boldFont);
        Phrase two1 = new Phrase("Adv2", boldFont);
        Phrase five1 = new Phrase("Eggs", boldFont);
        Phrase four1 = new Phrase("Uniform", boldFont);
        Phrase three1 = new Phrase("Total Deductions", boldFont);
        Phrase six1 = new Phrase("Net Salary", boldFont);

        //   PdfPCell pdfWordCel1zz= new PdfPCell();                
        PdfPCell pdfWordCell1 = new PdfPCell();
        PdfPCell pdfWordCell2 = new PdfPCell();
        PdfPCell pdfWordCell3 = new PdfPCell();
        PdfPCell pdfWordCell4 = new PdfPCell();
        PdfPCell pdfWordCell5 = new PdfPCell();
        PdfPCell pdfWordCell6 = new PdfPCell();
        PdfPCell pdfWordCell7 = new PdfPCell();
        PdfPCell pdfWordCell8 = new PdfPCell();
        PdfPCell pdfWordCell9 = new PdfPCell();
        PdfPCell pdfWordCell10 = new PdfPCell();
        PdfPCell pdfWordCell11 = new PdfPCell();
        PdfPCell pdfWordCell12 = new PdfPCell();
        PdfPCell pdfWordCell13 = new PdfPCell();
        PdfPCell pdfWordCell14 = new PdfPCell();
        PdfPCell pdfWordCell15 = new PdfPCell();
        PdfPCell pdfWordCell16 = new PdfPCell();
        PdfPCell pdfWordCell17 = new PdfPCell();
        PdfPCell pdfWordCell18 = new PdfPCell();
        PdfPCell pdfWordCell19 = new PdfPCell();
        PdfPCell pdfWordCell20 = new PdfPCell();
        PdfPCell pdfWordCell21 = new PdfPCell();
        PdfPCell pdfWordCell22 = new PdfPCell();
        PdfPCell pdfWordCell23 = new PdfPCell();
        PdfPCell pdfWordCell24 = new PdfPCell();

        //    pdfWordCel1zz.addElement(zzz);
        pdfWordCell1.addElement(one);
        pdfWordCell2.addElement(two);
        pdfWordCell3.addElement(five);
        pdfWordCell4.addElement(four);
        pdfWordCell5.addElement(three);
        pdfWordCell6.addElement(six);
        pdfWordCell7.addElement(seven);
        pdfWordCell8.addElement(seven2);
        pdfWordCell9.addElement(eight);
        pdfWordCell10.addElement(nine);
        pdfWordCell11.addElement(ten);
        pdfWordCell12.addElement(ten4);
        pdfWordCell13.addElement(ten5);
        pdfWordCell14.addElement(ten6);
        pdfWordCell15.addElement(ten7);
        pdfWordCell16.addElement(ten8);
        pdfWordCell17.addElement(ten9);
        pdfWordCell18.addElement(ten11);

        pdfWordCell19.addElement(one1);
        pdfWordCell20.addElement(two1);
        pdfWordCell21.addElement(five1);
        pdfWordCell22.addElement(four1);
        pdfWordCell23.addElement(three1);
        pdfWordCell24.addElement(six1);

        d.open();
        PdfPTable table = new PdfPTable(24);

        table.setTotalWidth(1250);
        //table.setWidths(new int[] {40,40});
        table.setLockedWidth(true);

        //            table.addCell( pdfWordCel1zz );
        table.addCell(pdfWordCell1);
        table.addCell(pdfWordCell2);

        table.addCell(pdfWordCell3);
        table.addCell(pdfWordCell4);
        table.addCell(pdfWordCell5);
        table.addCell(pdfWordCell6);
        table.addCell(pdfWordCell7);
        table.addCell(pdfWordCell8);
        table.addCell(pdfWordCell9);
        table.addCell(pdfWordCell10);
        table.addCell(pdfWordCell11);
        table.addCell(pdfWordCell12);
        table.addCell(pdfWordCell13);
        table.addCell(pdfWordCell14);
        table.addCell(pdfWordCell15);
        table.addCell(pdfWordCell16);
        table.addCell(pdfWordCell17);
        table.addCell(pdfWordCell18);
        table.addCell(pdfWordCell19);
        table.addCell(pdfWordCell20);
        table.addCell(pdfWordCell21);
        table.addCell(pdfWordCell22);
        table.addCell(pdfWordCell23);
        table.addCell(pdfWordCell24);

        Connection connection = null;
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hrmsdp_10", "root",
                "nivriti@123");
        Statement st = connection.createStatement();
        CallableStatement st1 = null;
        String sql = "{Call deptwise1(?,?)}";
        st1 = connection.prepareCall(sql);
        st1.setString(1, newmonth);
        st1.setInt(2, year);
        int days2 = 0;
        int wage2 = 0;
        int earn2 = 0;
        int inc2 = 0;
        int gross2 = 0;
        int pf2 = 0;
        int sal_adv2 = 0;
        int cash2 = 0;
        int gasl2 = 0;
        int tra2 = 0;
        int power2 = 0;
        int meals2 = 0;
        int tiffin2 = 0;
        int tea2 = 0;
        int store2 = 0;
        int medi2 = 0;
        int cable2 = 0;
        int gas22 = 0;
        int adv22 = 0;
        int eggs2 = 0;
        int unif2 = 0;
        int tot_ded2 = 0;
        int net_sal2 = 0;
        ResultSet rs = st1.executeQuery();
        while (rs.next()) {
            table.addCell(rs.getString("dept_name"));
            table.addCell(rs.getString("sum(distinct days)"));
            table.addCell(rs.getString("wages"));
            table.addCell(rs.getString("earnings"));
            table.addCell(rs.getString("increments"));
            table.addCell(rs.getString("gross_salary"));
            table.addCell(rs.getString("pf"));
            table.addCell(rs.getString("salary_advance"));
            table.addCell(rs.getString("cash_loan"));
            table.addCell(rs.getString("gas_loan"));
            table.addCell(rs.getString("tra_loan"));
            table.addCell(rs.getString("power"));
            table.addCell(rs.getString("meals"));
            table.addCell(rs.getString("tiffin"));
            table.addCell(rs.getString("tea"));
            table.addCell(rs.getString("store"));
            table.addCell(rs.getString("medicines"));
            table.addCell(rs.getString("cable"));
            table.addCell(rs.getString("gas"));
            table.addCell(rs.getString("adv2"));
            table.addCell(rs.getString("eggs"));
            table.addCell(rs.getString("uniform"));
            table.addCell(rs.getString("total_deductions"));
            table.addCell(rs.getString("net_salary"));

            String days = rs.getString("sum(distinct days)");

            String wage = rs.getString("wages");
            int wage1 = Integer.parseInt(wage);
            String earn = (rs.getString("earnings"));
            int earn1 = Integer.parseInt(earn);
            String inc = rs.getString("increments");
            int inc1 = Integer.parseInt(inc);
            String gross_sal = rs.getString("gross_salary");
            int gross_sal1 = Integer.parseInt(gross_sal);

            String pf = rs.getString("pf");
            int pf1 = Integer.parseInt(pf);
            String sal_adv = rs.getString("salary_advance");
            int sal_adv1 = Integer.parseInt(sal_adv);
            int cash1 = 0, gas1 = 0, tra1 = 0;
            try {
                String cash = rs.getString("cash_loan");
                cash1 = Integer.parseInt(cash);
                System.out.println("Incentives month isssssssss" + newmonth);

                String gas12 = rs.getString("gas_loan");
                gas1 = Integer.parseInt(gas12);

                String tra = rs.getString("tra_loan");
                tra1 = Integer.parseInt(tra);
            } catch (NumberFormatException nm) {
                System.out.println("------------------------>" + nm);
            }
            String power = rs.getString("power");
            int power1 = Integer.parseInt(power);
            String meals = rs.getString("meals");
            int meals1 = Integer.parseInt(meals);
            String tiffin = rs.getString("tiffin");
            int tiffin1 = Integer.parseInt(tiffin);
            String tea = rs.getString("tea");
            int tea1 = Integer.parseInt(tea);
            String store = rs.getString("store");
            int store1 = Integer.parseInt(store);
            String medicines = rs.getString("medicines");
            int medicines1 = Integer.parseInt(medicines);
            String cable = rs.getString("cable");

            int cable1 = Integer.parseInt(cable);
            String gas2 = rs.getString("gas");
            int gas3 = Integer.parseInt(gas2);
            String adv2 = rs.getString("adv2");
            int adv21 = Integer.parseInt(adv2);
            String egg = rs.getString("eggs");
            int egg1 = Integer.parseInt(egg);
            String uniform = rs.getString("uniform");
            int uniform1 = Integer.parseInt(uniform);
            String tot = rs.getString("total_deductions");
            int tot1 = Integer.parseInt(tot);
            String net = rs.getString("net_salary");
            int net1 = Integer.parseInt(net);

            int days1 = Integer.parseInt(days);

            System.out.println("ddddddddddddddddddd" + days1);
            days2 = days1 + days2;
            System.out.println("ddddddddddddddddddd" + days2);
            wage2 = wage1 + wage2;
            earn2 = earn1 + earn2;
            inc2 = inc1 + inc2;
            gross2 = gross_sal1 + gross2;
            pf2 = pf1 + pf2;
            sal_adv2 = sal_adv1 + sal_adv2;
            cash2 = cash1 + cash2;
            gasl2 = gas1 + gasl2;
            tra2 = tra1 + tra2;
            power2 = power1 + power2;
            meals2 = meals1 + meals2;
            tiffin2 = tiffin1 + tiffin2;
            tea2 = tea1 + tea2;
            store2 = store1 + store2;
            medi2 = medicines1 + medi2;
            cable2 = cable1 + cable2;
            gas22 = gas3 + gas22;
            adv22 = adv21 + adv22;
            eggs2 = egg1 + eggs2;
            unif2 = uniform1 + unif2;
            tot_ded2 = tot1 + tot_ded2;
            net_sal2 = net1 + net_sal2;

        }

        String days3 = Integer.toString(days2);
        String wage3 = Integer.toString(wage2);
        String earn3 = Integer.toString(earn2);
        String inc3 = Integer.toString(inc2);
        String gross3 = Integer.toString(gross2);
        String pf3 = Integer.toString(pf2);
        String sal_adv3 = Integer.toString(sal_adv2);
        String cash3 = Integer.toString(cash2);
        String gas13 = Integer.toString(gasl2);
        String tra3 = Integer.toString(tra2);
        String power3 = Integer.toString(power2);
        String meals3 = Integer.toString(meals2);
        String tiffin3 = Integer.toString(tiffin2);
        String tea3 = Integer.toString(tea2);
        String store3 = Integer.toString(store2);
        String medi3 = Integer.toString(medi2);
        String cable3 = Integer.toString(cable2);
        String gas33 = Integer.toString(gas22);
        String adv33 = Integer.toString(adv22);
        String eggs3 = Integer.toString(eggs2);
        String unif3 = Integer.toString(unif2);
        String tot_ded3 = Integer.toString(tot_ded2);
        String net_sal3 = Integer.toString(net_sal2);
        PdfPTable table1 = new PdfPTable(24);
        Phrase total = new Phrase("TOTAL", boldFont);
        table1.setTotalWidth(1250);
        table1.setLockedWidth(true);

        table1.addCell(total);
        table1.addCell(days3);
        table1.addCell(wage3);
        table1.addCell(earn3);
        table1.addCell(inc3);
        table1.addCell(gross3);
        table1.addCell(pf3);
        table1.addCell(sal_adv3);
        table1.addCell(cash3);
        table1.addCell(gas13);
        table1.addCell(tra3);
        table1.addCell(power3);
        table1.addCell(meals3);
        table1.addCell(tiffin3);
        table1.addCell(tea3);
        table1.addCell(store3);
        table1.addCell(medi3);
        table1.addCell(cable3);
        table1.addCell(gas33);
        table1.addCell(adv33);
        table1.addCell(eggs3);
        table1.addCell(unif3);
        table1.addCell(tot_ded3);
        table1.addCell(net_sal3);

        d.add(para);
        d.add(Chunk.NEWLINE);
        d.add(Chunk.NEWLINE);
        d.add(table);
        d.add(table1);
        d.close();

    }

    catch (Exception e) {
        System.out.println(e);
    }
    byte[] bytes = null;
    bytes = b.toByteArray();
    res.setContentLength(bytes.length);
    if (bytes != null) {
        inputStream = new ByteArrayInputStream(bytes);
    }
    return "success";
}

From source file:com.hrms.struts.Reportsaction.java

public String generateemployees() {
    //    System.out.println(pdf.getEmp_id());
    //    System.out.println(pdf.getName());

    HttpServletResponse res = ServletActionContext.getResponse();
    Rectangle envelope = new Rectangle(1300, 1300);
    Document d = new Document(envelope, 10f, 10f, 100f, 0f);
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    d.addTitle("Salary Abstract For the Month of JUNE 2016");
    Font ffont = new Font(Font.FontFamily.TIMES_ROMAN, 25, Font.BOLD);

    try {/*from   w  w w.  j av  a 2s . c  om*/
        String date = object.getEmpdate();
        System.out.println("ssdff" + date);
        SimpleDateFormat s1 = new SimpleDateFormat("dd-MM-yy");
        Date d1 = s1.parse(date);
        System.out.println("Date is [[[[[[[[[[[[[[[" + d1);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        System.out.println("Incentives year year isssssssss" + year);

        String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August",
                "September", "October", "November", "December" };
        String newmonth = monthNames[month - 1];
        System.out.println("Incentives month isssssssss" + newmonth);

        Chunk reportTitle = new Chunk("Pay Sheet  For the Month of " + newmonth + year, ffont);

        Phrase p = new Phrase(reportTitle);
        //  p.add(reportTitle);
        Paragraph para = new Paragraph();
        para.add(p);
        para.setAlignment(Element.ALIGN_CENTER);
        PdfWriter.getInstance(d, b);

        PdfWriter.getInstance(d, b);

        Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD);
        Phrase two = new Phrase("Code No", boldFont);
        Phrase three = new Phrase("Name", boldFont);
        Phrase four = new Phrase("Status", boldFont);
        Phrase five = new Phrase("Dept", boldFont);
        Phrase six = new Phrase("Days", boldFont);
        Phrase seven = new Phrase("Wage", boldFont);
        Phrase eight = new Phrase("Inc", boldFont);
        Phrase nine = new Phrase("Earn", boldFont);
        Phrase ten = new Phrase("Inc Amt", boldFont);
        Phrase eleven = new Phrase("Gross Earn", boldFont);
        Phrase twelve = new Phrase("PF", boldFont);
        Phrase thirteen = new Phrase("PPP", boldFont);
        Phrase fourteen = new Phrase("PF No", boldFont);
        Phrase fifteen = new Phrase("Sal Advance", boldFont);

        PdfPCell pdfWordCell2 = new PdfPCell();
        PdfPCell pdfWordCell3 = new PdfPCell();
        PdfPCell pdfWordCell4 = new PdfPCell();
        PdfPCell pdfWordCell5 = new PdfPCell();
        PdfPCell pdfWordCell6 = new PdfPCell();
        PdfPCell pdfWordCell7 = new PdfPCell();
        PdfPCell pdfWordCell8 = new PdfPCell();
        PdfPCell pdfWordCell9 = new PdfPCell();
        PdfPCell pdfWordCell10 = new PdfPCell();
        PdfPCell pdfWordCell11 = new PdfPCell();
        PdfPCell pdfWordCell12 = new PdfPCell();
        PdfPCell pdfWordCell13 = new PdfPCell();
        PdfPCell pdfWordCell14 = new PdfPCell();
        PdfPCell pdfWordCell15 = new PdfPCell();
        PdfPCell pdfWordCell50 = new PdfPCell(new Phrase("Gas Loan", boldFont));
        PdfPCell pdfWordCell16 = new PdfPCell(new Phrase("Cash Loan", boldFont));
        PdfPCell pdfWordCell17 = new PdfPCell(new Phrase("Tra Loan", boldFont));
        PdfPCell pdfWordCell18 = new PdfPCell(new Phrase("Power", boldFont));
        PdfPCell pdfWordCell19 = new PdfPCell(new Phrase("Meals", boldFont));
        PdfPCell pdfWordCell20 = new PdfPCell(new Phrase("Tiffin", boldFont));
        PdfPCell pdfWordCell21 = new PdfPCell(new Phrase("Tea", boldFont));
        PdfPCell pdfWordCell22 = new PdfPCell(new Phrase("Store", boldFont));
        PdfPCell pdfWordCell23 = new PdfPCell(new Phrase("Medicine", boldFont));
        PdfPCell pdfWordCell24 = new PdfPCell(new Phrase("Cable", boldFont));
        PdfPCell pdfWordCell25 = new PdfPCell(new Phrase("Gas", boldFont));
        PdfPCell pdfWordCell26 = new PdfPCell(new Phrase("Adv2", boldFont));
        PdfPCell pdfWordCell27 = new PdfPCell(new Phrase("Eggs", boldFont));
        PdfPCell pdfWordCell28 = new PdfPCell(new Phrase("Uniform", boldFont));
        PdfPCell pdfWordCell29 = new PdfPCell(new Phrase("Total Deduction", boldFont));
        PdfPCell pdfWordCell30 = new PdfPCell(new Phrase("Net Salary", boldFont));
        //   PdfPCell pdfWordCell31= new PdfPCell(new Phrase("Signature", boldFont));

        pdfWordCell2.addElement(two);
        pdfWordCell3.addElement(three);
        pdfWordCell4.addElement(four);
        pdfWordCell5.addElement(five);
        pdfWordCell6.addElement(six);
        pdfWordCell7.addElement(seven);
        pdfWordCell8.addElement(eight);
        pdfWordCell9.addElement(nine);
        pdfWordCell10.addElement(ten);
        pdfWordCell11.addElement(eleven);
        pdfWordCell12.addElement(twelve);
        pdfWordCell13.addElement(thirteen);
        pdfWordCell14.addElement(fourteen);
        pdfWordCell15.addElement(fifteen);

        d.open();
        PdfPTable table = new PdfPTable(30);
        //     PdfPTable table1 = new PdfPTable(2);
        //    table.setWidths(new int[]{4,5,6,5,7,5,5,5,4,7,6,4,4,6,8,7,6,6,6,6,4,5,9,5,4,2,2,2,2,2,2});
        table.setTotalWidth(1250);
        table.setWidths(new int[] { 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 45, 40, 40, 40, 40,
                40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 });
        table.setLockedWidth(true);
        //   table.addCell(  pdfWordCell );  

        //      table.setTotalWidth(1250);
        //      table.setLockedWidth(true);

        table.addCell(pdfWordCell2);
        table.addCell(pdfWordCell3);
        table.addCell(pdfWordCell4);
        table.addCell(pdfWordCell5);
        table.addCell(pdfWordCell6);
        table.addCell(pdfWordCell7);
        table.addCell(pdfWordCell8);
        table.addCell(pdfWordCell9);
        table.addCell(pdfWordCell10);
        table.addCell(pdfWordCell11);
        table.addCell(pdfWordCell12);
        table.addCell(pdfWordCell13);
        table.addCell(pdfWordCell14);
        table.addCell(pdfWordCell15);
        table.addCell(pdfWordCell50);
        table.addCell(pdfWordCell16);
        table.addCell(pdfWordCell17);
        table.addCell(pdfWordCell18);
        table.addCell(pdfWordCell19);
        table.addCell(pdfWordCell20);
        table.addCell(pdfWordCell21);
        table.addCell(pdfWordCell22);
        table.addCell(pdfWordCell23);
        table.addCell(pdfWordCell24);
        table.addCell(pdfWordCell25);
        table.addCell(pdfWordCell26);
        table.addCell(pdfWordCell27);
        table.addCell(pdfWordCell28);
        table.addCell(pdfWordCell29);
        table.addCell(pdfWordCell30);
        // table.addCell(pdfWordCell31);

        Connection connection = null;
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hrmsdp_10", "root",
                "nivriti@123");
        //   Statement st=connection. createStatement(); 

        Statement st1 = connection.createStatement();
        CallableStatement st = null;
        String sql = "{Call emp_payslip123(?,?)}";
        st = connection.prepareCall(sql);

        st.setString(1, newmonth);
        st.setInt(2, year);
        //  String sql="Call calc(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        //  PreparedStatement st=connection.prepareStatement(sql);
        //    ResultSet rs= st.executeQuery("Call calc(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        ResultSet rs = st.executeQuery();
        while (rs.next()) {

            table.addCell(rs.getString("emp_id"));
            table.addCell(rs.getString("emp_name"));
            table.addCell(rs.getString("status"));
            table.addCell(rs.getString("dept_name"));
            table.addCell(rs.getString("days"));
            table.addCell(rs.getString("wage"));
            table.addCell(rs.getString("inc"));
            table.addCell(rs.getString("earn"));
            table.addCell(rs.getString("inc_amount"));
            table.addCell(rs.getString("gross_salary"));
            table.addCell(rs.getString("pf"));
            table.addCell(rs.getString("ppp"));
            table.addCell(rs.getString("pf_no"));
            table.addCell(rs.getString("salary_advance"));
            table.addCell(rs.getString("sum(gas_loan)"));
            table.addCell(rs.getString("sum(cash_loan)"));
            table.addCell(rs.getString("sum(tra_loan)"));
            table.addCell(rs.getString("power"));
            table.addCell(rs.getString("meals"));
            table.addCell(rs.getString("tiffin"));
            table.addCell(rs.getString("tea"));
            table.addCell(rs.getString("store"));
            table.addCell(rs.getString("medicines"));
            table.addCell(rs.getString("cable"));
            table.addCell(rs.getString("gas"));
            table.addCell(rs.getString("adv2"));
            table.addCell(rs.getString("eggs"));
            table.addCell(rs.getString("uniform"));
            table.addCell(rs.getString("total_deductions"));
            table.addCell(rs.getString("net_salary"));
            //   table.addCell("");
            // table.addCell(image);
        }
        //ResultSet rs1=st1.executeQuery("SELECT   sum(days) as days , sum(wage) as wages, sum(earn) as earn ,sum(inc) as inc,sum(gros_earn) as gross_earn,sum(sal_advance) as sal_adv,sum(cash_loan) as cash_loan,sum(gas_loan) as gas_loan,sum(tra_loan) as tra_loan,sum(power) as power,sum(meals) as meals,sum(tiffin) as tiffin,sum(tea) as tea,sum(store) as store,sum(medicines) as medicines,sum(cable) as cable,sum(gas) as gas,sum(adv2) as adv2,sum(eggs) as eggs,sum(uniform) as uniform,sum(total_deduction) as totla_deduction  FROM caluclation ");
        //            ResultSet rs1=st1.executeQuery("select sum(days),sum(wage) from caluclation");
        //      String s1=rs1.getString(1);

        //   table.setTotalWidth(PageSize.LARGE_CROWN_OCTAVO.getWidth());   
        d.add(para);
        d.add(Chunk.NEWLINE);
        d.add(Chunk.NEWLINE);
        d.add(table);
        d.close();
    } catch (Exception e) {
        System.out.println(e);
    }
    byte[] bytes = null;
    bytes = b.toByteArray();
    res.setContentLength(bytes.length);
    if (bytes != null) {
        inputStream = new ByteArrayInputStream(bytes);
    }
    return "success";
}

From source file:com.icebreak.p2p.front.controller.trade.download.InvestReceiptPDFCreator.java

/**
 * ???/*from   w w w  .j  ava 2  s  .  com*/
 * @param tradeId
 * @param detailId
 * @param servletPath
 * @return ?  byte[]
 * @throws Exception
 */
public byte[] creatFileData4Receipt(long tradeId, long detailId, String servletPath) throws Exception {

    FileInputStream fis = null;
    BufferedInputStream buff = null;

    String fileKey = tradeId + "_" + detailId;//System.currentTimeMillis() + "";
    String filePath = servletPath + "/resources/pdf/investReceipt_" + fileKey + ".pdf";
    this.receiptFilePath = filePath;

    File file = new File(filePath);

    if (!file.exists()) {

        String timeLimit = "";
        String interestRate = "";
        String guaranteeName = "";
        String investFlowCode = null;
        String investor = "";
        String investorReal = "";
        String investorCertNo = "";
        String loanner = "";
        String loannerReal = "";
        String loannerCertNo = "";
        String investAmount = "";
        String totalAmountStr = "";
        String effectiveDate = "";
        String expireDate = "";

        Trade trade = tradeService.getByTradeId(tradeId);
        effectiveDate = DateUtil.simpleFormat(trade.getEffectiveDateTime());
        expireDate = DateUtil.simpleFormat(trade.getExpireDateTime());
        LoanDemandDO loanDemand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        guaranteeName = loanDemand.getGuaranteeName();
        if ("W".equals(loanDemand.getTimeLimitUnit()) || "M".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else if ("Y".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else {
            timeLimit = loanDemand.getTimeLimit() + "";
        }
        interestRate = CommonUtil.mul(loanDemand.getInterestRate(), 100) + "%";
        List<UserInvestEntry> userInvests = tradeService.getEntriesByTradeIdAndDetailId(tradeId, detailId);
        long totalAmount = 0;
        if (userInvests != null && userInvests.size() > 0) {
            UserInvestEntry tradeItem = userInvests.get(0);
            investAmount = MoneyUtil.getFormatAmount(tradeItem.getAmount());
            long investorId = userInvests.get(0).getInvestorId();
            long loannerId = userInvests.get(0).getLoanerId();
            investorCertNo = getCertNoByUserId(investorId);
            loannerCertNo = getCertNoByUserId(loannerId);
            investor = userInvests.get(0).getInvestorUserName();
            investorReal = userInvests.get(0).getInvestorRealName();
            loannerReal = userInvests.get(0).getLoanerRealName();
            loanner = userInvests.get(0).getLoanerUserName();
            totalAmount = userInvests.get(0).getAmount();
        }

        //?
        /*interest = caculateInterest(new Money(totalAmount), loanDemand.getInterestRate(),
        loanDemand.getTimeLimit(), loanDemand.getTimeLimitUnit());*/

        long divisionAmount = 0;
        long profitAmount = 0;
        List<TradeDetail> details = tradeService.getInvestProfitTrade(detailId);
        if (details != null && details.size() > 0) {
            for (TradeDetail detail : details) {
                divisionAmount += detail.getAmount();
                if (detail.getProfitType() > 0) {
                    profitAmount += detail.getAmount();
                }
            }
        }
        totalAmount += divisionAmount;

        TradeFlowCode tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(detailId);
        if (tradeFlow != null) {
            investFlowCode = tradeFlow.getTradeFlowCode();
        }

        String guaranteeLicenseNo = "";
        Map<String, Object> cond = new HashMap<String, Object>();
        cond.put("roleId", 8L);

        cond.put("tradeId", trade.getId());
        List<TradeQueryDetail> det = loanDemandManager.getTradeDetailByConditions(cond);
        if (det != null && det.size() > 0) {
            tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(det.get(0).getId());
            if (tradeFlow != null) {
                guaranteeLicenseNo = tradeFlow.getTradeFlowCode();
            }
        }

        LoanDemandDO demand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        long divisionTemplateId = demand.getDivisionTemplateId();
        DivisionTemplateLoanDO divisionTemplateLoan = divisionTemplateLoanService
                .getByBaseId(divisionTemplateId);
        List<DivsionRuleRole> investRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getInvestTemplateId()));
        List<DivsionRuleRole> repayRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getRepayTemplateId()));
        //??
        double totalAnnualInterest = 0;
        investRolelist.addAll(repayRolelist);
        if (investRolelist != null && investRolelist.size() > 0) {
            for (DivsionRuleRole druleRole : investRolelist) {
                if (DivisionPhaseEnum.INVESET_PHASE.code().equals(druleRole.getPhase())) {
                    if ("11".equals(String.valueOf(druleRole.getRoleId()))) {
                        totalAnnualInterest += druleRole.getRule();
                    }

                }
            }
        }

        totalAmountStr = MoneyUtil.getFormatAmount(totalAmount);
        String divisionAmountStr = MoneyUtil.getFormatAmount(divisionAmount);

        FileOutputStream fos = null;
        Document doc = new Document(PageSize.A4, 20, 20, 140, 20);
        try {
            fos = new FileOutputStream(filePath);
            PdfWriter writer = PdfWriter.getInstance(doc, fos);
            doc.open();
            //   
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            Font titleChinese = new Font(bfChinese, 20, Font.BOLD); // ?     
            Paragraph title = new Paragraph(AppConstantsUtil.getProductName() + "?", titleChinese);// 
            title.setAlignment(Element.ALIGN_CENTER); // 
            title.setLeading(1f);//?//?
            doc.add(title);

            Font fontZH = new Font(bfChinese, 12, Font.NORMAL);
            float[] widths = { 20f, 30f, 25f, 25f };
            PdfPTable table = new PdfPTable(widths);

            table.setSpacingBefore(20f);// ?
            table.setTotalWidth(500);// 
            table.setWidthPercentage(100);//%100
            // table.getDefaultCell().setBorder(0);//
            PdfPCell cell;
            //               cell = new PdfPCell(new Paragraph("?",fontZH));
            //               cell.setColspan(4);
            //               table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(AppConstantsUtil.getPlatformName(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getRepayDivisionWayMsg(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(interestRate, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(timeLimit, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(guaranteeName, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Paragraph(StringUtil.nullToEmpty(loanDemand.getGuaranteeLicenseNo()), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph((loanDemand.getLoanAmount() / 100) + "", fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getLoanPurpose(), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(investFlowCode, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);

            table.addCell(cell);
            Paragraph iparas = new Paragraph("??" + investor, fontZH);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + investorReal);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + StringUtil.subString(investorCertNo, 7, "****"));
            iparas.add(Chunk.NEWLINE);
            iparas.add("?" + effectiveDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("" + expireDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + investAmount);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + divisionAmountStr);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + totalAmountStr);

            cell = new PdfPCell(iparas);
            cell.setColspan(2);
            cell.setRowspan(8);

            cell.setMinimumHeight(120);
            table.addCell(cell);
            Paragraph paras = new Paragraph("??" + loanner, fontZH);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + loannerReal);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + StringUtil.subString(loannerCertNo, 7, "****"));
            paras.add(Chunk.NEWLINE);
            paras.add("?" + effectiveDate);
            paras.add(Chunk.NEWLINE);
            paras.add("" + expireDate);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add("()" + totalAmountStr);
            cell = new PdfPCell(paras);
            cell.setColspan(2);
            cell.setRowspan(8);
            table.addCell(cell);
            doc.add(table);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            Paragraph tips = new Paragraph("  ?? ?"
                    + AppConstantsUtil.getPlatformName() + "", fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            tips = new Paragraph("  ??" + AppConstantsUtil.getPlatformAddress(), fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            //               XMLWorkerHelper.getInstance().parseXHtml(writer, doc,
            //                     new ByteArrayInputStream(str.getBytes()));
            doc.close();
            logger.info("?");

        } catch (Exception e) {
            logger.error("?", e);
            throw new Exception("?:" + e.getMessage());
        } finally {

            if (fos != null) {
                fos.close();
            }
        }
    }

    byte[] data = new byte[1024];

    file = new File(filePath);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] temp = new byte[1024];
        int size = 0;

        fis = new FileInputStream(file);
        buff = new BufferedInputStream(fis);

        int i = 0;

        while ((size = buff.read(temp)) != -1) {
            out.write(temp, 0, size);
            i += 1;
        }

        data = out.toByteArray();

        buff.close();
        fis.close();
        //file.delete();

        if (i == 0 && size == -1) { //PDF
            file.delete();
        }
    } catch (FileNotFoundException e) {
        logger.error("?", e);
    } catch (IOException e) {
        logger.error("delete file", e);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }

    return data;
}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public void addStorybookPart(Document document, int i, Long date, Long previousDate, String senderString,
        String previousSenderString, String receiverString, String contentString, Bitmap contentBitmap,
        Boolean isVideo) throws DocumentException, MalformedURLException, IOException {
    Paragraph paragraph = new Paragraph();
    if (i == 0) {
        paragraph.add(new Chunk("T", this.serifFont24));
        paragraph.add(new Chunk("his story begins", this.serifFont11));
        if (!this.settings.useTimestamps.booleanValue()) {
            paragraph.add(new Chunk(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, this.serifFont11));
        }/*  ww  w.java  2 s . c  o m*/
    } else if (!senderString.equals(previousSenderString)) {
        document.add(Chunk.NEWLINE);
    }
    Boolean dateChanged = Boolean.valueOf(false);
    if (this.settings.useTimestamps.booleanValue()) {
        SimpleDateFormat dateFormat;
        if (i == 0) {
            dateFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.US);
            dateFormat.setTimeZone(TimeZone.getDefault());
            paragraph.add(new Chunk(" on " + dateFormat.format(new Date(date.longValue()))
                    + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, this.serifFont11));
        } else {
            dateFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.US);
            dateFormat.setTimeZone(TimeZone.getDefault());
            String dateString = dateFormat.format(new Date(date.longValue()));
            String previousDateString = PdfObject.NOTHING;
            if (previousDate != null) {
                previousDateString = dateFormat.format(new Date(previousDate.longValue()));
            }
            if (!previousDateString.equals(dateString)) {
                dateChanged = Boolean.valueOf(true);
                document.add(Chunk.NEWLINE);
                paragraph.add(new Chunk("O", this.serifFont24));
                paragraph.add(new Chunk("n " + dateString + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR,
                        this.serifFont11));
            }
        }
    }
    if (i == 0) {
        paragraph.add(new Chunk("when " + senderString + " texted " + receiverString + ", ", this.serifFont11));
    }
    if (contentString.length() > 0) {
        Boolean addPhrase = Boolean.valueOf(false);
        String phrase = null;
        if (dateChanged.booleanValue()) {
            paragraph.add(new Chunk(new StringBuilder(String.valueOf(senderString)).append(" texted ")
                    .append(receiverString).append(", ").toString(), this.serifFont11));
        } else if (!(i == 0 || dateChanged.booleanValue() || senderString.equals(previousSenderString))) {
            Boolean isOpening = Boolean
                    .valueOf(this.wasLastPhraseOpening.booleanValue() ? this.generator.nextBoolean() : true);
            int phraseIdx = this.lastPhraseIdx;
            if (isOpening.booleanValue() && !this.wasLastPhraseOpening.booleanValue()) {
                this.lastPhraseIdx = -1;
            }
            if (isOpening.booleanValue()) {
                do {
                    phraseIdx = this.generator.nextInt(this.openings.length);
                } while (phraseIdx == this.lastPhraseIdx);
                phrase = this.openings[phraseIdx];
            } else {
                do {
                    phraseIdx = this.generator.nextInt(this.closings.length);
                } while (phraseIdx == this.lastPhraseIdx);
                phrase = this.closings[phraseIdx];
            }
            this.lastPhraseIdx = phraseIdx;
            this.wasLastPhraseOpening = isOpening;
            phrase = phrase.replace("[speaker]", senderString);
            addPhrase = Boolean.valueOf(true);
        }
        if (addPhrase.booleanValue() && this.wasLastPhraseOpening.booleanValue()) {
            paragraph.add(new Chunk(phrase, this.serifFont11));
        }
        paragraph.add(new Chunk("\"" + contentString.trim() + "\"", this.serifFont11));
        if (addPhrase.booleanValue() && !this.wasLastPhraseOpening.booleanValue()) {
            paragraph.add(new Chunk(phrase, this.serifFont11));
        }
        document.add(paragraph);
    } else if (contentBitmap != null) {
        if (i != 0) {
            paragraph.add(new Chunk(new StringBuilder(String.valueOf(senderString)).append(" sent ")
                    .append(receiverString).append(":").toString(), this.serifFont11));
            document.add(paragraph);
            document.add(Chunk.NEWLINE);
        }
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (isVideo.booleanValue()) {
            contentBitmap.compress(CompressFormat.PNG, 50, stream);
        } else {
            contentBitmap.compress(CompressFormat.JPEG, 50, stream);
        }
        Image contentImage = Image.getInstance(stream.toByteArray());
        contentImage.scaleToFit(445.0f, 195.0f);
        contentImage.setAlignment(1);
        if (isVideo.booleanValue()) {
            contentImage.setCompressionLevel(this.settings.compressionLevel);
        }
        document.add(contentImage);
        document.add(Chunk.NEWLINE);
    }
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private void processMacro(String buf, BaseFont base, Map it, Paragraph p)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    List<String> list = LightUtil.splitMacro(buf, '$');
    for (String ss : list) {
        Chunk ch = null;/*from  w  w  w . j  a v  a 2  s  .co  m*/
        if (ss.equals("${pageNumber}")) {
            PdfWriter writer = getWriter();
            if (writer != null)
                ss = writer.getPageNumber() + "";
            else
                ss = ThreadHelper.get("pageNumber") + "";
        } else if (ss.equals("${pageCount}")) {
            ss = ThreadHelper.get("pageCount") + "";
        } else if (ss.equals("${newPage}")) {
            ch = Chunk.NEXTPAGE;
        } else if (ss.equals("${newLine}")) {
            ch = Chunk.NEWLINE;
        }
        if (ch == null)
            ch = new Chunk(ss, new Font(base));
        applyFont(ch, it);

        String gt = MapUtil.getStr(it, "goto", null);
        if (gt != null) {
            ch.setLocalGoto(gt);
        }

        p.add(ch);
    }
}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public void generatePdf(Author author, String filename, String type) {
    // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch)

    // marginLeft, marginRight, marginTop, marginBottom
    Document document = new Document(PageSize.A4, 50, 50, 80, 50);
    try {/*from  w w  w .j  a  v  a 2  s.co m*/
        if (m_shopping_basket.size() > 0) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            writer.setBoxSize("art", new Rectangle(50, 50, 560, 790));

            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

            document.open();

            PdfContentByte cb = writer.getDirectContent();

            document.addAuthor("ywesee GmbH");
            document.addCreator("AmiKo for Windows");
            document.addCreationDate();

            // Logo
            String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png");
            File logoFile = new File(logoImageStr);
            if (!logoFile.exists())
                logoImageStr = Constants.IMG_FOLDER + "empty_logo.png";

            Image logo = Image.getInstance(logoImageStr);
            logo.scalePercent(30);
            logo.setAlignment(Rectangle.ALIGN_RIGHT);
            document.add(logo);
            document.add(Chunk.NEWLINE);

            // Bestelladresse
            // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); 
            String bestellAdrStr = getAddressAsString(BestellAdresseID);
            Paragraph p = new Paragraph(12);
            // p.setIndentationLeft(60);
            p.add(new Chunk(bestellAdrStr, font_norm_10));
            document.add(p);
            document.add(Chunk.NEWLINE);

            // Title
            p = new Paragraph(m_rb.getString("order"), font_bold_16);
            document.add(p);

            // Date
            DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date();
            p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10);
            p.setSpacingAfter(20);
            document.add(p);

            // document.add(Chunk.NEWLINE);

            // Add addresses (Lieferadresse + Rechnungsadresse)
            /* --> OLD
            String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2"));
            String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3"));              
            */
            // --> NEW
            String lieferAdrStr = getAddressAsString(LieferAdresseID);
            String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID);

            PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 });
            addressTable.setWidthPercentage(100f);
            addressTable.getDefaultCell().setPadding(5);
            addressTable.setSpacingAfter(5f);
            addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            document.add(addressTable);

            document.add(Chunk.NEWLINE);

            // Add shopping basket
            if (type.equals("specific"))
                document.add(getShoppingBasketForAuthor(author, cb));
            else if (type.equals("all"))
                document.add(getFullShoppingBasket(cb, "all"));
            else if (type.equals("rest"))
                document.add(getFullShoppingBasket(cb, "rest"));
            LineSeparator separator = new LineSeparator();
            document.add(separator);
        }
    } catch (IOException e) {

    } catch (DocumentException e) {

    }

    document.close();
    // System.out.println("Saved PDF to " + filename);
}