Example usage for com.itextpdf.text PageSize A4

List of usage examples for com.itextpdf.text PageSize A4

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.itextpdf.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java

public void createPdf(String contextPath, String outputFileName, String unitssId, String voyContent)
        throws Exception {
    LclUnitSs lclUnitSs = new LclUnitSsDAO().findById(Long.parseLong(unitssId));
    String voyageNo = lclUnitSs.getLclSsHeader().getScheduleNo();
    String unitNo = lclUnitSs.getLclUnit().getUnitNo();
    document = new Document();
    document.setPageSize(PageSize.A4);
    document.setMargins(8, 2, 8, 8);/*from w  w w .  ja  v  a2 s  .  c  om*/
    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
    document.open();
    document.add(onStartPage(contextPath, voyageNo, unitNo, voyContent));
    document.add(voyInfo(lclUnitSs));
    document.add(unitInfo(lclUnitSs));
    document.add(dispoInfo(lclUnitSs));
    document.add(voyContent(voyContent));
    document.add(thankyouMsg(contextPath));
    document.close();
}

From source file:com.gp.cong.logisoft.reports.DeliveryOrderPdfCreator.java

public void initialize(String fileName, FclBl bl) throws FileNotFoundException, DocumentException, Exception {
    document = new Document(PageSize.A4);
    document.setMargins(4, 4, 4, 4);//from   w w  w.  j a v a 2 s.c o m
    pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();
}

From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java

public void createPdf(String realPath, String outputFileName, Long notificationId, String companyName,
        LclFileNumber fileNumber) throws DocumentException, IOException, Exception {
    LclExportNotiFicationForm lclExportNotiFicationForm = new LclExportsVoyageNotificationDAO()
            .getNotificationDetail(notificationId);
    LclSsDetail lclSsDetail = null;/* www  .j av  a2 s.co m*/
    String pod = "", finalDest = "";
    String voyageHeading = "Voyage Notification";

    if (lclExportNotiFicationForm != null) {
        lclSsDetail = new LclSsDetailDAO().findByTransMode(lclExportNotiFicationForm.getHeaderId(), "V");
        if (lclSsDetail != null) {
            pod = new LclUtils().getConcatenatedOriginByUnlocation(lclSsDetail.getArrival());
            finalDest = new LclUtils()
                    .getConcatenatedOriginByUnlocation(lclSsDetail.getLclSsHeader().getDestination());
        }
    }
    companyCode = new SystemRulesDAO().getSystemRules("CompanyCode");
    String path = LoadLogisoftProperties.getProperty(
            companyCode.equalsIgnoreCase("03") ? "application.image.logo" : "application.image.econo.logo");

    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, new FileOutputStream(outputFileName));
    document.open();
    document.add(imageBlock(realPath, path));
    document.add(headerPage(voyageHeading));
    document.add(informationBlock(companyName, pod, finalDest));
    document.add(changesBlock(lclSsDetail, lclExportNotiFicationForm));
    document.add(containerBlock(companyName, finalDest, fileNumber, lclExportNotiFicationForm));
    document.add(reasonBlock(lclExportNotiFicationForm));
    document.add(footerBlock());
    document.close();
}

From source file:com.havoc.hotel.util.BookingPdf.java

public static String generateBookingPDF(Booking booking)
        throws DocumentException, FileNotFoundException, IOException {
    Document document = new Document(PageSize.A4);
    String bookingname = booking.getFirstName() + " " + booking.getLastName();
    document.addHeader("HOTEL HAVOC", "Hotel havoc Booking confirmation");
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(FILE + "Booking" + "" + booking.getCustomer().getFirstName() + ".pdf "));
    writer.setViewerPreferences(PdfWriter.PageModeUseOC);
    writer.setPdfVersion(PdfWriter.VERSION_1_7);
    document.open();/* w  w  w  .ja  v a  2s . c o  m*/
    String html = htmlTemplate(booking);

    List unorderedList = new List(List.UNORDERED);

    unorderedList.add(new ListItem("Name       :" + booking.getFirstName() + " " + booking.getLastName()));
    //        unorderedList.add(new ListItem("Room Price :" + booking.getRoom().getRoomPrice()));
    unorderedList.add(new ListItem("Total Price :" + booking.getTotalPrice()));
    unorderedList.add(new ListItem("check in   :" + booking.getCheckinDate()));
    unorderedList.add(new ListItem("Total Nights:" + booking.getTotalNights()));
    unorderedList.add(new ListItem("check out  :" + booking.getCheckoutDate()));
    unorderedList.add(new ListItem("Booked By  :" + booking.getCustomer().getUsername()));

    document.add(unorderedList);
    document.close();
    return bookingname;

}

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;/*from  w w  w . j a  v a  2  s. c  om*/
    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  w  w  w . j a  v  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.icebreak.p2p.front.controller.trade.download.InvestReceiptPDFCreator.java

/**
 * ???/*  w w w  .ja v  a  2s .c om*/
 * @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.incosyz.sms.other.SendOrderMail.java

public void savePdf(GETOrderModel gETOrderModel, String savePath) throws IOException, DocumentException {
    String html = getHTML(gETOrderModel);
    File file = new File("./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html");
    //            file.createNewFile();
    FileWriter fileWriter = new FileWriter(file);
    BufferedWriter bw = new BufferedWriter(fileWriter);
    bw.write(html);//  www .j  a  va2s.  c om
    bw.close();

    Document d = new Document(PageSize.A4);
    String filePath = savePath + ".pdf";

    FileOutputStream fileOutputStream = new FileOutputStream(filePath);
    PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream);

    d.addAuthor("Incosyz");
    d.addTitle("Sale Detail");
    d.addTitle("Sale Detail");

    d.open();

    FileInputStream fileInputStream = new FileInputStream(file);
    XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream);

    d.close();
    fileOutputStream.close();

    if (file.isFile()) {
        file.delete();
    }

}

From source file:com.incosyz.sms.other.SendOrderMail.java

public void sendOrder(GETOrderModel gETOrderModel, String txt) throws IOException, MessagingException {
    try {/*  w  ww.  j  a v a 2 s. c om*/
        String html = getHTML(gETOrderModel);
        File file = new File(
                "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html");
        //            file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fileWriter);
        bw.write(html);
        bw.close();

        Document d = new Document(PageSize.A4);
        String filePath = "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".pdf";

        FileOutputStream fileOutputStream = new FileOutputStream(filePath);
        PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream);

        d.addAuthor("Incosyz");
        d.addTitle("Sale Detail");
        d.addTitle("Sale Detail");

        d.open();

        FileInputStream fileInputStream = new FileInputStream(file);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream);

        d.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText("");
        mailSender.setSubject(txt + " Sale Detail Round No : " + gETOrderModel.getOrderModel().getRoundNo()
                + "  | Order Amount : Rs "
                + CurrancyFormat.getCurrancyFormat(gETOrderModel.getOrderModel().getOrderAmount()));
        mailSender.setAttachmentPath(filePath);
        mailSender.sendMail();

        if (file.isFile()) {
            File f = new File(filePath);
            f.delete();
            file.delete();
        }

    } catch (DocumentException ex) {
        Logger.getLogger(SendOrderMail.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java

public void sendPdf(ArrayList<CheckModel> checkModels, String chequeDescription)
        throws DocumentException, MessagingException {
    try {/*from   w  w w . j a va2 s  .  c  o m*/

        String html = getHTML(checkModels, chequeDescription);

        Document document = new Document(PageSize.A4.rotate());

        String path = "./src/com/incosyz/sms/temp/tmporders.pdf";
        File f = new File(path);
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream);

        document.open();

        StringReader fileReader = new StringReader(html);
        XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader);

        document.close();
        fileOutputStream.close();

        MailSender mailSender = new MailSender();
        MimeBodyPart body = (MimeBodyPart) mailSender.getBody();
        body.setText(html, "utf-8", "html");
        mailSender.setAttachmentPath(path);
        mailSender.setSubject(chequeDescription);
        mailSender.sendMail();
    } catch (IOException ex) {
        Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}