Example usage for com.itextpdf.text Document open

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

Introduction

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

Prototype

boolean open

To view the source code for com.itextpdf.text Document open.

Click Source Link

Document

Is the document open or not?

Usage

From source file:imprimer.java

public void quitter_territoire() {

    Document document = new Document(PageSize.A4);
    try {/*  w  w  w  .  ja  v  a 2  s .  com*/
        PdfWriter.getInstance(document, new FileOutputStream("quitter territoire.pdf"));

        document.open();
        imagee(document);

        document.open();
        imagee(document);
        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Autorisation de quitter le territoire",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        //      cell = new PdfPCell(new Phrase("Fusion de 2 cellules de la premire colonne"));
        //      cell.setRowspan(2);
        //      table.addCell(cell);
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell();
        //contenu du tableau.
        table.addCell("\nNom:\n\n");
        table.addCell("\n\n");
        table.addCell("\nPrenom:\n\n");
        table.addCell("\n\n");
        table.addCell("\nGRADE :\n\n");
        table.addCell("\n\n");
        table.addCell("\nADRESSE PERSONNELLE :\n\n");
        table.addCell("\n\n");
        table.addCell("\nAFFECTATION :\n\n");
        table.addCell("\n\n");

        cell = new PdfPCell(
                new Phrase("\nJai  lhonneur de solliciter une autorisation  dabsence.\n\n"));
        cell.setColspan(2);
        table.addCell(cell);

        table.addCell("\nDU:\n\n");
        table.addCell("\n\n");
        table.addCell("\nAU:\n\n");
        table.addCell("\n\n");
        table.addCell("\nMOTIF :\n\n");
        table.addCell("\n\n");
        table.addCell("\nAVIS DU  CHEF \nDETABLISSEMENT:\n\n");
        table.addCell("\n\nFAVORABLE.def\n\n");
        cell = new PdfPCell(new Phrase("\nFait  Ouarzazate le :" + tdnow + "\n\n"));
        cell.setColspan(2);

        table.addCell(cell);
        table.addCell("Signature du  demandeur\n\n\n\n\n\n\n\n\n");
        table.addCell("Cachet  et  signature\n\n\n\n\n\n\n\n");
        document.add(table);
        document.close();
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("quitter territoire.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

    } catch (Exception ex) {
        System.out.print("catch");
    }
}

From source file:Servlet3.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from ww w.  j  a v  a 2s.c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        System.out.println("inside servlet");
        String a = request.getParameter("countryf");
        String c = request.getParameter("submit");
        String b = request.getParameter("paramf");

        //code added by Murugappan

        String CurentUID = request.getParameter("UIDvalue2f");
        String URLRequest = request.getRequestURL().append('?').append(request.getQueryString()).toString();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        SimpleDateFormat format1 = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy");
        String date1 = cal.getTime().toString();

        System.out.println("inside servlet");

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:server");

        //iserting data to UserActivity table
        Statement sthistoryinsert3 = con.createStatement();
        String insertstring = "Insert into UserActivity values('" + CurentUID + "','" + date1
                + "','Future Data Forecast','" + a + "','" + b + "','" + URLRequest + "')";
        sthistoryinsert3.executeUpdate(insertstring);
        sthistoryinsert3.close();
        System.out.println("\n Step 1");
        Statement st = con.createStatement();
        //  Statement st2 = con.createStatement();
        XYSeriesCollection dataset = new XYSeriesCollection();
        XYSeries series = new XYSeries(b);

        String query = "SELECT [2000],[2012] FROM country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        System.out.println(query);
        ResultSet rs = st.executeQuery(query);
        if (rs == null)
            System.out.println("\n no rows ");
        else
            System.out.println("Rows present ");
        rs.next();

        Double start = Double.parseDouble(rs.getString(1));
        Double end = Double.parseDouble(rs.getString(2));
        Double period = 13.0;
        Double growth = Math.pow((end / start), (1 / period)) - 1;
        System.out.println("growth percentage =" + growth);
        rs.close();
        String query2 = "select [2011],[2012] from country where CountryName='" + a + "' AND SeriesName='" + b
                + "'";
        rs = st.executeQuery(query2);
        rs.next();
        series.add(2011, Double.parseDouble(rs.getString(1)));
        Double second = Double.parseDouble(rs.getString(2));
        series.add(2012, second);

        Double growthvalue = second + (second * growth);

        series.add(2013, growthvalue);
        for (int i = 2014; i <= 2016; i++) {
            System.out.println("actual growth value = " + growthvalue);
            series.add((i++), (growthvalue + growthvalue * growth));
            growthvalue = growthvalue + growthvalue * growth;
        }
        rs.close();
        dataset.addSeries(series);
        DecimalFormat format_2Places = new DecimalFormat("0.00");
        growth = growth * 100;
        growth = Double.valueOf(format_2Places.format(growth));
        JFreeChart chart = ChartFactory.createXYLineChart(
                "Energy forecasting for " + a + " based on " + b + " with growth value estimated at " + growth
                        + "% ",
                "Year", "Energy consumed in millions", dataset, PlotOrientation.VERTICAL, true, true, false);
        // JFreeChart chart1=ChartFactory.createLineChart("World population Growth","Year","population in millions",dataSet1,PlotOrientation.VERTICAL,true,true,false);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        chart.setBackgroundPaint(Color.white);
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.black);
        plot.setRangeGridlinePaint(Color.black);

        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, false);
        plot.setRenderer(renderer);

        /* We have to insert this colored Pie Chart into the PDF file using iText now */

        if (c.equals("View Graph in Browser")) {
            ChartUtilities.writeChartAsPNG(bos, chart, 700, 500);
            response.setContentType("image/png");
            OutputStream out = new BufferedOutputStream(response.getOutputStream());
            out.write(bos.toByteArray());
            out.flush();
            out.close();
        }

        else {
            int width = 640; /* Width of our chart */
            int height = 480; /* Height of our chart */
            Document PieChart = new Document(new com.itextpdf.text.Rectangle(width, height));
            java.util.Date date = new java.util.Date();
            String chartname = "My_Colored_Chart" + date.getTime() + ".pdf";
            PdfWriter writer = PdfWriter.getInstance(PieChart, new FileOutputStream(chartname));
            PieChart.open();
            /* Add some Metadata to identify document later */
            PieChart.addTitle("How to color your Pie Chart and embed in a PDF file using iText");
            PieChart.addAuthor("Thinktibits");
            PieChart.addKeywords("iText,Color PieChart,JFreeChart,PDF,Example Tutorial");
            PdfContentByte Add_Chart_Content = writer.getDirectContent();
            PdfTemplate template_Chart_Holder = Add_Chart_Content.createTemplate(width, height);
            Graphics2D Graphics_Chart = template_Chart_Holder.createGraphics(width, height,
                    new DefaultFontMapper());
            Rectangle2D Chart_Region = new Rectangle2D.Double(0, 0, 540, 380);
            chart.draw(Graphics_Chart, Chart_Region);
            Graphics_Chart.dispose();
            Add_Chart_Content.addTemplate(template_Chart_Holder, 0, 0);
            PieChart.close();
            //PrintWriter out = response.getWriter();
            //out.println("<!DOCTYPE html> <html> <body> <a href =file:///C:/apache-tomcat-8.0.12/bin/"+chartname+" download=newFileName> Download your file here </a> </body></html>");
            PdfReader reader = new PdfReader(chartname);
            PdfStamper stamper = null;
            try {
                stamper = new PdfStamper(reader, bos);
            } catch (DocumentException e) {
                e.printStackTrace();
            }
            try {
                stamper.close();
            } catch (DocumentException e) {

                e.printStackTrace();
            }

            // set some response headers
            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(bos.size());

            OutputStream os = response.getOutputStream();
            bos.writeTo(os);
            os.flush();
            os.close();
        }
    }

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

}

From source file:PrintMaleMembers.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w  w .  j  av a 2  s.  co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        response.setContentType("Invoice.pdf");
        //Get the output stream for writing PDF object
        OutputStream out = response.getOutputStream();
        SystemDao dao = new SystemDao();

        String username_dbase = getServletContext().getInitParameter("username");
        String dbasepsw = getServletContext().getInitParameter("password");
        String dbase = getServletContext().getInitParameter("jdbcConnection");
        dao.open(username_dbase, dbasepsw, dbase);

        Document document = new Document();
        /* Basic PDF Creation inside servlet */

        ArrayList<User> users = dao.gettAllUsers();
        //tithes
        ArrayList<Donation> list = dao.getAllDonations();
        ArrayList<String> projects = dao.getProjects();
        //donaations
        Vector<String> donations = dao.get_donation();

        PdfWriter.getInstance(document, out);

        document.open();
        document.addAuthor("LightHouse Chapel International");
        document.addCreationDate();
        document.addCreator("lci.com");
        document.addTitle("USER INFORMATION SUMMARY");

        document.add(new Paragraph(" "));
        document.add(new Paragraph("============ USERS ==========="));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("   NAME     " + "                  " + "   SURNAME   "
                + "                  " + "  ACCOUNT NUMBER  "));
        for (User user : users) {
            document.add(new Paragraph("  " + user.getName() + "                  " + user.getSurname()
                    + "                  " + user.getEmail()));
        }
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" Total Users : " + users.size()));
        document.add(new Paragraph(" "));
        document.close();
    } catch (Exception ex) {
        response.sendRedirect("systemError.jsp");
    }
}

From source file:BillingArchiveFrame.java

private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed
    // TODO add your handling code here:
    String title = "";
    if (jTabbedPane2.getSelectedIndex() == 0) {
        model = (DefaultTableModel) residentpersonalinfotable.getModel();
        title = "AccountSummary";
    } else if (jTabbedPane2.getSelectedIndex() == 1) {
        model = (DefaultTableModel) residentaddresstable.getModel();
        title = "transientBilling";
    } else if (jTabbedPane2.getSelectedIndex() == 2) {
        model = (DefaultTableModel) residentcontactinfotable.getModel();
        title = "residentBilling";
    }/*from w w w  .j ava  2  s .  c o m*/
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\" + title + "BillingArchive.pdf"));
        document.open();
        model = (DefaultTableModel) residentpersonalinfotable.getModel();
        PdfPTable tab = new PdfPTable(model.getColumnCount());
        for (int i = 0; i < model.getColumnCount(); i++) {
            tab.addCell(model.getColumnName(i));
        }
        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                if (model.getValueAt(i, j) != null) {
                    tab.addCell(model.getValueAt(i, j).toString());
                } else {
                    tab.addCell("-");
                }
            }
        }
        document.add(tab);

        JOptionPane.showMessageDialog(null,
                "Data saved at " + path + "'\\PDF\\BillingArchive.pdf' successfully", "Message",
                JOptionPane.INFORMATION_MESSAGE);
        document.close();

    } catch (FileNotFoundException | DocumentException ex) {
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:ReportGen.java

private void exportcounttablepdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportcounttablepdfActionPerformed
    Document document = new Document();
    try {//w w  w  .  ja  v a2 s .c  o  m
        PdfWriter.getInstance(document, new FileOutputStream(path + "\\counttablePDF.pdf"));
        document.open();

        PdfPTable tab = new PdfPTable(dataTable.getColumnCount());
        for (int i = 0; i < dataTable.getColumnCount(); i++) {
            tab.addCell(dataTable.getColumnName(i));
        }
        for (int i = 0; i < dataTable.getRowCount(); i++) {
            for (int j = 0; j < dataTable.getColumnCount(); j++) {
                tab.addCell(dataTable.getValueAt(i, j).toString());
            }
        }
        document.add(tab);

        JOptionPane.showMessageDialog(null, "Data saved at " + path + "'\\counttablePDF.pdf' successfully",
                "Message", JOptionPane.INFORMATION_MESSAGE);
        document.close();

    } catch (FileNotFoundException | DocumentException ex) {
        //            Logger.getLogger(ResidentArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:RegistrationArchiveFrame.java

private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed
    // TODO add your handling code here:
    // TODO add your handling code here:
    String title = "";
    if (jTabbedPane2.getSelectedIndex() == 0) {
        model = (DefaultTableModel) regpersonalinfotable.getModel();
        title = "PersonalInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 1) {
        model = (DefaultTableModel) regcontactinfotable.getModel();
        title = "ContactInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 2) {
        model = (DefaultTableModel) regfathersinfotable.getModel();
        title = "FatherInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 3) {
        model = (DefaultTableModel) regmothersinfotable.getModel();
        title = "MotherInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 4) {
        model = (DefaultTableModel) regguardiansinfotable.getModel();
        title = "GuardianInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 5) {
        model = (DefaultTableModel) guardianaddresstable.getModel();
        title = "GuardianAddress";
    }/*from ww w  .j  a va  2  s  . co  m*/

    Document document = new Document();
    try {
        PdfWriter.getInstance(document,
                new FileOutputStream(path + "\\PDF\\" + title + "RegistrationArchive.pdf"));

        document.open();

        PdfPTable tab = new PdfPTable(model.getColumnCount());
        for (int i = 0; i < model.getColumnCount(); i++) {
            tab.addCell(model.getColumnName(i));
        }
        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                if (model.getValueAt(i, j) != null) {
                    tab.addCell(model.getValueAt(i, j).toString());
                } else {
                    tab.addCell("-");
                }
            }
        }
        document.add(tab);

        JOptionPane.showMessageDialog(null,
                "Data saved at " + path + "'\\PDF\\" + title + "RegistrationArchive.pdf' successfully",
                "Message", JOptionPane.INFORMATION_MESSAGE);
        document.close();

    } catch (FileNotFoundException | DocumentException ex) {
        //            Logger.getLogger(RegistrationArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:generatereportbyaccz.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   ww w . j av  a2 s .  c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ClassNotFoundException {
    // setting the content type
    response.setContentType("application/pdf");
    try {
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            // Get the text that will be added to the PDF

            String month = request.getParameter("month");
            String year = request.getParameter("year");
            //String id=request.getParameter("empid");
            //  System.out.println(id);
            //   String text = request.getParameter("text");
            //  if (text == null || text.trim().length() == 0) {
            //       text = "You didn't enter any text.";
            //  }
            //String id="Ultimate01";    
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll123", "root", "");

            PreparedStatement ps = con
                    .prepareStatement("SELECT SUM(basicsalary) as sum1 FROM payslip where month=? and year=?");
            ps.setString(1, month);
            ps.setString(2, year);
            System.out.println("hey1");
            PreparedStatement ps1 = con.prepareStatement(
                    "SELECT COUNT(DISTINCT employeeid) as emps FROM payslip where month=? and year=?");
            ps1.setString(1, month);
            ps1.setString(2, year);
            System.out.println("hey1");

            ResultSet rs = ps.executeQuery();
            //System.out.println(rs.getInt(1));

            rs.next();
            //             System.out.println(rs.getInt("sum1"));
            ResultSet rs1 = ps1.executeQuery();
            rs1.next();
            if (rs.getFloat("sum1") == 0.0 && rs1.getFloat("emps") == 0.0) {
                response.sendRedirect("generatereportbyaccz.jsp?id=Report of " + month + "/" + year
                        + " is not generated OR Record of this Report is not available in our Database");
            }
            // step 1
            Float[] val = new Float[9];
            val[0] = rs.getFloat("sum1");
            val[1] = 6000.00f * rs1.getFloat("emps");
            val[2] = 1000.00f * rs1.getFloat("emps");
            val[3] = 1000.00f * rs1.getFloat("emps");
            val[4] = val[0] / 2;
            val[5] = 1000.00f * rs1.getFloat("emps");
            val[6] = val[4];
            val[7] = val[0] * 12 / 100;
            val[8] = 0.00f;
            if ((val[0] + val[4] + val[6]) * 12 > 250000.00f) {
                val[8] = (val[0] + val[4] + val[6]) / 10;
            }

            //System.out.println("sssssssssssssssssss");

            Document document = new Document();
            // step 2
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            Font font0 = new Font(Font.FontFamily.TIMES_ROMAN, 11);
            Font font1 = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
            Font font2 = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
            Font font3 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
            Font font4 = new Font(Font.FontFamily.HELVETICA, 10);
            Font font5 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
            Font font6 = new Font(Font.FontFamily.HELVETICA, 12);

            //font1.setColor(BaseColor.WHITE);
            BaseColor myColor = WebColors.getRGBColor("#F78181");
            BaseColor myColor1 = WebColors.getRGBColor("#FAFAFA");

            //step 3
            document.open();
            // step 3.5
            PdfPTable table1 = new PdfPTable(3); // 1 columns.
            // table1.setWidthPercentage(75);

            PdfPCell cell00 = new PdfPCell(new Paragraph("Monthly Payroll Summary\nFEB-2015", font2));
            cell00.setBorder(PdfPCell.NO_BORDER);
            cell00.setPaddingTop(18);
            cell00.setColspan(2);

            Image image = Image.getInstance("cc.jpg");
            PdfPCell cell0 = new PdfPCell(image, true);
            cell0.setBorder(PdfPCell.NO_BORDER);

            // cell0.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //PdfPCell cell1 = new PdfPCell(new Paragraph("Mr. NILESH POPATBHAI LATHIYA"));
            table1.addCell(cell00);
            //          table1.addCell(cell0);
            table1.addCell(cell0);
            //  table1.addCell(cell1);
            //            table.addCell(cell2);
            //          table.addCell(cell3);
            table1.setWidthPercentage(100);
            table1.setSpacingAfter(8f);
            //table1.setSpacingBefore(20f);

            //table1.setSpacingAfter(10f);

            document.add(table1);
            //  table1.setWidthPercentage(100);
            PdfPTable table21 = new PdfPTable(2); // 3 columns.
            table21.setWidthPercentage(100);

            PdfPCell cell151 = new PdfPCell(new Paragraph("Total Number of Employees", font3));
            //cell15.setLeading(10f, 0f);
            cell151.setPadding(3);
            cell151.setBorderWidth(1f);
            cell151.setBackgroundColor(myColor1);

            PdfPCell cell161 = new PdfPCell(new Paragraph(Integer.toString(rs1.getInt("emps")), font4));
            //  cell16.setLeading(10f, 0f);
            cell161.setPadding(3);
            cell161.setBorderWidth(1f);
            cell161.setBackgroundColor(myColor1);

            table21.addCell(cell151);
            table21.addCell(cell161);

            table21.setSpacingAfter(12f);

            document.add(table21);

            PdfPTable table2 = new PdfPTable(2); // 3 columns.

            table2.setWidthPercentage(100);

            PdfPCell cell15 = new PdfPCell(new Paragraph("Total Basic Salary", font3));
            //cell15.setLeading(10f, 0f);
            cell15.setPadding(3);
            cell15.setBorderWidth(1f);
            cell15.setBackgroundColor(myColor1);

            PdfPCell cell16 = new PdfPCell(new Paragraph(Float.toString(val[0]), font4));
            //  cell16.setLeading(10f, 0f);
            cell16.setPadding(3);
            cell16.setBorderWidth(1f);
            cell16.setBackgroundColor(myColor1);

            PdfPCell cell17 = new PdfPCell(new Paragraph("Total House Rent Allowance", font3));
            //cell17.setLeading(10f, 0f);
            cell17.setPadding(3);
            cell17.setBorderWidth(1f);
            cell17.setBackgroundColor(myColor1);
            PdfPCell cell18 = new PdfPCell(new Paragraph(Float.toString(val[1]), font4));
            //cell18.setLeading(10f, 0f);
            cell18.setPadding(3);
            cell18.setBorderWidth(1f);
            cell18.setBackgroundColor(myColor1);
            PdfPCell cell19 = new PdfPCell(new Paragraph("Total Medical Allowance", font3));
            //cell19.setLeading(10f, 0f);
            cell19.setPadding(3);
            cell19.setBorderWidth(1f);
            cell19.setBackgroundColor(myColor1);
            PdfPCell cell20 = new PdfPCell(new Paragraph(Float.toString(val[2]), font4));
            //cell20.setLeading(10f, 0f);
            cell20.setPadding(3);
            cell20.setBorderWidth(1f);
            cell20.setBackgroundColor(myColor1);

            table2.addCell(cell15);
            table2.addCell(cell16);
            table2.addCell(cell17);
            table2.addCell(cell18);
            table2.addCell(cell19);
            table2.addCell(cell20);

            PdfPCell cell21 = new PdfPCell(new Paragraph("Total Travelling Allowance", font3));
            //cell21.setLeading(10f, 0f);
            cell21.setPadding(3);
            cell21.setBorderWidth(1f);
            cell21.setBackgroundColor(myColor1);
            PdfPCell cell22 = new PdfPCell(new Paragraph(Float.toString(val[3]), font4));
            //  cell22.setLeading(10f, 0f);
            cell22.setPadding(3);
            cell22.setBorderWidth(1f);
            cell22.setBackgroundColor(myColor1);
            PdfPCell cell23 = new PdfPCell(new Paragraph("Total Personal Allowance", font3));
            //cell23.setLeading(10f, 0f);
            cell23.setPadding(3);
            cell23.setBorderWidth(1f);
            cell23.setBackgroundColor(myColor1);

            PdfPCell cell24 = new PdfPCell(new Paragraph(Float.toString(val[4]), font4));
            //cell24.setLeading(10f, 0f);
            cell24.setPadding(3);
            cell24.setBorderWidth(1f);
            cell24.setBackgroundColor(myColor1);
            PdfPCell cell25 = new PdfPCell(new Paragraph("Total City Allowance", font3));
            //cell25.setLeading(10f, 0f);
            cell25.setPadding(3);
            cell25.setBorderWidth(1f);
            cell25.setBackgroundColor(myColor1);
            PdfPCell cell26 = new PdfPCell(new Paragraph(Float.toString(val[5]), font4));
            //cell26.setLeading(10f, 0f);
            cell26.setPadding(3);
            cell26.setBorderWidth(1f);
            cell26.setBackgroundColor(myColor1);

            table2.addCell(cell21);
            table2.addCell(cell22);
            table2.addCell(cell23);
            table2.addCell(cell24);
            table2.addCell(cell25);
            table2.addCell(cell26);

            PdfPCell cell27 = new PdfPCell(new Paragraph("Total Performance Pay", font3));
            //cell27.setLeading(10f, 0f);
            cell27.setPadding(3);
            cell27.setBorderWidth(1f);
            cell27.setBackgroundColor(myColor1);
            PdfPCell cell28 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4));
            //  cell28.setLeading(10f, 0f);
            cell28.setPadding(3);
            cell28.setBorderWidth(1f);
            cell28.setBackgroundColor(myColor1);

            table2.addCell(cell27);
            table2.addCell(cell28);

            table2.setSpacingAfter(12f);

            document.add(table2);

            PdfPTable table3 = new PdfPTable(2); // 3 columns.
            table3.setWidthPercentage(100);

            PdfPCell cell271 = new PdfPCell(new Paragraph("Final Total amount paid by company", font3));
            //cell27.setLeading(10f, 0f);
            cell271.setPadding(3);
            cell271.setBorderWidth(1f);
            cell271.setBackgroundColor(myColor1);
            PdfPCell cell281 = new PdfPCell(new Paragraph(Float.toString(val[6]), font4));
            //  cell28.setLeading(10f, 0f);
            cell281.setPadding(3);
            cell281.setBorderWidth(1f);
            cell281.setBackgroundColor(myColor1);

            PdfPCell cell29 = new PdfPCell(new Paragraph("Total Provident Fund Collected", font3));
            //cell29.setLeading(10f, 0f);
            cell29.setPadding(3);
            cell29.setBorderWidth(1f);
            cell29.setBackgroundColor(myColor1);
            PdfPCell cell30 = new PdfPCell(new Paragraph(Float.toString(val[7]), font4));
            //cell30.setLeading(10f, 0f);
            cell30.setPadding(3);
            cell30.setBorderWidth(1f);
            cell30.setBackgroundColor(myColor1);
            PdfPCell cell31 = new PdfPCell(new Paragraph("Total Professional Tax Collected", font3));
            //cell31.setLeading(10f, 0f);
            cell31.setPadding(3);
            cell31.setBorderWidth(1f);
            cell31.setBackgroundColor(myColor1);
            PdfPCell cell32 = new PdfPCell(new Paragraph(Float.toString(val[8]), font4));
            //cell32.setLeading(10f, 0f);
            cell32.setPadding(3);
            cell32.setBorderWidth(1f);
            cell32.setBackgroundColor(myColor1);

            table3.addCell(cell271);
            table3.addCell(cell281);
            table3.addCell(cell29);
            table3.addCell(cell30);
            table3.addCell(cell31);
            table3.addCell(cell32);

            table3.setSpacingAfter(12f);

            document.add(table3);
            /*  PdfPCell cell33 = new PdfPCell(new Paragraph("PAN",font3));
              //cell33.setLeading(10f, 0f);
              cell33.setPadding(3);
              cell33.setBorderWidth(1f);
              cell33.setBackgroundColor(myColor1);
              PdfPCell cell34 = new PdfPCell(new Paragraph("XXXXXXX792E",font4));
            //  cell34.setLeading(10f, 0f);
              cell34.setPadding(3);
              cell34.setBorderWidth(1f);
              cell34.setBackgroundColor(myColor1);
              PdfPCell cell35 = new PdfPCell(new Paragraph("Leave Balance",font3));
              //cell35.setLeading(10f, 0f);
              cell35.setPadding(3);
              cell35.setBorderWidth(1f);
              cell35.setBackgroundColor(myColor1);
              PdfPCell cell36 = new PdfPCell(new Paragraph("EL X SL X CL X",font4));
              //cell36.setLeading(10f, 0f);
              cell36.setPadding(3);
              cell36.setBorderWidth(1f);
              cell36.setBackgroundColor(myColor1);
              PdfPCell cell37 = new PdfPCell(new Paragraph(" WON/SWON",font3));
              //cell37.setLeading(10f, 0f);
              cell37.setPadding(3);
              cell37.setBorderWidth(1f);
              cell37.setBackgroundColor(myColor1);
              PdfPCell cell38 = new PdfPCell(new Paragraph("2616141",font4));
              //cell38.setLeading(10f, 0f);
              cell38.setPadding(3);
              cell38.setBorderWidth(1f);
              cell38.setBackgroundColor(myColor1);
                      
              table2.addCell(cell33);
              table2.addCell(cell34);
              table2.addCell(cell35);
              table2.addCell(cell36);
              table2.addCell(cell37);
              table2.addCell(cell38);
             */

            /* 
             PdfPTable table3 = new PdfPTable(5); // 5 columns.
             table3.setWidthPercentage(100);
                    
             PdfPCell cell39 = new PdfPCell(new Paragraph("Earnings",font1));
             cell39.setLeading(10f, 0f);
             cell39.setPadding(4);
             cell39.setBorderWidth(1f);
             cell39.setBackgroundColor(myColor);
             PdfPCell cell40 = new PdfPCell(new Paragraph("Arrears (INR)",font1));
             cell40.setLeading(10f, 0f);
             cell40.setPadding(4);
             cell40.setBorderWidth(1f);
             cell40.setBackgroundColor(myColor);
             PdfPCell cell41 = new PdfPCell(new Paragraph("Current (INR)",font1));
             cell41.setLeading(10f, 0f);
             cell41.setPadding(4);
             cell41.setBorderWidth(1f);
             cell41.setBackgroundColor(myColor);
             PdfPCell cell42 = new PdfPCell(new Paragraph("Deductions",font1));
             cell42.setLeading(10f, 0f);
             cell42.setPadding(4);
             cell42.setBorderWidth(1f);
             cell42.setBackgroundColor(myColor);
             PdfPCell cell43 = new PdfPCell(new Paragraph("Amount (INR)",font1));
             cell43.setLeading(10f, 0f);
             cell43.setPadding(4);
             cell43.setBorderWidth(1f);
             cell43.setBackgroundColor(myColor);
                     
             table3.addCell(cell39);
             table3.addCell(cell40);
             table3.addCell(cell41);
             table3.addCell(cell42);
             table3.addCell(cell43);
                     
             String[] sal = new String[9];
             sal[0]="Basic Salary";
             sal[1]="House Rent Allowance";
             sal[2]="Medical Allowance";
             sal[3]="Travelling Allowance";
             sal[4]="Personal Allowance";
             sal[5]="City Allowance";
             sal[6]="Performance Pay";
             sal[7]="Provident Fund";
             sal[8]="Professional Tax";
                     
             Float[] val = new Float[9];
             val[0]=rs1.getFloat(4);
             val[1]=6000.00f;
             val[2]=1000.00f;
             val[3]=1000.00f;
             val[4]=val[0]/2;
             val[5]=1000.00f;
             val[6]=val[4];
             val[7]=val[0]*12/100;
             val[8]=0.00f;
             if((val[0]+val[4]+val[6])*12>250000.00f)
             {
                 val[8]=(val[0]+val[4]+val[6])/10;
             }
                     
                     
                     
             for(int i=0;i<7;i++)
             {
              PdfPCell cell44 = new PdfPCell(new Paragraph(sal[i],font3));
             //cell27.setLeading(10f, 0f);
             cell44.setPadding(3);
             cell44.setBorderWidth(1f);
             cell44.setBackgroundColor(myColor1);
             PdfPCell cell45 = new PdfPCell(new Paragraph("",font4));
            //  cell45.setLeading(10f, 0f);
             cell45.setPadding(3);
             cell45.setBorderWidth(1f);
             cell45.setBackgroundColor(myColor1);
             PdfPCell cell46 = new PdfPCell(new Paragraph(val[i].toString(),font3));
             //cell46.setLeading(10f, 0f);
             cell46.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell46.setPadding(3);
             cell46.setBorderWidth(1f);
             cell46.setBackgroundColor(myColor1);
                         
             table3.addCell(cell44);
             table3.addCell(cell45);
             table3.addCell(cell46);
                     
                     
             if(i==0 || i==1) {       
             PdfPCell cell47 = new PdfPCell(new Paragraph(sal[7+i],font4));
             //cell47.setLeading(10f, 0f);
             cell47.setPadding(3);
             cell47.setBorderWidth(1f);
             cell47.setBackgroundColor(myColor1);
             table3.addCell(cell47);
             PdfPCell cell48 = new PdfPCell(new Paragraph(val[i+7].toString(),font3));
             //cell48.setLeading(10f, 0f);
             cell48.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell48.setPadding(3);
             cell48.setBorderWidth(1f);
             cell48.setBackgroundColor(myColor1);
             table3.addCell(cell48);
             }
             else
             {
             PdfPCell cell47 = new PdfPCell(new Paragraph("",font4));
             cell47.setBorder(PdfPCell.NO_BORDER);
             cell47.setBorderWidthRight (1f);
             cell47.setColspan(2);
             table3.addCell(cell47);
             }
                        
             }
                     
             PdfPCell cell48 = new PdfPCell(new Paragraph("",font4));
             //cell48.setBorder(PdfPCell.NO_BORDER);
             cell48.setColspan(3);
             table3.addCell(cell48);
                     
             PdfPCell cell49 = new PdfPCell(new Paragraph("",font4));
             //cell49.setBorder(PdfPCell.NO_BORDER);
             cell49.setColspan(2);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
             table3.addCell(cell48);
             table3.addCell(cell49);
                    
                     
             PdfPCell cell50 = new PdfPCell(new Paragraph("Total Earnings (Current + Arrears)",font3));
             //cell27.setLeading(10f, 0f);
             cell50.setColspan(2);
             cell50.setPadding(3);
             cell50.setBorderWidth(1f);
             cell50.setBackgroundColor(myColor1);
             table3.addCell(cell50);
                     
             float a = 0.0f;
            for(int i=0;i<7;i++)
            {a+=val[i];}
             PdfPCell cell55 = new PdfPCell(new Paragraph(Float.toString(a),font3));
             //cell27.setLeading(10f, 0f);
             cell55.setPadding(3);
             cell55.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell55.setBorderWidth(1f);
             cell55.setBackgroundColor(myColor1);
             table3.addCell(cell55);
                     
                     
             PdfPCell cell51 = new PdfPCell(new Paragraph("Total Deductions",font3));
             //cell27.setLeading(10f, 0f);
             //cell51.setColspan(3);
             cell51.setPadding(3);
             cell51.setBorderWidth(1f);
             cell51.setBackgroundColor(myColor1);
             table3.addCell(cell51);
                     
             float b = val[7]+val[8];
                    
             PdfPCell cell56 = new PdfPCell(new Paragraph(Float.toString(b),font3));
             //cell27.setLeading(10f, 0f);
             //cell56.setColspan(3);
             cell56.setPadding(3);
             cell56.setHorizontalAlignment(Element.ALIGN_RIGHT);
             cell56.setBorderWidth(1f);
             cell56.setBackgroundColor(myColor1);
             table3.addCell(cell56);
                     
             table3.setSpacingAfter(12f);
                    
             document.add(table3);
                    
             PdfPTable table4 = new PdfPTable(5); // 2 columns.
             table4.setWidthPercentage(100);
                     
             PdfPCell cell54 = new PdfPCell(new Paragraph("",font3));
             cell54.setBorder(PdfPCell.NO_BORDER);
             cell54.setColspan(3);
             table4.addCell(cell54);
                     
             PdfPCell cell52 = new PdfPCell(new Paragraph("Net Pay",font5));
            cell52.setLeading(10f, 0f);
            // cell52.setBorder(PdfPCell.ALIGN_CENTER);
             cell52.setHorizontalAlignment(Element.ALIGN_LEFT);
             cell52.setVerticalAlignment(Element.ALIGN_CENTER);
                     
             cell52.setPadding(6f);
             cell52.setBorderWidth(1f);
             cell52.setBackgroundColor(myColor);
             table4.addCell(cell52);
                     
             PdfPCell cell53 = new PdfPCell(new Paragraph(""+(a-b),font6));
             cell53.setLeading(10f, 0f);
             cell53.setPadding(6f);
                  cell53.setHorizontalAlignment(Element.ALIGN_CENTER);
             cell53.setVerticalAlignment(Element.ALIGN_CENTER);
            cell53.setBorderWidth(1f);
                     
             table4.addCell(cell53);
                     
             document.add(table4);
                    
            */

            // step 4
            // document.add(new Paragraph(String.format(
            //         "You have submitted the following text using the %s method:%s",
            //        request.getMethod(),uname)));
            //   document.add(new Paragraph(text));
            // step 5
            document.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");

            // the contentlength
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            OutputStream os = response.getOutputStream();
            baos.writeTo(os);
            os.flush();
            os.close();
        } else {
            response.sendRedirect("index.jsp?id=Your session may be expired. You have to login first");

        }
    } catch (Exception e) {
        //       throw new IOException(e.getMessage());
        System.out.println(e);
        System.out.println("sssssssssssssssssss");

    }
}

From source file:adams.flow.transformer.PDFExtract.java

License:Open Source License

/**
 * Executes the flow item.//from ww  w. j a  v  a2  s  . c om
 *
 * @return      null if everything is fine, otherwise error message
 */
@Override
protected String doExecute() {
    String result;
    File file;
    int i;
    Document document;
    PdfCopy copy;
    PdfReader reader;
    int[] pages;
    int page;
    FileOutputStream fos;

    result = null;

    // get file
    if (m_InputToken.getPayload() instanceof File)
        file = (File) m_InputToken.getPayload();
    else
        file = new PlaceholderFile((String) m_InputToken.getPayload());

    fos = null;
    try {
        if (isLoggingEnabled())
            getLogger().info("Extracting pages from '" + file + "' into '" + m_Output + "'");
        document = new Document();
        fos = new FileOutputStream(m_Output.getAbsolutePath());
        copy = new PdfCopy(document, fos);
        document.open();
        document.addCreationDate();
        document.addCreator(Environment.getInstance().getProject());
        document.addAuthor(System.getProperty("user.name"));
        reader = new PdfReader(file.getAbsolutePath());
        if (isLoggingEnabled())
            getLogger().info("- #pages: " + reader.getNumberOfPages());
        m_Pages.setMax(reader.getNumberOfPages());
        pages = m_Pages.getIntIndices();
        for (i = 0; i < pages.length; i++) {
            page = pages[i] + 1;
            copy.addPage(copy.getImportedPage(reader, page));
            if (isLoggingEnabled())
                getLogger().info("- adding page: " + page);
        }
        copy.freeReader(reader);
        document.close();
    } catch (Exception e) {
        result = handleException("Failed to extract pages: ", e);
    } finally {
        FileUtils.closeQuietly(fos);
    }

    if (result == null)
        m_OutputToken = new Token(m_Output.getAbsolutePath());

    return result;
}

From source file:adams.flow.transformer.PDFMerge.java

License:Open Source License

/**
 * Executes the flow item.//from  w ww .  ja v  a2  s.  c  o m
 *
 * @return      null if everything is fine, otherwise error message
 */
@Override
protected String doExecute() {
    String result;
    PlaceholderFile[] files;
    int i;
    int n;
    int pages;
    Document document;
    PdfCopy copy;
    PdfReader reader;
    FileOutputStream fos;

    result = null;

    // get files
    files = FileUtils.toPlaceholderFileArray(m_InputToken.getPayload());

    fos = null;
    try {
        if (isLoggingEnabled())
            getLogger().info("Merging PDFs into: " + m_Output);
        document = new Document();
        fos = new FileOutputStream(m_Output.getAbsolutePath());
        copy = new PdfCopy(document, fos);
        document.open();
        document.addCreationDate();
        document.addCreator(Environment.getInstance().getProject());
        document.addAuthor(System.getProperty("user.name"));
        for (i = 0; i < files.length; i++) {
            if (isLoggingEnabled())
                getLogger().info("Adding file: " + files[i]);
            reader = new PdfReader(files[i].getAbsolutePath());
            // loop over the pages in that document
            pages = reader.getNumberOfPages();
            if (isLoggingEnabled())
                getLogger().info("- #pages: " + pages);
            for (n = 1; n <= pages; n++) {
                copy.addPage(copy.getImportedPage(reader, n));
                if (isLoggingEnabled())
                    getLogger().info("- adding page: " + n);
            }
            copy.freeReader(reader);
        }
        document.close();
    } catch (Exception e) {
        result = handleException("Failed to merge PDF files: ", e);
    } finally {
        FileUtils.closeQuietly(fos);
    }

    if (result == null)
        m_OutputToken = new Token(m_Output.getAbsolutePath());

    return result;
}

From source file:adams.gui.print.PDFWriter.java

License:Open Source License

/**
 * generates the actual output.// w ww.  ja  v  a2  s. co  m
 *
 * @throws Exception   if something goes wrong
 */
@Override
public void generateOutput() throws Exception {
    BufferedImage bi;
    Document doc;
    Image image;
    float scale;
    FileOutputStream fos;

    // render image
    bi = createBufferedImage();

    // generate PDF
    scale = (float) m_ImageScale;
    doc = new Document();
    fos = new FileOutputStream(getFile().getAbsoluteFile());
    PdfWriter.getInstance(doc, fos);
    doc.open();
    image = Image.getInstance(Toolkit.getDefaultToolkit().createImage(bi.getSource()), null);
    if (m_ImageRotation != 0) {
        image.setRotationDegrees(m_ImageRotation);
        image.rotate();
    }
    image.scaleToFit(doc.getPageSize().getWidth() * scale, doc.getPageSize().getHeight() * scale);
    doc.add(image);
    doc.close();
    FileUtils.closeQuietly(fos);
}