Example usage for com.itextpdf.text Paragraph add

List of usage examples for com.itextpdf.text Paragraph add

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph add.

Prototype

@Override
public boolean add(Element o) 

Source Link

Document

Adds an Element to the Paragraph.

Usage

From source file:com.grant.report.BillPdf.java

private void addTitlePage(Document document, PrintDetails printDetails) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//www.  j a  v  a 2 s.c o m
    // Lets write a big header
    preface.add(new Paragraph("GRANT TECH HOLDINGS", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("No, 407 A, Colombo Road, Pepiliyana", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("Tel/Fax :0112 199 100 | 0719 192 815 | 0719 392 815", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph("E-mail :granttech@sltnet.lk | granttechholdings@gmail.com", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            subFont));
    preface.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface.add(new Paragraph("Customer Name : " + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Address : " + printDetails.getAddress(), smallBold));

    preface.add(new Paragraph(
            "Date: " + printDetails.getInvoiceNo() + "                | Order No: " + printDetails.getOrderNo(),
            smallBold));

    preface.add(new Paragraph("Pay Type: " + printDetails.getPayType() + "                | Sales Code: "
            + printDetails.getCustomerName(), smallBold));

    preface.add(new Paragraph("Cheque No: " + printDetails.getNoPay(), smallBold));

    createTable(preface);

    Paragraph preface2 = new Paragraph();
    preface2.setIndentationLeft(350);

    preface2.add(new Paragraph("Sub Total : " + printDetails.getSubTotal(), smallBold));

    preface2.add(new Paragraph("Discount  : " + printDetails.getDiscount() + " %", smallBold));

    preface2.add(new Paragraph("Total  : " + printDetails.getTotal(), smallBold));

    Paragraph preface3 = new Paragraph();

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph("Goods once sold will not be taken back. ", smallBold2));

    preface3.add(new Paragraph(
            "Cheques to be drawn in favour of Grant Tech Holdings (Pvt) Ltd 1146009208-Commercial Bank-Wadduwa. ",
            verySmBold));
    preface3.add(new Paragraph("goods are accepted in good condition. ", verySmBold));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    preface3.add(new Paragraph(
            "Name:___________________________________________                          Signature:__________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "I.D No (If credit):__________________________________                          Date:______________________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "Checked by:_______________________________________                        Authorized by:_______________________________________",
            smallBold3));

    preface3.add(new Paragraph(
            "____________________________________________________________________________________", smallBold));

    // now add all this to the document
    document.add(preface);
    document.add(preface2);
    document.add(preface3);
    document.newPage();
}

From source file:com.grant.report.BillPdf.java

private void createTable(Paragraph preface) throws BadElementException, DocumentException {
    addEmptyLine(preface, 1);// w  ww. ja va  2s.c o  m
    PdfPTable table = new PdfPTable(6);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    PdfPCell c1 = new PdfPCell(new Phrase("Item Code"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Description"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Qty"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Unit"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Rate"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Amount"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    table.setHeaderRows(1);
    float[] columnWidths = new float[] { 15f, 30f, 10f, 10f, 10f, 15f };
    table.setWidths(columnWidths);

    ItemDAO dao = new ItemDAO();

    String itemName;
    String itemNo;
    String description;
    String outwards;
    String unitPrice;
    String amount;
    String unit;

    Vector<Vector<String>> data;
    data = dao.getStockOutTbl(invoNo);
    String s = data.get(0).get(1);
    for (int i = 0; i < data.size(); i++) {
        Vector<String> data2 = data.get(i);

        itemName = data.get(i).get(0);
        description = data.get(i).get(3);
        outwards = data.get(i).get(5);
        itemNo = data.get(i).get(1);
        unit = data.get(i).get(6);
        unitPrice = data.get(i).get(8);
        amount = data.get(i).get(9);

        table.addCell(itemNo);
        table.addCell(description);
        table.addCell(outwards);
        table.addCell(unit);
        table.addCell(unitPrice);
        table.addCell(amount);
    }
    preface.add(table);
}

From source file:com.groupecom2015.entitieManager.MessageFacade.java

public void sendBuyingConfirmationEmail(List<ArticlePanier> listArt, CompteUser cu) {

    Date d = new Date(System.currentTimeMillis());
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
    Font font_2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL);
    Font font_3 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    double total = 0.0;
    String resume = "";
    try {/*from w  w w . j  av  a2 s  .c o m*/
        // new File( System.getProperty( "user.home" ) +"/"+ cu.getIdCompte()).mkdirs();
        //String FILE = System.getProperty("user.home") +"/"+ cu.getIdCompte()+"/commandeRecu.pdf";
        new File("/home/umar/webapp_photo/uploads/" + cu.getIdCompte()).mkdirs();
        String FILE = "/home/umar/webapp_photo/uploads/" + cu.getIdCompte() + "/commandRecu.pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(FILE));
        document.open();

        Paragraph para = new Paragraph();
        para.add(new Paragraph(d + ""));
        para.add(new Paragraph(""));
        para.add(new Paragraph("Bonjour, " + cu.getNom(), font));
        para.add(new Paragraph("Veuillez trouvez ci-dessous votre le rsum de vos achat", font));
        para.add(new Paragraph(""));

        for (ArticlePanier l : listArt) {
            para.add(new Paragraph(
                    "" + l.getArticle().getNomArticle() + "     " + l.getArticle().getPrixVenteArticle(),
                    font_2));
            total += l.getArticle().getPrixVenteArticle();
            resume = resume + "\n" + l.getArticle().getNomArticle() + "  "
                    + l.getArticle().getPrixVenteArticle() + "\n";
        }
        para.add(new Paragraph("Total : " + total, font_3));
        para.add(new Paragraph(""));
        para.add(new Paragraph("Nous vous remercions pour votre achat", font_2));
        document.add(para);
        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

    //sending email with the pdf attached --> dropped

    final String from = "ecomgroup2015@gmail.com"; //ecomgroup2015@gmail.com
    final String to = "" + cu.getEmail();
    final String fileUpload = "/uploads/" + cu.getIdCompte() + "/commandRecu.pdf";
    try {
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.port", "587"); //587
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true");

        Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, "groupeecom");
            }
        });

        javax.mail.Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to));
        message.setSubject("Votre recipiss d'achat");
        message.setText("Bonjour " + cu.getNom() + "\n Veuillez trouvez ci-joint votre rsum d'achat\n"
                + "\n  " + resume + "  \n" + total);

        /*BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText("Cher(e) "+cu.getNom()+"\n veuillez trouver ci-joint votre recipiss d'achat");
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        messageBodyPart = new MimeBodyPart();
        String filename = "/uploads/"+cu.getIdCompte()+"/commandRecu.pdf";
        DataSource source = new FileDataSource(FILE);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(FILE);
        multipart.addBodyPart(messageBodyPart);
                
        // Send the complete message parts
        message.setContent(multipart);*/
        Transport.send(message);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.horizzon.inventerium.ExportPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from www .j a va2 s.  c om*/
    // Lets write a big header
    preface.add(new Paragraph("Transaction Details"));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(0)));
    addEmptyLine(preface, 3);
    //       preface.add(new Paragraph("This document describes something which is very important ",
    //           smallBold));

    addEmptyLine(preface, 8);

    //       preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //           redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

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   www  .ja  va2s .  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.AdvancesReportPdf.java

private void subTotal(PdfPTable table, double subTotalAmount) {
    PdfPCell cellLabel = new PdfPCell();
    Paragraph parLabel = new Paragraph();
    parLabel.add(new Phrase("", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);/*  w ww  .  j a  va 2s . c o  m*/
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    parLabel = new Paragraph();
    parLabel.add(new Phrase(
            "SUB TOTAL:      "
                    + CommonUtil.formatNumValue(CommonUtil.roundOffToTwoDecimalPlaces(subTotalAmount)),
            content));
    parLabel.setAlignment(Element.ALIGN_RIGHT);
    cellLabel.addElement(parLabel);
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

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

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

private void grandTotal(PdfPTable table, double grandTotalAmount) {
    //        PdfPCell cellLabel = new PdfPCell();
    //        Paragraph parLabel = new Paragraph();      
    //        parLabel.add(new Phrase("", content));
    //        parLabel.setAlignment(Element.ALIGN_LEFT);   
    //        cellLabel.addElement(parLabel);     
    //        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    //        cellLabel.setBorder(Rectangle.BOTTOM);
    //        cellLabel.setPaddingBottom(10);
    //        table.addCell(cellLabel);

    PdfPCell cellLabel = new PdfPCell();
    Paragraph parLabel = new Paragraph();
    parLabel.add(new Phrase(
            "GRAND TOTAL:      "
                    + CommonUtil.formatNumValue(CommonUtil.roundOffToTwoDecimalPlaces(grandTotalAmount)),
            content));//from  w  ww . ja  va 2 s.c  o  m
    parLabel.setAlignment(Element.ALIGN_RIGHT);
    cellLabel.addElement(parLabel);
    cellLabel.setColspan(2);
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

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

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  ww  .jav  a2  s.c o  m*/
    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.hris.payroll.reports.AdvancesSummaryReportPdf.java

private void subTotal(PdfPTable table, double subTotalAmount) {
    PdfPCell cellLabel = new PdfPCell();
    Paragraph parLabel = new Paragraph();
    parLabel.add(new Phrase("", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);/*from www . j  a va2s.  co  m*/
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    parLabel = new Paragraph();
    parLabel.add(new Phrase(
            "SUB TOTAL:      "
                    + CommonUtil.formatNumValue(CommonUtil.roundOffToTwoDecimalPlaces(subTotalAmount)),
            content));
    parLabel.setAlignment(Element.ALIGN_RIGHT);
    cellLabel.addElement(parLabel);
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

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

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

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

private void grandTotal(PdfPTable table, double grandTotalAmount) {
    //        PdfPCell cellLabel = new PdfPCell();
    //        Paragraph parLabel = new Paragraph();      
    //        parLabel.add(new Phrase("", content));
    //        parLabel.setAlignment(Element.ALIGN_LEFT);   
    //        cellLabel.addElement(parLabel);     
    //        cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    //        cellLabel.setBorder(Rectangle.BOTTOM);
    //        cellLabel.setPaddingBottom(10);
    //        table.addCell(cellLabel);

    PdfPCell cellLabel = new PdfPCell();
    Paragraph parLabel = new Paragraph();
    parLabel.add(new Phrase(
            "GRAND TOTAL:      "
                    + CommonUtil.formatNumValue(CommonUtil.roundOffToTwoDecimalPlaces(grandTotalAmount)),
            content));/*from   w  w w  . j  a v a 2  s. co  m*/
    parLabel.setAlignment(Element.ALIGN_RIGHT);
    cellLabel.addElement(parLabel);
    cellLabel.setColspan(2);
    cellLabel.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellLabel.setBorder(Rectangle.BOTTOM);
    cellLabel.setPaddingBottom(10);
    table.addCell(cellLabel);

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

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