Example usage for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment

List of usage examples for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment.

Prototype

public void setHorizontalAlignment(final int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment of the table relative to the page.

Usage

From source file:com.automaster.autoview.server.servlet.PdfServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {/*w  ww.j a v a  2s. c o  m*/
        this.dataAtual = new Date(System.currentTimeMillis());
        this.cnpjUn = null;

        String tempoDecorrido = " 0";
        int codVeiculo = Integer.parseInt(request.getParameter("cod"));
        String placa = request.getParameter("placa");
        Timestamp dataInicio = new Timestamp(Long.parseLong(request.getParameter("dataInicio")));
        Timestamp dataFim = new Timestamp(Long.parseLong(request.getParameter("dataFim")));

        TimeZone timeZonePadrao = TimeZone.getTimeZone(ZoneId.of("-3"));
        //System.out.println("Time zone : " + timeZonePadrao);

        ZzzPosPlacaVeiculoDAO zzzPosPlacaVeiculoDAO = new ZzzPosPlacaVeiculoDAO();
        VeiculoDAO veiculoDAO = new VeiculoDAO();
        TreeMap<String, String> veiculo = veiculoDAO.buscarVeiculoPorCodigo(codVeiculo);
        placa = veiculo.get("placa");
        //System.out.println("PLACA: "+veiculo.get("placa"));
        ArrayList<TreeMap<String, String>> posicoes = zzzPosPlacaVeiculoDAO
                .buscarPosicoesPorIntervaloData(placa, dataInicio, dataFim);
        int codCliente = Integer.parseInt(veiculo.get("clienteCodCliente"));
        //System.out.println("COD CLIENTE: "+codCliente);
        ClienteDAO clienteDAO = null;
        clienteDAO = new ClienteDAO();
        TreeMap<String, String> infoClienteUnidade = clienteDAO.buscarPorCodClienteSimplificado(codCliente);
        // Get the text that will be added to the PDF
        // step 1
        Document document = new Document();
        document.addHeader("Adriano", "AutoMaster");
        document.addCreator("Adriano Vale");
        document.addAuthor("Adriano Vale");
        document.addCreationDate();
        document.setPageSize(PageSize.A4.rotate());
        // step 2
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);
        // step 3
        document.open();
        // step 4
        //getServletContext().getRealPath("/")
        String url = getServletContext().getRealPath("/");
        //"D:\\Users\\Adriano\\Documents\\NetBeansProjects\\JRGWT\\web\\imagens\\logo.jpg"
        Image logo = Image.getInstance(url + "/imagens/logo.jpg");
        logo.setAlignment(Element.ALIGN_CENTER);

        Paragraph titulo = new Paragraph("Relatrio de Posies",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 20, Font.BOLD));
        titulo.setAlignment(Element.ALIGN_CENTER);

        Paragraph tituloPlaca = new Paragraph("Veculo: " + placa,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        tituloPlaca.setAlignment(Element.ALIGN_CENTER);

        SimpleDateFormat dataFormatadaCabecalho = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        dataFormatadaCabecalho.setTimeZone(timeZonePadrao);

        Date dataHoraInicio0 = new Date(Long.parseLong(request.getParameter("dataInicio")));
        Date dataHoraFim0 = new Date(Long.parseLong(request.getParameter("dataFim")));
        Paragraph periodo = new Paragraph(
                "Perodo: De: " + dataFormatadaCabecalho.format(dataHoraInicio0) + " at: "
                        + dataFormatadaCabecalho.format(dataHoraFim0),
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        periodo.setSpacingAfter(10.0f);
        periodo.setAlignment(Element.ALIGN_CENTER);
        //PdfPTable tabela = new PdfPTable(new float[]{0.11f, 0.095f, 0.06f, 0.065f, 0.085f, 0.06f, 0.04f, 0.065f, 0.055f, 0.06f, 0.24f, 0.065f});
        PdfPTable tabela = new PdfPTable(new float[] { 0.07f, 0.045f, 0.045f, 0.27f });
        tabela.setWidthPercentage(98.0f);
        tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
        PdfPCell tituloData = new PdfPCell(Phrase.getInstance("Data e Hora"));
        tituloData.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloData);
        //tabela.addCell("Data e hora");
        PdfPCell tituloVel = new PdfPCell(Phrase.getInstance("Velocidade"));
        tituloVel.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloVel);
        PdfPCell tituloIgn = new PdfPCell(Phrase.getInstance("Ignio"));
        tituloIgn.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloIgn);
        //tabela.addCell("Latitude");
        //tabela.addCell("Longitude");
        //tabela.addCell("Satlite");
        //tabela.addCell("GPS");
        //tabela.addCell("Entrada");
        //tabela.addCell("Sada");
        //tabela.addCell("Evento");
        PdfPCell tituloEnd = new PdfPCell(Phrase.getInstance("Endereo"));
        tituloEnd.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloEnd);
        //tabela.addCell("Direo");
        double latAnt = 0;
        double lonAnt = 0;
        double latAtual = 0;
        double lonAtual = 0;
        double distanciaTotal = 0;
        double distancia = 0;
        event.setHeader("AutoMaster");

        for (int i = 0; i < posicoes.size(); i++) {
            //for (int col = 0; col < posicoes.get(i).size(); col++) {
            if (i == 0) {
                distancia = 0;
                //System.out.println("linha 00 - PDF");
            } else {
                //System.out.println("linha 01 - PDF");
                latAnt = Double.parseDouble(posicoes.get(i - 1).get("lat"));
                lonAnt = Double.parseDouble(posicoes.get(i - 1).get("lon"));
                latAtual = Double.parseDouble(posicoes.get(i).get("lat"));
                lonAtual = Double.parseDouble(posicoes.get(i).get("lon"));
                //System.out.println("linha 02 - PDF");
                if (latAnt == latAtual && lonAnt == lonAtual) {
                    distancia = 0;
                } else {
                    distancia = caculaDistanciaEntreDoisPontos(latAnt, lonAnt, latAtual, lonAtual);
                    //System.out.println("linha 03 - PDF");
                }

            }
            distanciaTotal = distanciaTotal + distancia;
            //System.out.println("linha 04 - PDF");
            //TimeZone.setDefault(timeZoneMundial);
            Date dataHora0 = new Date(Long.parseLong(posicoes.get(i).get("dataHora")));
            //System.out.println("dataHora0 : "+dataHora0.toString());
            //TimeZone.setDefault(timeZoneCliente);
            //Date dataHora = new Date(dataHora0.getTime());
            SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            dataFormatada.setTimeZone(timeZonePadrao);
            //System.out.println("dataFormatada : "+dataFormatada);
            PdfPCell celData = new PdfPCell(Phrase.getInstance(dataFormatada.format(dataHora0)));
            celData.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celData);
            //tabela.addCell(dataFormatada);
            PdfPCell celVel = new PdfPCell(Phrase.getInstance(posicoes.get(i).get("vel")));
            celVel.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celVel);
            PdfPCell celIgn = new PdfPCell(Phrase
                    .getInstance(posicoes.get(i).get("ign").equalsIgnoreCase("True") ? "Ligada" : "Desligada"));
            celIgn.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celIgn);
            //tabela.addCell(posicoes.get(i).get("lat"));
            //tabela.addCell(posicoes.get(i).get("lon"));
            //tabela.addCell(posicoes.get(i).get("sat"));
            //tabela.addCell(posicoes.get(i).get("gps"));
            //tabela.addCell(posicoes.get(i).get("entrada"));
            //tabela.addCell(posicoes.get(i).get("saida"));
            //tabela.addCell(posicoes.get(i).get("evento"));
            PdfPCell celEnd = new PdfPCell(
                    Phrase.getInstance(posicoes.get(i).get("endereco") == null ? "Sem endereo"
                            : posicoes.get(i).get("endereco")));
            celEnd.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celEnd);
            //tabela.addCell(posicoes.get(i).get("direcao"));
            //}
        }
        //System.out.println("linha 05 - PDF");
        tempoDecorrido = calculaDatas(Long.parseLong(posicoes.get(0).get("dataHora")),
                Long.parseLong(posicoes.get(posicoes.size() - 1).get("dataHora")));
        //System.out.println("linha 06 - PDF");
        int index = 0;
        String kms = "0";
        String m = "";
        double metros = 0;
        //System.out.println("linha 07 - PDF");
        if (distanciaTotal > 0) {
            //System.out.println("linha 08 - PDF");
            BigDecimal decimalFormatado = new BigDecimal(distanciaTotal).setScale(2, RoundingMode.HALF_EVEN);
            //System.out.println("linha 09 - PDF");
            index = String.valueOf(decimalFormatado).indexOf(".");
            kms = String.valueOf(decimalFormatado).substring(0, index);
            m = "0" + (String.valueOf(decimalFormatado).substring(index));
            metros = Double.parseDouble(m) * 1000;
            //System.out.println("linha 10 - PDF");
        }
        /*document.add(new Paragraph(String.format(
         "You have submitted the following text using the %s method:",
         request.getMethod())));
         document.add(new Paragraph(text));*/
        //System.out.println("linha 11 - PDF");
        Paragraph kilometragem = new Paragraph(
                "Percorridos: " + kms + " KM e " + String.valueOf(metros) + " metros. Tempo: " + tempoDecorrido,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        //System.out.println("linha 12 - PDF");
        periodo.setSpacingAfter(10.0f);
        periodo.setAlignment(Element.ALIGN_CENTER);
        // step 5
        document.add(logo);
        document.add(titulo);
        document.add(tituloPlaca);
        document.add(periodo);
        document.add(tabela);
        document.add(kilometragem);
        String dia = new SimpleDateFormat("dd").format(dataAtual);
        String ano = new SimpleDateFormat("yyyy").format(dataAtual);
        int mes = dataAtual.getMonth();
        String mesEscrito = null;
        switch (mes) {
        case 0:
            mesEscrito = "janeiro";
            break;
        case 1:
            mesEscrito = "fevereiro";
            break;
        case 2:
            mesEscrito = "maro";
            break;
        case 3:
            mesEscrito = "abril";
            break;
        case 4:
            mesEscrito = "maio";
            break;
        case 5:
            mesEscrito = "junho";
            break;
        case 6:
            mesEscrito = "julho";
            break;
        case 7:
            mesEscrito = "agosto";
            break;
        case 8:
            mesEscrito = "setembro";
            break;
        case 9:
            mesEscrito = "outubro";
            break;
        case 10:
            mesEscrito = "novembro";
            break;
        case 11:
            mesEscrito = "dezembro";
            break;
        }
        String textRodape = infoClienteUnidade.get("cidadeUnidade") + " , "
                + infoClienteUnidade.get("estadoUnidade") + "    " + dia + "  de  " + mesEscrito + "  de  "
                + ano + ".";
        Paragraph localData = new Paragraph(textRodape,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.PLAIN));
        localData.setAlignment(Element.ALIGN_RIGHT);
        localData.setSpacingBefore(30.0f);
        localData.setSpacingAfter(10.0f);
        document.add(localData);
        Image assinatura = Image.getInstance(url + "/imagens/assinatura.png");
        assinatura.setAlignment(Element.ALIGN_CENTER);
        assinatura.scaleAbsolute(185, 91);
        document.add(assinatura);
        Paragraph infoEmpresa1 = new Paragraph("AUTO MASTER LTDA",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa1.setAlignment(Element.ALIGN_CENTER);
        infoEmpresa1.setSpacingAfter(1f);
        document.add(infoEmpresa1);
        Paragraph infoEmpresa2 = new Paragraph("___________________________",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa2.setAlignment(Element.ALIGN_CENTER);
        document.add(infoEmpresa2);
        String cnpjEmpresa = formataCNPJ(infoClienteUnidade.get("cnpjUnidade"));
        Paragraph infoEmpresa3 = new Paragraph(cnpjEmpresa,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa3.setAlignment(Element.ALIGN_CENTER);
        document.add(infoEmpresa3);
        document.close();
        // setting some response headers
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // setting the content type
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "attachment; filename=Historico-" + placa + ".pdf");
        // the contentlength
        response.setContentLength(baos.size());
        // write ByteArrayOutputStream to the ServletOutputStream
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
    //        response.setContentType("text/html;charset=UTF-8");
    //        try (PrintWriter out = response.getWriter()) {
    //            /* TODO output your page here. You may use following sample code. */
    //            out.println("<!DOCTYPE html>");
    //            out.println("<html>");
    //            out.println("<head>");
    //            out.println("<title>Servlet PdfServlet</title>");            
    //            out.println("</head>");
    //            out.println("<body>");
    //            out.println("<h1>Servlet PdfServlet at " + request.getContextPath() + "</h1>");
    //            out.println("</body>");
    //            out.println("</html>");
    //        }
}

From source file:com.bougsid.printers.PrintMission.java

public void printMission(Mission mission) {
    Document document = new Document(PageSize.A4);
    try {/*from   www .ja  v a 2 s.  c  om*/
        File downloadDir = new File(msg.getMessage("application.mission.downloaddir"));
        if (!downloadDir.exists()) {
            downloadDir.mkdir();
        }
        System.out.println("Dir =" + downloadDir.getPath());
        PdfWriter.getInstance(document,
                new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf"));
        document.open();
        Paragraph p = new Paragraph();
        p.setSpacingAfter(60);
        document.add(p);
        //header
        Paragraph paragraph = new Paragraph(
                msg.getMessage("mission.pdf.school") + "       " + mission.getIdMission() + "           ",
                DEFAULT_FONT);
        Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " "
                + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
        paragraph.add(phrase);
        paragraph.setSpacingAfter(50);
        document.add(paragraph);
        //title
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(40);
        PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"),
                FontFactory.getFont(FontFactory.HELVETICA, 18)));
        cell.setBorderWidth(1);
        cell.setPadding(10);

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        table.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(40);
        document.add(table);

        //content
        table = new PdfPTable(2);
        table.setWidthPercentage(100);

        //line 1
        cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 2
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 3
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        if (mission.getEntreprise() != null) {
            //line 4
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);

            //line 5
            cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setPaddingTop(20);
            table.addCell(cell);
        }

        //line 6
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        p = new Paragraph();
        p.setFont(DEFAULT_FONT);
        for (Ville ville : mission.getVilles()) {
            p.add(ville.getNom() + "\n");
        }
        cell = new PdfPCell(p);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 7
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 8
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(
                ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "    Heure : "
                        + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")),
                DEFAULT_FONT));

        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        //line 9
        cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);
        switch (mission.getTransportType()) {
        case PERSONNEL:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Accompagnement:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " "
                    + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName()
                    + " " + msg.getMessage("mission.pdf.accomp.voitue") + " "
                    + mission.getAccompEmploye().getVehicule().getMarque() + " "
                    + msg.getMessage("mission.pdf.mat") + " "
                    + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        case Service:
            cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " "
                    + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat")
                    + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT));
            break;
        default: {
            cell = new PdfPCell(new Paragraph(
                    ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"),
                    DEFAULT_FONT));
        }
        }
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(20);
        table.addCell(cell);

        table.setSpacingAfter(40);
        document.add(table);

        //note
        document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT));

        //signature
        if (mission.getEmploye().getGrade().getType() == GradeType.DG) {

        } else {
            Employe dir = employeService.getDG();
            if (dir != null)
                paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setSpacingBefore(40);
            document.add(paragraph);
            paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT);
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            document.add(paragraph);
        }

    } catch (DocumentException ex) {
        ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    }
    document.close();
    //        try {
    //            Desktop.getDesktop().open(new File("./order.pdf"));
    //        } catch (IOException ex) {
    //            JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier");
    //        }
}

From source file:com.carfinance.module.common.controller.DocumentDownloadController.java

/**
 * ??/*ww  w.  j a  va  2  s. c om*/
 * @param model
 * @param request
 * @param response
 */
@RequestMapping(value = "/pdfhunchecontrace", method = RequestMethod.GET)
public void pdfHuncheContrace(Model model, HttpServletRequest request, HttpServletResponse response) {
    String contrace_id_str = request.getParameter("contrace_id");

    String org_id = "";
    String contrace_no = "";
    String customer_name = "";
    String vehicle_id = "";
    String daily_available_km = "";

    VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService
            .getVehicleContraceInfoById(Long.valueOf(contrace_id_str));
    if (vehicleContraceInfo != null) {
        org_id = String.valueOf(vehicleContraceInfo.getOrg_id());
        contrace_no = vehicleContraceInfo.getContrace_no();
        customer_name = vehicleContraceInfo.getCustomer_name();
        daily_available_km = vehicleContraceInfo.getDaily_available_km() + "";
    } else {
        PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService
                .getPropertyContraceInfoById(Long.valueOf(contrace_id_str));
        if (propertyContraceInfo != null) {
            org_id = String.valueOf(propertyContraceInfo.getOrg_id());
            contrace_no = propertyContraceInfo.getContrace_no();
            customer_name = propertyContraceInfo.getCustomer_name();
        }
    }

    List<VehicleContraceVehsInfo> vehicleContraceVehsInfoList = this.vehicleServiceManageService
            .getVehicleContraceVehsListByContraceId(Long.valueOf(contrace_id_str));

    //1.ContentType
    response.setContentType("multipart/form-data");
    //2.????(??a.pdf)
    response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + ".pdf");

    Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
    // ?? pdf ?
    try {
        BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);

        Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK);
        Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK);
        Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK);

        FileOutputStream pdfFile = new FileOutputStream(
                new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf"));
        // pdf ?
        Paragraph paragraph1 = new Paragraph("???", bold_fontChinese);
        paragraph1.setAlignment(Element.ALIGN_CENTER);

        Paragraph paragraph2 = new Paragraph(
                "???", normal_fontChinese);
        Paragraph paragraph3 = new Paragraph("" + customer_name + " (",
                normal_fontChinese);
        Paragraph paragraph4 = new Paragraph(
                "?????________________???",
                normal_fontChinese);
        Paragraph paragraph5 = new Paragraph("??????",
                normal_fontChinese);
        // table
        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100);
        table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        // 
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?/", normal_fontChinese));
        table.addCell(cell);
        cell.setPhrase(new Paragraph("?", normal_fontChinese));
        table.addCell(cell);
        // ?
        for (VehicleContraceVehsInfo v : vehicleContraceVehsInfoList) {

            PdfPCell newcell = new PdfPCell();
            newcell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            newcell.setPhrase(new Paragraph("1", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getModel(), normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(v.getDaily_price() + "", normal_fontChinese));
            table.addCell(newcell);
            newcell.setPhrase(new Paragraph(daily_available_km, normal_fontChinese));
            table.addCell(newcell);
        }

        Paragraph paragraph6 = new Paragraph(
                "??_________________________________________________________________",
                normal_fontChinese);
        Paragraph paragraph7 = new Paragraph(
                "____________________________?______",
                normal_fontChinese);
        Paragraph paragraph8 = new Paragraph("????", normal_fontChinese);
        Paragraph paragraph9 = new Paragraph(
                "???________________________???________________________",
                normal_fontChinese);
        Paragraph paragraph10 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph11 = new Paragraph(
                "???????????????",
                normal_fontChinese);
        Paragraph paragraph12 = new Paragraph("?", normal_fontChinese);
        Paragraph paragraph13 = new Paragraph(
                "??????????????",
                normal_fontChinese);
        Paragraph paragraph14 = new Paragraph(
                "?????????",
                normal_fontChinese);
        Paragraph paragraph15 = new Paragraph("?????",
                normal_fontChinese);
        Paragraph paragraph16 = new Paragraph(
                "(/)                                       (/)",
                normal_fontChinese);
        Paragraph paragraph17 = new Paragraph(
                "                                                      ??", normal_fontChinese);
        Paragraph paragraph18 = new Paragraph(
                "??                                               ??  ",
                normal_fontChinese);
        Paragraph paragraph19 = new Paragraph(
                "                                                      201          ",
                normal_fontChinese);

        //  Document ?File  PdfWriter ?
        PdfWriter.getInstance(pdfDoc, pdfFile);
        pdfDoc.open(); //  Document 

        // ??
        pdfDoc.add(paragraph1);
        pdfDoc.add(new Chunk("\n\n"));
        pdfDoc.add(paragraph2);
        pdfDoc.add(paragraph3);
        pdfDoc.add(paragraph4);
        pdfDoc.add(paragraph5);
        pdfDoc.add(table);
        pdfDoc.add(paragraph6);
        pdfDoc.add(paragraph7);
        pdfDoc.add(paragraph8);
        pdfDoc.add(paragraph9);
        pdfDoc.add(paragraph10);
        pdfDoc.add(paragraph11);
        pdfDoc.add(paragraph12);
        pdfDoc.add(paragraph13);
        pdfDoc.add(paragraph14);
        pdfDoc.add(paragraph15);
        pdfDoc.add(paragraph16);
        pdfDoc.add(paragraph17);
        pdfDoc.add(paragraph18);
        pdfDoc.add(paragraph19);

        pdfDoc.close();

        ServletOutputStream out;
        //File(?download.pdf)
        File file = new File(appProps.get("hunche.contrace.download.path") + contrace_no + ".pdf");

        try {
            FileInputStream inputStream = new FileInputStream(file);
            //3.response?ServletOutputStream(out)
            out = response.getOutputStream();
            int b = 0;
            byte[] buffer = new byte[512];
            while (b != -1) {
                b = inputStream.read(buffer);
                //4.?(out)
                out.write(buffer, 0, b);
            }
            inputStream.close();
            out.close();
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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 ww w .j  a  va2  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;//w  ww  .  j a  va 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 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.PayslipReportPDF.java

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

    Document document = null;/*from   ww  w  .ja v  a2 s . co m*/
    Rectangle pageSize = new Rectangle(318, 825);
    try {
        //            document = new Document(PageSize.A4, 50, 50, 48, 40);
        document = new Document(pageSize, 37, 37, 37, 37);
        PdfWriter writer = PdfWriter.getInstance(document, outputStream);
        document.open();

        PdfPTable mainTable = new PdfPTable(1);
        //            mainTable.setTotalWidth(new float[]{ 120, 120 });
        mainTable.setWidthPercentage(100);
        mainTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
        //            mainTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //            mainTable.setLockedWidth(true);

        //            leftColumnTable(mainTable);
        //            rightColumnTable(mainTable);

        //            for(Employee e : es.findEmployeeByBranch(getBranchId())){
        for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) {
            document.add(leftColumnTable(pr, getPayrollDate()));
            document.newPage();
        }

    } catch (DocumentException ex) {
        Logger.getLogger(PayslipReportPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}

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

private PdfPTable leftColumnTable(PayrollRegister pr, Date payrollDate) throws DocumentException {
    PdfPTable table = new PdfPTable(3);
    table.setTotalWidth(new float[] { 120, 20, 103 });
    table.setWidthPercentage(100);// w  w  w . ja  v  a  2  s .c  o  m
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setLockedWidth(true);

    PdfPCell cellTitle = new PdfPCell();
    cellTitle.setColspan(3);
    Paragraph parTitle = new Paragraph();
    parTitle.add(new Phrase("Payslip: ", header));
    parTitle.setAlignment(Element.ALIGN_CENTER);
    cellTitle.addElement(parTitle);
    cellTitle.setBorder(cellBorder);
    table.addCell(cellTitle);

    PdfPCell cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(3);
    Paragraph parLabel = new Paragraph();
    parLabel.add(
            new Phrase("Payroll Date: " + CommonUtil.convertDateFormat(getPayrollDate().toString()), content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    //        PdfPCell cellValue = new PdfPCell();
    //        cellValue.setUseAscender(true);
    //        Paragraph parValue = new Paragraph();
    //        parValue.add(new Phrase(CommonUtil.convertDateFormat(getPayrollDate().toString()), content));
    //        parValue.setAlignment(Element.ALIGN_RIGHT);
    //        cellValue.addElement(parValue);     
    //        cellValue.setBorder(cellBorder);
    //        table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(3);
    parLabel = new Paragraph();
    parLabel.add(
            new Phrase(
                    "Cut-off Date: " + CommonUtil.changeDateFormat(pr.getAttendancePeriodFrom().toString())
                            + " - " + CommonUtil.changeDateFormat(pr.getAttendancePeriodTo().toString()),
                    content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    //        PdfPCell cellValue = new PdfPCell();
    //        cellValue.setUseAscender(true);
    //        Paragraph parValue = new Paragraph();
    //        parValue.add(new Phrase(CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString())+" - "+CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString()), content));
    //        parValue.setAlignment(Element.ALIGN_RIGHT);
    //        cellValue.addElement(parValue);     
    //        cellValue.setBorder(cellBorder);
    //        table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(3);
    parLabel = new Paragraph();
    String middlename;
    if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) {
        middlename = " ";
    } else {
        middlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". ";
    }
    String name = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " " + middlename;
    parLabel.add(new Phrase("Employee Name: " + name, content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    //        cellValue = new PdfPCell();
    ////        cellValue.setUseAscender(true);
    //        parValue = new Paragraph();
    //        parValue.add(new Phrase(pr.getLastname().toUpperCase()+", "+pr.getFirstname().toUpperCase()+" "+pr.getMiddlename().toUpperCase().charAt(0)+".", employeeName));
    ////        parValue.add(new Phrase("NAME", content));
    //        parValue.setAlignment(Element.ALIGN_RIGHT);
    //        cellValue.addElement(parValue);     
    //        cellValue.setBorder(cellBorder);
    //        table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(3);
    parLabel = new Paragraph();
    String position = (ephs.findByEmployee(pr.getEmployeeId()).getPosition() == null) ? "N/A"
            : ephs.findByEmployee(pr.getEmployeeId()).getPosition().toUpperCase();
    parLabel.add(new Phrase("POSITION: " + position, smallerFont));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    //        cellValue = new PdfPCell();
    //        cellValue.setUseAscender(true);
    //        parValue = new Paragraph();
    //        parValue.add(new Phrase(CommonUtil.convertDateFormat(new Date().toString()), content));
    //        parValue.setAlignment(Element.ALIGN_RIGHT);
    //        cellValue.addElement(parValue);     
    //        cellValue.setBorder(cellBorder);
    //        table.addCell(cellValue);

    cellLabel = new PdfPCell();
    //        cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("Monthly/Daily Rate: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    PdfPCell cellValue = new PdfPCell();
    //        cellValue.setUseAscender(true);
    Paragraph parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getRate()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("Half-month Rate: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getHalfMonthSalary()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Overtime: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(
            new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getOvertimePay())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Holiday Premium: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double premium = (pr.getLegalHolidayPay() + pr.getSpecialHolidayPay())
            - (pr.getTotalLatesHolidayDeduction() + pr.getTotalUndertimeHolidayDeduction());
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(premium)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Working Day-off: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getWorkingDayOffPay())),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Night Differential: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getNightDifferential())),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Absences/Lates/Undertime: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double alu = pr.getAbsences() + pr.getTotalLatesDeduction() + pr.getTotalUndertimeDeduction();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(alu)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("GROSS PAY: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getGrossPay())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Allowances: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(" ", content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("COLA: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getColaAllowance()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Meal Allowance: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getMealAllowance()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("AFL: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getAllowanceForLiquidation()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Transportation Allowance: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    cellLabel.setColspan(2);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getTransportationAllowance()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Housing Allowance: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getOtherAllowance()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Communications Allowance: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(pr.getCommunicationAllowance()), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("TOTAL PAY: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double totalPay = pr.getGrossPay() + pr.getCommunicationAllowance() + pr.getTransportationAllowance()
            + pr.getColaAllowance() + pr.getPerDiemAllowance() + pr.getMealAllowance() + pr.getOtherAllowance()
            + pr.getAllowanceForLiquidation();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalPay)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("DEDUCTIONS: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(" ", content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("SSS Contribution: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getSss())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("PHIC Contribution: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getPhic())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("HDMF Contribution: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getHdmf())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Withholoding Taxes: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getTax())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("SSS Loan: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "sss loan"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("HDMF Loan: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "hdmf loan"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Additional HDMF Contribution: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(
            new Phrase(
                    String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(
                            as.findAdvancesTotalAmount(pr.getPayrollId(), "additional HDMF contribution"))),
                    content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("PAG-IBIG 2: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "pag-ibig ii"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Advances to O/E: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(" ", content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Cash Bond: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash bond"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Cash Advance: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash advance"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Lending: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "lending"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Jewelry: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "jewelry"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Staffhouse: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(
            String.valueOf(CommonUtil
                    .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "staffhouse"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Hotel and Restaurant Charges: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(
            new Phrase(
                    String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(
                            as.findAdvancesTotalAmount(pr.getPayrollId(), "hotel and restaurant charges"))),
                    content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Cash Shortages: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil
            .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash shortages"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Employee Charges: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil
            .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "employee charges"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("ATM Initial Deposit: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil
            .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "atm initial deposit"))),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(allowances);
    parLabel.add(new Phrase("Others__________________: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double otherCharges = as.findAdvancesTotalAmount(pr.getPayrollId(), "advances to o/e")
            + as.findAdvancesTotalAmount(pr.getPayrollId(), "other charges");
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(otherCharges)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("TOTAL DEDUCTIONS:", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double totalDeductions = as.findAdvancesTotalAmount(pr.getPayrollId()) + pr.getTax() + pr.getPhic()
            + pr.getHdmf() + pr.getSss();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalDeductions)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    table.addCell(cellValue);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    cellLabel.setColspan(2);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("NET PAY:", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    double netPay = CommonUtil.roundOffToTwoDecimalPlaces(totalPay - totalDeductions);
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay)), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    /***************************************************************************/
    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("Adjustments:", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(
            new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getAdjustments())), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    /***************************************************************************/
    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    //        parLabel.add(new Phrase("_____________________________", content));
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    //        parValue.add(new Phrase(String.valueOf(totalPay - totalDeductions), content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    /***************************************************************************/
    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("TOTAL AMOUNT TO BE RECEIVED:", smallFont));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay + pr.getAdjustments())),
            content));
    parValue.setAlignment(Element.ALIGN_RIGHT);
    cellValue.addElement(parValue);
    cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    table.addCell(cellValue);

    /***************************************************************************/
    cellLabel = new PdfPCell();
    //        cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase("Prepared By: ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    //        cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    //        cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase("Conforme: ", content));
    parValue.setAlignment(Element.ALIGN_LEFT);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    /***************************************************************************/
    int userId = ubas.findUserByBranch(getBranchId());
    String employeeId = us.findEmployeeIdByUserId(userId);
    Employee e = es.findEmployeeById(employeeId);

    String payrollClerkMiddlename;
    if (e.getMiddlename() == null || e.getMiddlename().isEmpty()) {
        payrollClerkMiddlename = " ";
    } else {
        payrollClerkMiddlename = String.valueOf(e.getMiddlename().toUpperCase().charAt(0)) + ". ";
    }
    String payrollClerk = e.getFirstname().toUpperCase() + " " + payrollClerkMiddlename
            + e.getLastname().toUpperCase();

    String employeeMiddlename;
    if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) {
        employeeMiddlename = " ";
    } else {
        employeeMiddlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". ";
    }
    String employee = pr.getFirstname().toUpperCase() + " " + employeeMiddlename
            + pr.getLastname().toUpperCase();

    cellLabel = new PdfPCell();
    cellLabel.setPaddingTop(30);
    parLabel = new Paragraph();
    parLabel.add(new Phrase(payrollClerk, smallerFont));
    parLabel.setAlignment(Element.ALIGN_CENTER);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(Rectangle.BOTTOM);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    cellLabel.setPaddingTop(30);
    parLabel = new Paragraph();
    parLabel.add(new Phrase(" ", content));
    parLabel.setAlignment(Element.ALIGN_CENTER);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setPaddingTop(30);
    parValue = new Paragraph();
    parValue.add(new Phrase(employee, smallerFont));
    parValue.setAlignment(Element.ALIGN_CENTER);
    cellValue.addElement(parValue);
    cellValue.setBorder(Rectangle.BOTTOM);
    table.addCell(cellValue);

    /***************************************************************************/
    cellLabel = new PdfPCell();
    cellLabel.setUseAscender(true);
    parLabel = new Paragraph();
    //        parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("Payroll Clerk", content));
    parLabel.setAlignment(Element.ALIGN_CENTER);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellLabel = new PdfPCell();
    parLabel = new Paragraph();
    //        parLabel.setIndentationLeft(halfMonthRate);
    parLabel.add(new Phrase("", content));
    parLabel.setAlignment(Element.ALIGN_LEFT);
    cellLabel.addElement(parLabel);
    cellLabel.setBorder(cellBorder);
    table.addCell(cellLabel);

    cellValue = new PdfPCell();
    cellValue.setUseAscender(true);
    parValue = new Paragraph();
    parValue.add(new Phrase("Employee", content));
    parValue.setAlignment(Element.ALIGN_CENTER);
    cellValue.addElement(parValue);
    cellValue.setBorder(cellBorder);
    table.addCell(cellValue);

    return table;
}

From source file:com.iucosoft.eavertizare.util.Export.java

public static void toPdf(JFrame frame, JTable jTableClients, String firma) {

    Document document = new Document(PageSize.A4.rotate());
    try {//from   w w w .  j  av a  2s. c  o m
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setDialogTitle("Specify a file to save");

        int userSelection = fileChooser.showSaveDialog(frame);

        if (userSelection == JFileChooser.APPROVE_OPTION) {

            File fileToSave = fileChooser.getSelectedFile();
            System.out.println("Save as file: " + fileToSave.getAbsolutePath());
            PdfWriter.getInstance(document, new FileOutputStream(fileToSave.getAbsolutePath() + ".pdf"));

        }

        document.open();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();

        if (firma.equals("All firms")) {

            addTitle(document, "Raport pentru toate firmele cu toti clienti \n din " + dateFormat.format(date));
        } else {

            addTitle(document, "Raport pentru " + firma + " \n din " + dateFormat.format(date));
        }

        addEmptyLine(document, new Paragraph(), 2);

        PdfPTable table = new PdfPTable(jTableClients.getColumnCount());
        table.setTotalWidth(jTableClients.getColumnCount() + 780);
        table.setLockedWidth(true);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);

        for (int i = 0; i < table.getNumberOfColumns(); i++) {

            if (jTableClients.getColumnName(i).equals("")) {
                table.addCell("Trimis");
            } else {
                table.addCell(jTableClients.getColumnName(i));
            }
        }
        Object value;
        for (int i = 0; i < jTableClients.getRowCount(); i++) {
            for (int j = 0; j < table.getNumberOfColumns(); j++) {
                value = jTableClients.getValueAt(i, j);
                table.addCell(value.toString());
            }
        }
        document.add(table);
        document.close();

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

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)//from   w w w.j  av  a  2s.c o m
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String mpsrID = request.getParameter("MPSR_ID");
    if (null == mpsrID)
        return;

    MPSRProjectInfo basicInfo = MPSRProjectInfo.getInstance(mpsrID);
    MPSRExecutiveSummary exeSummary = MPSRExecutiveSummary.getInstance(mpsrID);
    MPSRStatusSummary statusSummary = MPSRStatusSummary.getInstance(mpsrID);
    MPSRFunctionPerformance funcPerform = MPSRFunctionPerformance.getInstance(mpsrID);
    MPSRCostPerformance costPerform = MPSRCostPerformance.getInstance(mpsrID);
    MPSRSchedulePerformance[] schedulePerform = MPSRSchedulePerformance.getInstance(mpsrID);
    MPSRSafety safety = MPSRSafety.getInstance(mpsrID);
    MPSRAuthorization auth = MPSRAuthorization.getInstance(mpsrID);
    MPSRBudget budget = MPSRBudget.getInstance(mpsrID);
    MPSRCostReport[] costRpt = MPSRCostReport.getInstance(mpsrID);
    MPSRSchedule schedule = MPSRSchedule.getInstance(mpsrID);
    MPSRMilestone[] milestones = MPSRMilestone.getInstance(mpsrID);
    MPSRLPE lpe = MPSRLPE.getInstance(mpsrID);
    MPSRInsidePlantDesign[] ipds = MPSRInsidePlantDesign.getInstance(mpsrID);
    MPSROutsidePlantDesign[] opds = MPSROutsidePlantDesign.getInstance(mpsrID);
    MPSRProcure procure = MPSRProcure.getInstance(mpsrID);
    MPSRApprovedChanges[] approvedChanges = MPSRApprovedChanges.getInstance(mpsrID);
    MPSRPendingChanges[] pendingChanges = MPSRPendingChanges.getInstance(mpsrID);
    MPSRInsidePlantConstruction[] ipcs = MPSRInsidePlantConstruction.getInstance(mpsrID);
    MPSROutsidePlantConstruction[] opcs = MPSROutsidePlantConstruction.getInstance(mpsrID);
    MPSRAppendix[] appendixs = MPSRAppendix.getInstance(mpsrID);
    MPSRAttachment[] attachments = MPSRAttachment.getInstance(mpsrID);

    // response.setContentType("application/pdf");
    // response.setHeader("Content-Disposition",
    // "attachment; filename=\"test.pdf\"");

    Font fontNormal = null;
    Font fontCoverTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);
    Font fontCoverTableHeader = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
    Font fontCoverTableContent = new Font(FontFamily.HELVETICA, 16);
    Font fontChapterHeader = new Font(FontFamily.HELVETICA, 18, Font.BOLD);
    Font fontSection1Header = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
    Font fontSection2Header = new Font(FontFamily.HELVETICA, 14, Font.BOLD);
    Font fontWork = new Font(FontFamily.HELVETICA, 12, Font.UNDERLINE);

    Font fontTableCaption = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Font fontTableColumnHeader = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    Font fontTableColumnHeaderYellow = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    fontTableColumnHeaderYellow.setColor(BaseColor.YELLOW);
    Font fontTableRowTitle = new Font(FontFamily.HELVETICA, 12, Font.ITALIC);
    Font fontTableCellBold = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    Font fontTableNote = new Font(FontFamily.HELVETICA, 10, Font.ITALIC);
    Font fontImageCaption = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD);

    Font fontPOTableHeader = new Font(FontFamily.HELVETICA, 10, Font.BOLD);
    fontPOTableHeader.setColor(BaseColor.YELLOW);
    Font fontPOTable = new Font(FontFamily.HELVETICA, 9);
    Font fontPOTableSummary = new Font(FontFamily.HELVETICA, 9, Font.BOLD);

    Font fontPageHeader = new Font(FontFamily.HELVETICA, 8);
    Font fontPageFooter = new Font(FontFamily.HELVETICA, 10);

    Phrase[] headerTexts = new Phrase[] { new Phrase("ELECTRIC DELIVERY", fontPageHeader),
            new Phrase("DELIVERY PROJECTS & CONSTRUCTION (DP&C)", fontPageHeader),
            new Phrase("PROJECT MONTHLY REPORT", fontPageHeader) };

    Paragraph paragraph = null;
    PdfPTable table = null;
    PdfPCell cell = null;

    Document document = new Document(DEFAULT_PAGE_SIZE, 36, 36, 9 * 10, 36);
    ByteArrayOutputStream baosOrig = new ByteArrayOutputStream();
    XMLWorkerHelper xmlWorker = XMLWorkerHelper.getInstance();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, baosOrig);
        writer.setStrictImageSequence(true);
        writer.setLinearPageMode();
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines | PdfWriter.FitWindow);

        Image icon = getEmbeddedImage(getServletContext(), "/resource/image/company_logo.png");

        document.open();

        PdfOutline root = writer.getRootOutline();

        // *******************************************************************************************//

        // addOutline(root, writer, MPSRUI.TREE_0);

        for (int i = 0; i < 2; i++) {
            document.add(new Paragraph(" "));
        }

        String[] titles = { " DELIVERY PROJECTS & CONSTRUCTION", "MONTHLY REPORT",
                basicInfo.getReportMonthYear(), basicInfo.getProjectTitle(),
                "PROJECT No. " + basicInfo.getProjectDefinition() };
        int[] spaceingAfters = { 48, 48, 48, 24, 48 };
        for (int i = 0; i < titles.length; i++) {
            paragraph = new Paragraph();
            paragraph.setSpacingAfter(spaceingAfters[i]);
            paragraph.setFont(fontCoverTitle);
            paragraph.setAlignment(Element.ALIGN_CENTER);
            paragraph.add(new Chunk(titles[i]));
            document.add(paragraph);
        }

        addCoverImage(document, MPSRUI.getFilePath(mpsrID, basicInfo.getFileName()));

        document.add(new Paragraph(" "));

        table = new PdfPTable(2);
        table.addCell(new Phrase("Client", fontCoverTableHeader));
        table.addCell(new Phrase(basicInfo.getProjectManager(), fontCoverTableContent));
        table.addCell(new Phrase("Location", fontCoverTableHeader));
        table.addCell(new Phrase(basicInfo.getProjectDirector(), fontCoverTableContent));
        document.add(table);

        // *******************************************************************************************//

        document.resetPageCount();
        document.add(Chunk.NEXTPAGE);
        writer.setPageEvent(new MPSRPageEventHelper(icon, headerTexts, fontPageFooter));

        // *******************************************************************************************//

        PdfOutline outline1 = addOutline(root, writer, MPSRUI.TREE_1);
        addSectionTitle(document, MPSRUI.TREE_1, fontChapterHeader, 0, 0, 12);

        PdfOutline outline2 = addOutline(outline1, writer, "1.1");

        addOutline(outline2, writer, MPSRUI.TREE_1_1_1);
        addSectionTitle(document, MPSRUI.TREE_1_1_1, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_2);
        addSectionTitle(document, MPSRUI.TREE_1_1_2, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_2(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_3);
        addSectionTitle(document, MPSRUI.TREE_1_1_3, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_3(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_4);
        addSectionTitle(document, MPSRUI.TREE_1_1_4, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_4(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 1.2 Status Summary
        // *******************************************************************************************//

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_2);
        addSectionTitle(document, MPSRUI.TREE_1_2, fontSection1Header, 6, 12, 12);

        paragraph = new Paragraph();
        paragraph.add(basicInfo.getProjectTitle());
        paragraph.setSpacingAfter(4);
        document.add(paragraph);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1 });

        cell = new PdfPCell(
                new Phrase("Project #: " + basicInfo.getProjectDefinition(), fontTableColumnHeader));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        String[] headers = { "Status", "Approved (Include RnC)", "To Date", "At Completion" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        String[][] cellValues = {
                { "Budget ($M)", statusSummary.getBudgetStatus(),
                        !"".equals(statusSummary.getBudgetApproved()) ? CURRENCY_FORMATTER
                                .format(Double.parseDouble(statusSummary.getBudgetApproved())) : "",
                        !"".equals(statusSummary.getBudgetToDate())
                                ? CURRENCY_FORMATTER.format(Double.parseDouble(statusSummary.getBudgetToDate()))
                                : "",
                        !"".equals(statusSummary.getBudgetAtCompletion()) ? CURRENCY_FORMATTER
                                .format(Double.parseDouble(statusSummary.getBudgetAtCompletion())) : "" },
                { "Schedule - Duration (months)", statusSummary.getScheduleStatus(),
                        statusSummary.getScheduleApproved(), statusSummary.getScheduleToDate(),
                        statusSummary.getScheduleAtCompletion() },
                { "In-Service Date", statusSummary.getInServiceDateStatus(),
                        statusSummary.getInServiceDateApproved(), statusSummary.getInServiceDateToDate(),
                        statusSummary.getInServiceDateAtCompletion() } };
        for (int i = 0; i < cellValues.length; i++) {
            table.addCell(new Phrase(cellValues[i][0]));
            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setBackgroundColor(getBackgroundColor(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            for (int j = 2; j < 5; j++) {
                cell = new PdfPCell(new Phrase(cellValues[i][j]));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
            }
        }

        document.add(table);

        // -------------------------------------------------------------------//

        paragraph = new Paragraph("Legend:");
        paragraph.setSpacingAfter(4);
        paragraph.setIndentationLeft(25);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(240);
        table.setLockedWidth(true);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        String[] legends = { "On Target", "At Risk", "Off Target" };
        for (String legend : legends) {
            cell = new PdfPCell(new Phrase(legend));
            cell.setBackgroundColor(getBackgroundColor(legend));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setMinimumHeight(18);
            cell.setPadding(0);
            table.addCell(cell);
        }

        paragraph = new Paragraph();
        paragraph.add(table);
        paragraph.setIndentationLeft(25);
        document.add(paragraph);

        // *******************************************************************************************//
        // 1.2.1 Functional Area Performance Indicators
        // *******************************************************************************************//

        addOutline(outline2, writer, MPSRUI.TREE_1_2_1);
        addSectionTitle(document, MPSRUI.TREE_1_2_1, fontSection2Header, 12, 12, 12);

        table = new PdfPTable(4);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 4, 1, 1, 4 });

        headers = new String[] { "Activities", "Current Status", "Trend",
                "Comments (main performance drives)" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        Image imgArrowUp = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Up.png");
        Image imgArrowDown = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Down.png");
        Image imgArrowEven = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Even.png");
        Image[] images = { imgArrowUp, imgArrowDown, imgArrowEven };
        for (Image image : images) {
            image.scaleToFit(12, 12);
        }

        cellValues = new String[][] {
                { "Project - " + basicInfo.getProjectTitle(), funcPerform.getProjectStatus(),
                        funcPerform.getProjectTrend(), funcPerform.getProjectComment() },
                { "  Target Budget", funcPerform.getTargetBudgetStatus(), funcPerform.getTargetBudgetTrend(),
                        funcPerform.getTargetBudgetComment() },
                { "  Safety", funcPerform.getSafetyStatus(), funcPerform.getSafetyTrend(),
                        funcPerform.getSafetyComment() },
                { "  Licensing & Permitting", funcPerform.getLicensingStatus(), funcPerform.getLicensingTrend(),
                        funcPerform.getLicensingComment() },
                { "  Corporate Properties", funcPerform.getCorporateStatus(), funcPerform.getCorporateTrend(),
                        funcPerform.getCorporateComment() },
                { "  Inside Plant Design & Engineering", funcPerform.getIPDEStatus(),
                        funcPerform.getIPDETrend(), funcPerform.getIPDEComment() },
                { "  Public Outreach", funcPerform.getOutreachStatus(), funcPerform.getOutreachTrend(),
                        funcPerform.getOutreachComment() },
                { "  Procurement", funcPerform.getProcureStatus(), funcPerform.getProcureTrend(),
                        funcPerform.getProcureComment() },
                { "  Construction", funcPerform.getConstructionStatus(), funcPerform.getConstructionTrend(),
                        funcPerform.getConstructionComment() },
                { "  Environmental - Resource Recovery", funcPerform.getEnviromentStatus(),
                        funcPerform.getEnviromentTrend(), funcPerform.getEnviromentComment() },
                { "  Salvage", funcPerform.getSalvageStatus(), funcPerform.getSalvageTrend(),
                        funcPerform.getSalvageComment() },
                { "  Withdrawal", funcPerform.getWithdrawalStatus(), funcPerform.getWithdrawalTrend(),
                        funcPerform.getWithdrawalComment() } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setBackgroundColor(getBackgroundColor(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);

            if ("Up".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowUp);
            } else if ("Down".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowDown);
            } else if ("Even".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowEven);
            } else {
                cell = new PdfPCell();
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][3]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//

        document.setPageSize(DEFAULT_PAGE_SIZE.rotate());
        document.add(Chunk.NEXTPAGE);

        addOutline(outline2, writer, MPSRUI.TREE_1_2_2);
        addSectionTitle(document, MPSRUI.TREE_1_2_2, fontSection2Header, 12, 12, 12);
        addImage(document, MPSRUI.getFilePath(mpsrID, costPerform.getFileName()));

        // *******************************************************************************************//
        // 1.2.3 Schedule Performance
        // *******************************************************************************************//

        document.add(Chunk.NEXTPAGE);

        addOutline(outline2, writer, MPSRUI.TREE_1_2_3);
        addSectionTitle(document, MPSRUI.TREE_1_2_3, fontSection2Header, 12, 12, 12);

        table = new PdfPTable(9);
        table.setTotalWidth(750);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "WBS", "Original Duration", "Remaining Duration", "Baseline Start Date",
                "Baseline Finish Date", "Start Date", "Finish Date", "Total Float", "Status" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < schedulePerform.length; i++) {
            cell = new PdfPCell(new Phrase(schedulePerform[i].getWBS()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getOriginalDuration())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getRemainingDuration())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedStartDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getStartDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getTotalFloat()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getStatus()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        table.setHeaderRows(1);

        document.add(table);

        // *******************************************************************************************//
        // 1.3 Project Change Control
        // *******************************************************************************************//

        document.setPageSize(DEFAULT_PAGE_SIZE);
        document.add(Chunk.NEXTPAGE);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_3);
        addSectionTitle(document, MPSRUI.TREE_1_3, fontSection1Header, 6, 12, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_3_1);
        addSectionTitle(document, MPSRUI.TREE_1_3_1, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_3_2);
        addSectionTitle(document, MPSRUI.TREE_1_3_2, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_2(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 2 Safety
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_2);
        addSectionTitle(document, MPSRUI.TREE_2, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, safety.getDesc1(), fontNormal, 12, 0, 12);

        paragraph = new Paragraph("Table 2.1 Project Safety Summary", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(300);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell = new PdfPCell(new Phrase("Total Work Hours", fontTableColumnHeaderYellow));
        cell.setColspan(3);
        cell.setBackgroundColor(BaseColor.BLUE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);

        headers = new String[] { "Current Period", "Calendar YTD", "Project To Date" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cellValues = new String[][] { { INTEGER_FORMATTER.format(safety.getTotalWorkHoursCurrent()),
                INTEGER_FORMATTER.format(safety.getTotalWorkHoursYTD()),
                INTEGER_FORMATTER.format(safety.getTotalWorkHoursPTD()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][2], fontTableCellBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // -----------------------------------

        table = new PdfPTable(4);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell = new PdfPCell(new Phrase("Incidents", fontTableColumnHeaderYellow));
        cell.setColspan(4);
        cell.setBackgroundColor(BaseColor.BLUE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);

        cellValues = new String[][] {
                { "OSHA Recordable", INTEGER_FORMATTER.format(safety.getOshaRecordableCurrent()),
                        INTEGER_FORMATTER.format(safety.getOshaRecordableYTD()),
                        INTEGER_FORMATTER.format(safety.getOshaRecordablePTD()) },
                { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid1Current()),
                        INTEGER_FORMATTER.format(safety.getFirstAid1YTD()),
                        INTEGER_FORMATTER.format(safety.getFirstAid1PTD()) },
                { "Near Miss", INTEGER_FORMATTER.format(safety.getNearMissCurrent()),
                        INTEGER_FORMATTER.format(safety.getNearMissYTD()),
                        INTEGER_FORMATTER.format(safety.getNearMissPTD()) },
                { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid2Current()),
                        INTEGER_FORMATTER.format(safety.getFirstAid2YTD()),
                        INTEGER_FORMATTER.format(safety.getFirstAid2PTD()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0], fontTableRowTitle));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][2]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][3], fontTableCellBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cell = new PdfPCell(new Phrase("*Note - " + safety.getNote(), fontTableNote));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // *******************************************************************************************//
        // 3 Project Authorization
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_3);
        addSectionTitle(document, MPSRUI.TREE_3, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, auth.getDesc1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(10);
        table.setSpacingBefore(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 2, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "$ Millions", "Prior", auth.getHeaderYear0(), auth.getHeaderYear1(),
                auth.getHeaderYear2(), auth.getHeaderYear3(), auth.getHeaderYear4(), auth.getHeaderPostYear(),
                "Total", "Auth" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setBackgroundColor(BaseColor.YELLOW);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cellValues = new String[][] { { "Base", NUMBER_FORMATTER.format(auth.getBasePriorYear()),
                NUMBER_FORMATTER.format(auth.getBaseYear0()), NUMBER_FORMATTER.format(auth.getBaseYear1()),
                NUMBER_FORMATTER.format(auth.getBaseYear2()), NUMBER_FORMATTER.format(auth.getBaseYear3()),
                NUMBER_FORMATTER.format(auth.getBaseYear4()), NUMBER_FORMATTER.format(auth.getBasePostYear()),
                NUMBER_FORMATTER.format(auth.getBaseTotal()), "" },
                { "Risk & Contingency", NUMBER_FORMATTER.format(auth.getRnCPriorYear()),
                        NUMBER_FORMATTER.format(auth.getRnCYear0()),
                        NUMBER_FORMATTER.format(auth.getRnCYear1()),
                        NUMBER_FORMATTER.format(auth.getRnCYear2()),
                        NUMBER_FORMATTER.format(auth.getRnCYear3()),
                        NUMBER_FORMATTER.format(auth.getRnCYear4()),
                        NUMBER_FORMATTER.format(auth.getRnCPostYear()),
                        NUMBER_FORMATTER.format(auth.getRnCTotal()), "" },
                { "Total Project " + auth.getTotalProjectDate(), NUMBER_FORMATTER.format(auth.getPriorTotal()),
                        NUMBER_FORMATTER.format(auth.getYear0Total()),
                        NUMBER_FORMATTER.format(auth.getYear1Total()),
                        NUMBER_FORMATTER.format(auth.getYear2Total()),
                        NUMBER_FORMATTER.format(auth.getYear3Total()),
                        NUMBER_FORMATTER.format(auth.getYear4Total()),
                        NUMBER_FORMATTER.format(auth.getPostTotal()),
                        NUMBER_FORMATTER.format(auth.getTotalTotal()), "" },
                { "Current Request " + auth.getReq0RequestDate(),
                        NUMBER_FORMATTER.format(auth.getReq0PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq0Year0()),
                        NUMBER_FORMATTER.format(auth.getReq0Year1()),
                        NUMBER_FORMATTER.format(auth.getReq0Year2()),
                        NUMBER_FORMATTER.format(auth.getReq0Year3()),
                        NUMBER_FORMATTER.format(auth.getReq0Year4()),
                        NUMBER_FORMATTER.format(auth.getReq0PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq0Total()),
                        NUMBER_FORMATTER.format(auth.getReq0Authorization()) },
                { "Request Date " + auth.getReq1RequestDate(), NUMBER_FORMATTER.format(auth.getReq1PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq1Year0()),
                        NUMBER_FORMATTER.format(auth.getReq1Year1()),
                        NUMBER_FORMATTER.format(auth.getReq1Year2()),
                        NUMBER_FORMATTER.format(auth.getReq1Year3()),
                        NUMBER_FORMATTER.format(auth.getReq1Year4()),
                        NUMBER_FORMATTER.format(auth.getReq1PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq1Total()),
                        NUMBER_FORMATTER.format(auth.getReq1Authorization()) },
                { "Request Date " + auth.getReq2RequestDate(), NUMBER_FORMATTER.format(auth.getReq2PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq2Year0()),
                        NUMBER_FORMATTER.format(auth.getReq2Year1()),
                        NUMBER_FORMATTER.format(auth.getReq2Year2()),
                        NUMBER_FORMATTER.format(auth.getReq2Year3()),
                        NUMBER_FORMATTER.format(auth.getReq2Year4()),
                        NUMBER_FORMATTER.format(auth.getReq2PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq2Total()),
                        NUMBER_FORMATTER.format(auth.getReq2Authorization()) },
                { "Target Budget", "", "", "", "", "", "", "", auth.getTargetBudget(), "" } };
        for (int i = 0; i < cellValues.length; i++) {

            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            for (int j = 1; j < cellValues[i].length; j++) {
                cell = new PdfPCell(new Phrase(cellValues[i][j]));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell);
            }
        }

        document.add(table);

        // *******************************************************************************************//
        // 4 Project Budget
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_4);
        addSectionTitle(document, MPSRUI.TREE_4, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, budget.getDesc1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(2);
        table.setSpacingBefore(6);
        table.setTotalWidth(350);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 5, 2 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cellValues = new String[][] {
                { "Current Approved Budget (Base + RnC)",
                        CURRENCY_FORMATTER.format(budget.getPMBudget()) + "M" },
                { "Approved Phase Funding", CURRENCY_FORMATTER.format(budget.getPMActual()) + "M" },
                { "Expended To Date", CURRENCY_FORMATTER.format(budget.getPMCommitment()) + "M" },
                { "At Completion", CURRENCY_FORMATTER.format(budget.getPMAdditionalCost()) + "M" } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // ----------------------------------------------------
        // table 4.1
        // ----------------------------------------------------

        paragraph = new Paragraph("Table 4.1 Cost Report Summary", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Work Element", "Description", "Estimate", "Actual", "EAC" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < costRpt.length; i++) {
            cell = new PdfPCell(new Phrase(costRpt[i].getWbs()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(costRpt[i].getWbsDesc()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEstimate())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getActual())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEAC())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 5 Project Schedule
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_5);
        addSectionTitle(document, MPSRUI.TREE_5, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_1);
        addSectionTitle(document, MPSRUI.TREE_5_1, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_1(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_2);
        addSectionTitle(document, MPSRUI.TREE_5_2, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_2(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_3);
        addSectionTitle(document, MPSRUI.TREE_5_3, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_3(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_4);
        addSectionTitle(document, MPSRUI.TREE_5_4, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_4(), fontNormal, 12, 0, 12);

        // ----------------------------------------------------
        // table 5.1
        // ----------------------------------------------------

        paragraph = new Paragraph("Table 5.1 Planned Scorecard Milestones", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Milestone", "Planned Date", "Finish Date" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < milestones.length; i++) {
            cell = new PdfPCell(new Phrase(milestones[i].getMilestone()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(milestones[i].getPlannedDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(milestones[i].getFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 6 License & Permitting, and Environmental Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_6);
        addSectionTitle(document, MPSRUI.TREE_6, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_6_1);
        addSectionTitle(document, MPSRUI.TREE_6_1, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_1(), fontNormal, 12, 0, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_6_2);
        addSectionTitle(document, MPSRUI.TREE_6_2, fontSection1Header, 6, 12, 12);

        addOutline(outline2, writer, MPSRUI.TREE_6_2_1);
        addSectionTitle(document, MPSRUI.TREE_6_2_1, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_6_2_2);
        addSectionTitle(document, MPSRUI.TREE_6_2_2, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_2(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 7 Engineering Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_7);
        addSectionTitle(document, MPSRUI.TREE_7, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_7_1);
        addSectionTitle(document, MPSRUI.TREE_7_1, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1, 3 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < ipds.length; i++) {
            cell = new PdfPCell(new Phrase(ipds[i].getPackage()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIFR()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIFC()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIndicator()));
            cell.setBackgroundColor(getBackgroundColor(ipds[i].getIndicator()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getNote()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);
        }

        document.add(table);

        // -----------------------------------------------------------------------------------//

        addOutline(outline1, writer, MPSRUI.TREE_7_2);
        addSectionTitle(document, MPSRUI.TREE_7_2, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1, 3 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < opds.length; i++) {
            cell = new PdfPCell(new Phrase(opds[i].getPackage()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIFR()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIFC()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIndicator()));
            cell.setBackgroundColor(getBackgroundColor(opds[i].getIndicator()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getNote()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 8 Procurement Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_8);
        addSectionTitle(document, MPSRUI.TREE_8, fontChapterHeader, 0, 24, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_1);
        addSectionTitle(document, MPSRUI.TREE_8_1, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(2);
        table.setTotalWidth(300);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cellValues = new String[][] {
                { "Receipted to Date", CURRENCY_FORMATTER.format(procure.getReceiptedToDate()) },
                { "Open Commitments", CURRENCY_FORMATTER.format(procure.getOpenCommitment()) },
                { "Total", CURRENCY_FORMATTER.format(procure.getTotalPurchaseOrder()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        addParagraph(document, writer, xmlWorker, procure.getDesc_8_1_B(), fontNormal, 12, 12, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_2);
        addSectionTitle(document, MPSRUI.TREE_8_2, fontSection1Header, 6, 12, 12);

        // ----------------------------------------------------
        // section 8.2.1
        // ----------------------------------------------------

        addOutline(outline2, writer, MPSRUI.TREE_8_2_1);
        addSectionTitle(document, MPSRUI.TREE_8_2_1, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount",
                "This Month Description", "Total Amount" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontPOTableHeader));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        double totalToDate = 0;

        for (int i = 0; i < approvedChanges.length; i++) {
            cell = new PdfPCell(new Phrase(approvedChanges[i].getPurchaseOrder(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(approvedChanges[i].getVendor(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getPreviousAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getThisMonthAmount()),
                    fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(approvedChanges[i].getThisMonthDescription(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getTotalAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            totalToDate += approvedChanges[i].getTotalAmount();
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 7, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // ----------------------------------------------------
        // section 8.2.2
        // ----------------------------------------------------

        addOutline(outline2, writer, MPSRUI.TREE_8_2_2);
        addSectionTitle(document, MPSRUI.TREE_8_2_2, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_2(), fontNormal, 12, 0, 12);

        table = new PdfPTable(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount",
                "This Month Description", "Total Amount" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontPOTableHeader));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        totalToDate = 0;

        for (int i = 0; i < pendingChanges.length; i++) {
            cell = new PdfPCell(new Phrase(pendingChanges[i].getPurchaseOrder(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(pendingChanges[i].getVendor(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getPreviousAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getThisMonthAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(pendingChanges[i].getThisMonthDescription(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getTotalAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            totalToDate += pendingChanges[i].getTotalAmount();
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 7, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // *******************************************************************************************//
        // 9 Construction Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_9);
        addSectionTitle(document, MPSRUI.TREE_9, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_9_1);
        addSectionTitle(document, MPSRUI.TREE_9_1, fontSection1Header, 6, 12, 12);

        for (int i = 0; i < ipcs.length; i++) {
            addParagraph(document, writer, xmlWorker, ipcs[i].getWork(), fontWork, 12, 12, 0);
            addParagraph(document, writer, xmlWorker, ipcs[i].getDescription(), fontNormal, 12, 0, 0);
            addImage(document, MPSRUI.getFilePath(mpsrID, ipcs[i].getFileName()),
                    "Figure " + ipcs[i].getFigure() + " " + ipcs[i].getTitle(), fontImageCaption, 12, 3, 12);
        }

        // -----------------------------------------------------------------------------------------//

        addOutline(outline1, writer, MPSRUI.TREE_9_2);
        addSectionTitle(document, MPSRUI.TREE_9_2, fontSection1Header, 6, 12, 12);

        for (int i = 0; i < opcs.length; i++) {
            addParagraph(document, writer, xmlWorker, opcs[i].getWork(), fontWork, 12, 12, 0);
            addParagraph(document, writer, xmlWorker, opcs[i].getDescription(), fontNormal, 12, 0, 0);
            addImage(document, MPSRUI.getFilePath(mpsrID, opcs[i].getFileName()),
                    "Figure " + opcs[i].getFigure() + " " + opcs[i].getTitle(), fontImageCaption, 12, 3, 12);
        }

        // *******************************************************************************************//
        // Appendix
        // *******************************************************************************************//

        if (appendixs.length > 0) {

            document.add(Chunk.NEXTPAGE);
            outline1 = addOutline(root, writer, MPSRUI.TREE_APPENDIX);

            for (int i = 0; i < appendixs.length; i++) {
                addOutline(outline1, writer,
                        "Appendix " + appendixs[i].getNumber() + "  " + appendixs[i].getTitle());
                addSectionTitle(document,
                        "Appendix " + appendixs[i].getNumber() + "  " + appendixs[i].getTitle(),
                        fontChapterHeader, 0, 12, 12);
                addParagraph(document, writer, xmlWorker, appendixs[i].getDescription(), fontNormal, 12, 0, 0);

                importPages(document, writer, mpsrID, appendixs[i].getFileName());
            }
        }

        // *******************************************************************************************//
        // Attachment
        // *******************************************************************************************//

        if (attachments.length > 0) {

            document.setPageSize(DEFAULT_PAGE_SIZE);
            document.add(Chunk.NEXTPAGE);
            outline1 = addOutline(root, writer, MPSRUI.TREE_ATTACHMENT);

            for (int i = 0; i < attachments.length; i++) {
                addOutline(outline1, writer,
                        "Attachment " + attachments[i].getNumber() + "  " + attachments[i].getTitle());
                addSectionTitle(document,
                        "Attachment " + attachments[i].getNumber() + "  " + attachments[i].getTitle(),
                        fontChapterHeader, 0, 12, 12);
                addParagraph(document, writer, xmlWorker, attachments[i].getDescription(), fontNormal, 12, 0,
                        0);

                importPages(document, writer, mpsrID, attachments[i].getFileName());
            }
        }

        document.close();

        // *******************************************************************************************//

        // retrieve outline
        PdfReader readerOrig = new PdfReader(baosOrig.toByteArray());
        // int origNumberOfPages = readerOrig.getNumberOfPages();
        ColumnText ct = new ColumnText(null);
        ct.addElement(new Paragraph("Table of Contents", fontCoverTitle));
        List<HashMap<String, Object>> bookmarkList = SimpleBookmark.getBookmark(readerOrig);
        fillColumnText(bookmarkList, ct, 18, 0, fontSection2Header);

        // generate TOC after cover page
        ByteArrayOutputStream baosTOC = new ByteArrayOutputStream();
        PdfStamper stamperTOC = new PdfStamper(readerOrig, baosTOC);
        int tocPageEnd = 1;
        while (true) {
            stamperTOC.insertPage(++tocPageEnd, readerOrig.getPageSize(1));

            PdfContentByte underContent = stamperTOC.getUnderContent(tocPageEnd);

            generatePageHeader(document, underContent, icon, headerTexts);

            ct.setCanvas(stamperTOC.getOverContent(tocPageEnd));
            ct.setSimpleColumn(36, 36, 558, 693);
            if (!ColumnText.hasMoreText(ct.go()))
                break;
        }
        stamperTOC.close();

        // change page labels
        PdfPageLabels labels = new PdfPageLabels();
        labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
        labels.addPageLabel(tocPageEnd + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);

        // add labels
        ByteArrayOutputStream baosFinal = new ByteArrayOutputStream();
        PdfReader readerTOC = new PdfReader(baosTOC.toByteArray());
        // String selectPages = String.format("1-%s,%s-%s", tocPageEnd,
        // tocPageEnd + 1, origNumberOfPages + (tocPageEnd - 1));
        // readerTOC.selectPages(selectPages);
        PdfStamper stamperFinal = new PdfStamper(readerTOC, baosFinal);
        stamperFinal.getWriter().setPageLabels(labels);
        stamperFinal.close();

        // *******************************************************************************************//

        // send final PDF to browser
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        response.setContentLength(baosFinal.size());

        OutputStream os = response.getOutputStream();
        os.write(baosFinal.toByteArray());
        os.flush();
        os.close();

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

}

From source file:com.microware.intrahealth.Createpdf2.java

private static void createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data)
        throws BadElementException {

    Context _con = null;/*from w ww  . j av  a 2 s  .c  o  m*/
    //       PdfPTable table = new PdfPTable(new float[] { 2, 1 });

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    PdfPTable table = new PdfPTable(new float[] { 1, 3, 3, 5, 5, 2, 3, 2, 2, 2 });

    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    for (int i = 0; i < Header.length; i++) {
        //      table.addCell(new PdfPCell(new Phrase(Header[i], smallBold)));
        PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold));
        c1.getBorder();
        c1.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(c1);
    }
    //        table.addCell("Value");
    //        table.addCell("Location");
    table.setHeaderRows(1);

    //        PdfPCell c1 = new PdfPCell(new Phrase("Text",smallBold));
    //        c1.getBorder();
    //        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    //        table.addCell(c1);
    //
    //        c1 = new PdfPCell(new Phrase("Value",smallBold));
    //        c1.getBorder();
    //        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    //        table.addCell(c1);
    //
    //        table.setHeaderRows(1);
    PdfPCell[] cells = table.getRow(0).getCells();
    for (int j = 0; j < cells.length; j++) {
        cells[j].setBackgroundColor(new BaseColor(0, 85, 133));

        if (j == 0) {
            cells[j].setHorizontalAlignment(Element.ALIGN_LEFT);
        } else {
            cells[j].setHorizontalAlignment(Element.ALIGN_CENTER);
        }
    }

    dataprovider = new DataProvider(_con);
    //
    //        Font f = FontFactory.getFont(getFilesDir() + "/" + HINDI_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    //        PdfPCell eCell = new PdfPCell(new Phrase(entry, f));

    for (int i = 0; i < data.size(); i++) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(data.get(i).get("ASHAName"), subFont));

        table.addCell(String.valueOf((i + 1)));
        table.addCell(data.get(i).get("ASHAName"));
        table.addCell(data.get(i).get("VillageName"));
        table.addCell(data.get(i).get("PWName"));
        table.addCell(data.get(i).get("MotherMCTSID"));
        table.addCell(data.get(i).get("HusbandName"));
        table.addCell(Validate.changeDateFormat(data.get(i).get("CheckupVisitDate")));
        table.addCell(data.get(i).get("DangerSign"));
        table.addCell(data.get(i).get("CheckupPlace"));
        table.addCell("");

        PdfPCell[] cells1 = table.getRow(i + 1).getCells();
        cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT);
        //            cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER);
        //            cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER);

    }

    //      table.addCell("Colour");
    //      table.addCell("Hazen Unit");
    //      table.addCell("1.2");
    //      table.addCell("Turbidity");
    //      table.addCell("NTU");
    //      table.addCell("2.3");

    preface.add(table);

}