Example usage for com.itextpdf.text Document Document

List of usage examples for com.itextpdf.text Document Document

Introduction

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

Prototype


public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) 

Source Link

Document

Constructs a new Document -object.

Usage

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 w  ww.  j a  va  2s . c  o 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.hrms.struts.Reportsaction.java

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            int days1 = Integer.parseInt(days);

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

        }

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

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

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

    }

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

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

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

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

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

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

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

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

        PdfWriter.getInstance(d, b);

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

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

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

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

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

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

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

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

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

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

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

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

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

    FileInputStream fis = null;
    BufferedInputStream buff = null;

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

    File file = new File(filePath);

    if (!file.exists()) {

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

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

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

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

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

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

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

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

                }
            }
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    byte[] data = new byte[1024];

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

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

        int i = 0;

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

        data = out.toByteArray();

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

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

    return data;
}

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

public void createPDF(Context context) throws DocumentException, IOException {
    LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml"));
    this.mContext = context;
    Map<String, String> pdfParams = new HashMap();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US);
    dateFormat.setTimeZone(TimeZone.getDefault());
    this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf";
    float leftMargin = Txtbook.RIGHT_MARGIN_EVEN;
    float rightMargin = Txtbook.RIGHT_MARGIN_ODD;
    if (this.settings.addFrontCover.booleanValue()) {
        leftMargin = Txtbook.RIGHT_MARGIN_ODD;
        rightMargin = Txtbook.RIGHT_MARGIN_EVEN;
    }/*  w ww  . j  a  v  a  2 s  .  com*/
    Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN,
            Txtbook.TOP_MARGIN);
    File file = new File(Environment.getExternalStorageDirectory(), this.filename);
    if (!(file.exists() && file.canRead())) {
        file.createNewFile();
    }
    this.writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    this.writer.setCompressionLevel(this.settings.compressionLevel);
    this.writer.setStrictImageSequence(true);
    FontFactory.register("assets/fonts/DroidSans.ttf");
    this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0,
            new BaseColor(152, 152, 152));
    this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f);
    this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0,
            new BaseColor(103, 103, 103));
    this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0,
            new BaseColor(152, 152, 152));
    FontFactory.register("assets/fonts/CourierNew.ttf");
    this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0,
            new BaseColor(103, 103, 103));
    this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f);
    this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f);
    this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f);
    document.open();
    document.setMarginMirroring(true);
    document.addCreationDate();
    document.addCreator("Created with txt-book for Android www.txt-book.com");
    document.addTitle("txt-book for Android");
    if (this.settings.bookStyle == 1) {
        ConversationHeaderFooter hf = new ConversationHeaderFooter();
        hf.footerFont = this.sansFont9;
        hf.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf);
    } else {
        StorybookHeaderFooter hf2 = new StorybookHeaderFooter();
        hf2.title = this.settings.bookCoverTitle;
        hf2.headerFont = this.serifFont8Gray;
        hf2.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf2);
    }
    if (this.settings.addFrontCover.booleanValue()) {
        createFrontCoverPage(document, this.settings.bookCoverTitle,
                this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null);
        pdfParams.put("PDF Front Cover", "YES");
    } else {
        pdfParams.put("PDF Front Cover", "NO");
    }
    if (this.settings.addFrontCoverImage.booleanValue()) {
        pdfParams.put("PDF Front Cover Image", "YES");
    } else {
        pdfParams.put("PDF Front Cover Image", "NO");
    }
    if (this.settings.bookStyle == 1) {
        createContentPagesConversation(document);
    } else {
        createContentPagesStorybook(document, this.settings.bookCoverTitle);
    }
    int pages = this.writer.getPageNumber();
    if (this.settings.bookStyle == 2) {
        ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    } else {
        ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    }
    if (this.settings.addBackCover.booleanValue()) {
        pages++;
        pdfParams.put("PDF Back Cover", "YES");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
        createBackCoverPage(document, this.settings.backCoverNote);
    } else {
        pdfParams.put("PDF Back Cover", "NO");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
    }
    if (this.settings.bookStyle == 2) {
        pdfParams.put("PDF Style", "Storybook");
    } else {
        pdfParams.put("PDF Style", "Conversation");
    }
    pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString());
    document.close();
    FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams);
}

From source file:com.javaPdf.app.GeneradorContrato.java

public static void writePDF() {

    //        Document document = new Document() ;
    Document document = new Document(PageSize.LETTER, 65, 65, 60, 60);

    try {//  w  w  w  .j a v a  2s.  co  m

        /*Font que usaran las palabras destacadas con NEGRITA*/

        Font font_negrita = FontFactory.getFont("Times New Roman");
        font_negrita.setSize(11);
        font_negrita.setStyle(Font.BOLD);
        font_negrita.setFamily(Font.FontFamily.TIMES_ROMAN.toString());

        Scanner sc = new Scanner(System.in);

        Calendar calendarioGragoriano = new GregorianCalendar(12, Calendar.MONTH, 2017);

        /*Inicializar un objeto de tipo Calendar con un metodo de clase (Static) el cual
        obtiene una onstancia de la clase puede ser mas sencillo*/
        Calendar calendario = Calendar.getInstance();

        System.out.println(Calendar.DAY_OF_MONTH);
        System.out.println(calendario.getTime());

        /*Datos ingresados por teclado*/

        System.out.println("Ingrese el NOMBRE DEL EMPLEADOR: ");

        Chunk nombreEmpleador = new Chunk("[EMPLEADOR]", font_negrita);

        System.out.println("Ingrese el RUT DEL EMPLEADOR: ");

        Chunk rutEmpleador = new Chunk("xx.xxx.xxx-x", font_negrita);
        System.out.println("Ingrese el NOMBRE DEL TRABAJADOR: ");
        //            Chunk nombreTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk nombreTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese el RUT DEL TRABAJADOR: ");
        //            Chunk rutTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk rutTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese la DIRECCIN DEL TRABAJADOR: ");
        //            Chunk direccionTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk direccionTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese la COMUNA DEL TRABAJADOR: ");
        //            Chunk comunaTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk comunaTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese la FECHA DE NACIMIENTO DEL TRABAJADOR: ");
        //            Chunk fechaNacimientoTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk fechaNacimientoTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese el SUELDO QUE TENDRA EL TRABAJADOR: ");
        //            Chunk sueldoTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk sueldoTrabajador = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese la FUNCION QUE TENDRA EL TRABAJADOR: ");
        //            Chunk funcionTrabajador = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk funcionTrabajador = new Chunk(sc.nextLine().toUpperCase(), font_negrita);

        System.out.println("Ingrese la FECHA DE INICIO DE CONTRATO DEL TRABAJADOR: ");
        //            Chunk fechaInicioContrato = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk fechaInicioContrato = new Chunk(sc.nextLine(), font_negrita);

        System.out.println("Ingrese la FECHA DE TERMINO DE CONTRATO DEL TRABAJADOR: ");
        //            Chunk fechaTerminoContrato = new Chunk ("DATO DE PRUEBA", font_negrita);
        Chunk fechaTerminoContrato = new Chunk(sc.nextLine(), font_negrita);

        /*Clausulas*/
        Chunk primero = new Chunk(TEXTOPRIMERO, font_negrita);
        Chunk segundo = new Chunk(TEXTOSEGUNDO, font_negrita);
        Chunk tercero = new Chunk(TEXTOTERCERO, font_negrita);
        Chunk cuarto = new Chunk(TEXTOCUARTO, font_negrita);
        Chunk quinto = new Chunk(TEXTOQUINTO, font_negrita);
        Chunk sexto = new Chunk(TEXTOSEXTO, font_negrita);
        Chunk septimo = new Chunk(TEXTOSEPTIMO, font_negrita);
        Chunk octavo = new Chunk(TEXTOOCTAVO, font_negrita);
        Chunk noveno = new Chunk(TEXTONOVENO, font_negrita);
        //            Chunk afp = new Chunk (TEXTONOVENO2, font_negrita);
        //            Chunk salud = new Chunk (TEXTONOVENO4, font_negrita);
        //            Chunk cesantia = new Chunk (TEXTONOVENO6, font_negrita);
        Chunk decimo = new Chunk(TEXTODECIMO, font_negrita);
        Chunk undecimo = new Chunk(TEXTOUNDECIMO, font_negrita);

        //            Calendar calendario = Calendar.getInstance();
        SimpleDateFormat formateador = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("es"));
        Date fechaDate = new Date();
        Chunk fecha = new Chunk(formateador.format(fechaDate), font_negrita);

        String path = new File(".").getCanonicalPath();
        String FILE_NAME = path + "/CONTRATO " + nombreTrabajador + " RUT " + rutTrabajador + ".pdf";

        PdfWriter.getInstance(document, new FileOutputStream(new File(FILE_NAME)));

        //            Image firmaEmpleador = Image.getInstance(path + "/img/firmaEmpleador.png");
        //            firmaEmpleador.scaleAbsoluteWidth(150f);
        //            firmaEmpleador.scaleAbsoluteHeight(70f);
        //            firmaEmpleador.setAbsolutePosition(70f, 200f);
        //            
        Image timbreGerencia = Image.getInstance(path + "/img/timbreGerencia.png");
        timbreGerencia.scaleAbsoluteWidth(90f);
        timbreGerencia.scaleAbsoluteHeight(75f);
        timbreGerencia.setAbsolutePosition(230, 200f);
        //            
        Image firmaTrabajador = Image.getInstance(path + "/img/firmaTrabajador.png");
        firmaTrabajador.scaleAbsoluteWidth(160f);
        firmaTrabajador.scaleAbsoluteHeight(70f);
        firmaTrabajador.setAbsolutePosition(350, 175f);
        //            
        //            Image todoEnUno = Image.getInstance(path + "/img/todoEnUno.png");
        //            todoEnUno.scaleAbsoluteWidth(550);
        //            todoEnUno.scaleAbsoluteHeight(150);
        //            todoEnUno.setAbsolutePosition(15, 120f);

        document.open();
        FontFactory.registerDirectories();

        /*Parrafo de Titulo*/

        String tituloContrato_texto = "CONTRATO DE TRABAJO:\n";

        Font font_titulo = FontFactory.getFont("Times New Roman");
        font_titulo.setSize(14);
        font_titulo.setStyle(Font.BOLD | Font.UNDERLINE);
        font_titulo.setFamily(Font.FontFamily.TIMES_ROMAN.toString());
        Paragraph parrafoTitulo = new Paragraph(tituloContrato_texto, font_titulo);
        parrafoTitulo.setAlignment(Element.ALIGN_CENTER);

        document.add(parrafoTitulo);

        Font font_primer_parrafo = FontFactory.getFont("Times New Roman");
        font_primer_parrafo.setSize(11);
        //            font_primer_parrafo.setStyle(Font.BOLD | Font.UNDERLINE);
        font_primer_parrafo.setFamily(Font.FontFamily.TIMES_ROMAN.toString());

        Paragraph primer_parrafo = new Paragraph();

        /*Agregar CHunks a el parrafo*/
        /*PRIMER PARRAFO*/
        primer_parrafo.setAlignment(Element.ALIGN_JUSTIFIED);
        primer_parrafo.setLeading(15);
        primer_parrafo.setFont(font_primer_parrafo);
        primer_parrafo.add(TEXTO1);
        primer_parrafo.add(fecha);
        primer_parrafo.add(TEXTO2);
        primer_parrafo.add(nombreEmpleador);
        primer_parrafo.add(TEXTO3);
        primer_parrafo.add(rutEmpleador);
        primer_parrafo.add(TEXTO4);
        primer_parrafo.add(nombreTrabajador);
        primer_parrafo.add(TEXTO5);
        primer_parrafo.add(rutTrabajador);
        primer_parrafo.add(TEXTO6);
        primer_parrafo.add(direccionTrabajador);
        primer_parrafo.add(TEXTO7);
        primer_parrafo.add(comunaTrabajador);
        primer_parrafo.add(TEXTO8);
        primer_parrafo.add(fechaNacimientoTrabajador);
        primer_parrafo.add(TEXTO9);

        /*PRIMERA CLAUSULA*/
        primer_parrafo.add(primero);
        primer_parrafo.add(TEXTOPRIMERO1);
        primer_parrafo.add(funcionTrabajador);
        primer_parrafo.add(TEXTOPRIMERO2);

        /*SEGUNDA CLAUSULA*/
        primer_parrafo.add(segundo);
        //            primer_parrafo.add(TEXTOSEGUNDO1);

        /*TERCERA CLAUSULA*/
        primer_parrafo.add(tercero);
        primer_parrafo.add(TEXTOTERCERO1);
        primer_parrafo.add(Chunk.TABBING);
        primer_parrafo.add(TEXTOTERCERO2A);
        primer_parrafo.add(sueldoTrabajador);
        primer_parrafo.add(TEXTOTERCERO3A);
        primer_parrafo.add(Chunk.TABBING);
        primer_parrafo.add(TEXTOTERCERO4B);

        /*CUARTA CLAUSULA*/
        primer_parrafo.add(cuarto);
        //            primer_parrafo.add(TEXTOCUARTO1);

        /*QUINTA CLAUSULA*/
        primer_parrafo.add(quinto);
        //            primer_parrafo.add(TEXTOQUINTO1);

        /*SEXTA CLAUSULA*/
        primer_parrafo.add(sexto);
        //            primer_parrafo.add(TEXTOSEXTO1);

        /*SEPTIMA CLAUSULA*/
        primer_parrafo.add(septimo);
        //            primer_parrafo.add(TEXTOSEPTIMO1);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO2A);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO3B);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO4C);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO5D);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO6E);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO7F);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO8G);
        primer_parrafo.add(Chunk.TABBING);
        //            primer_parrafo.add(TEXTOSEPTIMO9H);

        /*OCTAVA CLAUSULA*/
        primer_parrafo.add(octavo);
        //            primer_parrafo.add(TEXTOOCTAVO1);

        /*NOVENA CLAUSULA*/
        primer_parrafo.add(noveno);
        //            primer_parrafo.add(TEXTONOVENO1);
        //            primer_parrafo.add(afp);
        //            primer_parrafo.add(TEXTONOVENO3);
        //            primer_parrafo.add(salud);
        //            primer_parrafo.add(TEXTONOVENO5);
        //            primer_parrafo.add(cesantia);

        /*public static final String TEXTONOVENO2 = " PROVIDA";
        public static final String TEXTONOVENO3 = "  Salud:";
        public static final String TEXTONOVENO4 = "FONASA";
        public static final String TEXTONOVENO5 = ", y las de cesanta en:";
        public static final String TEXTONOVENO6 = " AFC. \n\n";*/

        /*DCIMA CLAUSULA*/
        primer_parrafo.add(decimo);
        primer_parrafo.add(TEXTODECIMO1);
        primer_parrafo.add(fechaInicioContrato);
        primer_parrafo.add(TEXTODECIMO2);
        primer_parrafo.add(fechaTerminoContrato);
        primer_parrafo.add(TEXTODECIMO3);

        /*UNDECIMA CLAUSULA*/
        primer_parrafo.add(undecimo);
        //            primer_parrafo.add(TEXTOUNDECIMO1);

        document.add(primer_parrafo);

        //            document.add(todoEnUno);
        document.add(timbreGerencia);
        document.add(firmaTrabajador);
        document.addAuthor("IGVI");
        document.addTitle("CONTRATO DE TRABAJO IGVI");
        document.close();

    } catch (DocumentException e) {
        e.getMessage();
    } catch (IOException e) {
        e.getMessage();
    }

}

From source file:com.jpsycn.print.util.PDFUtils.java

private static Document setHeader(File file, Context mContext, Font simfang12, Font simfangBlod12, String title,
        String sno) throws DocumentException, IOException {
    Document document = new Document(PageSize.A4, 30, 30, 20, 0);

    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();/*from  w  w  w .ja v  a 2  s  .co m*/

    // 
    Font simhei18 = FontUtil.getFont(mContext, 18, "simhei.ttf");
    Paragraph b = new Paragraph(title, simhei18);
    b.setAlignment(Element.ALIGN_CENTER);
    document.add(b);
    // ?

    Chunk m1 = new Chunk("?", simfang12);
    Chunk m2 = new Chunk(sno, simfangBlod12);
    Paragraph p2 = new Paragraph();
    p2.add(m1);
    p2.add(m2);
    p2.setAlignment(Element.ALIGN_RIGHT);
    document.add(p2);
    return document;
}

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

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)//from ww w.  ja v  a 2 s  .co 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.masscustsoft.service.ToPdf.java

License:Open Source License

private void createPdf(Map rpt, Map<String, String> i18n, File pdf) throws Exception {
    OutputStream out = new FileOutputStream(pdf);

    ThreadHelper.set("_fonts_", new HashMap<String, BaseFont>());
    ThreadHelper.set("_defaultFont_", BaseFont.createFont());

    String pageSize = MapUtil.getStr(rpt, "pageSize", "A4");
    int defaultFontSize = MapUtil.getInt(rpt, "defaultFontSize", 6);
    ThreadHelper.set("_defaultFontSize_", defaultFontSize);
    ThreadHelper.set("_rpt_", rpt);

    int i = pageSize.indexOf(';');
    String margins = "36 36 36 36";
    if (i > 0) {
        margins = pageSize.substring(i + 1);
        pageSize = pageSize.substring(0, i);
    }// w  w  w.  j a v  a 2 s  . c o  m
    boolean rotate = false;
    if (pageSize.startsWith("@")) {
        rotate = true;
        pageSize = pageSize.substring(1);
    }
    Rectangle pSize = PageSize.getRectangle(pageSize);
    if (rotate)
        pSize = pSize.rotate();

    String mars[] = margins.split(" ");
    float ml = 0, mt = 0, mr = 0, mb = 0;
    mr = mt = mb = ml = LightUtil.decodeFloat(mars[0]);
    if (mars.length > 1) {
        mt = mb = LightUtil.decodeFloat(mars[1]);
    }
    if (mars.length > 2) {
        mr = LightUtil.decodeFloat(mars[2]);
    }
    if (mars.length > 3) {
        mb = LightUtil.decodeFloat(mars[3]);
    }
    Document doc = new Document(pSize, ml, mr, mt, mb);
    MapUtil.setIfStr(rpt, "author", doc, "addAuthor");
    MapUtil.setIfStr(rpt, "creator", doc, "addCreator");
    MapUtil.setIfStr(rpt, "title", doc, "addTitle");
    MapUtil.setIfStr(rpt, "keyWords", doc, "addKeywords");
    MapUtil.setIfStr(rpt, "subject", doc, "addSubject");

    PdfWriter writer = PdfWriter.getInstance(doc, out);
    writer.setPageEvent(this);
    writer.setStrictImageSequence(true);
    ThreadHelper.set("_writer_", writer);
    ThreadHelper.set("_doc_", doc);
    doc.open();

    List<Map> items = (List) rpt.get("items");
    for (Map row : items) {
        Element el = getElement(row);
        if (el != null)
            doc.add(el);
    }
    doc.close();
    out.close();
    writer.close();

    ThreadHelper.set("_writer_", null);
    ThreadHelper.set("_doc_", null);

}

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

License:Open Source License

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

    // marginLeft, marginRight, marginTop, marginBottom
    Document document = new Document(PageSize.A4, 50, 50, 80, 50);
    try {//  w ww  .ja  va 2  s . c  om
        if (m_shopping_basket.size() > 0) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            writer.setBoxSize("art", new Rectangle(50, 50, 560, 790));

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

            document.open();

            PdfContentByte cb = writer.getDirectContent();

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

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

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

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

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

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

            // document.add(Chunk.NEWLINE);

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

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

            document.add(Chunk.NEWLINE);

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

    } catch (DocumentException e) {

    }

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