Example usage for com.itextpdf.text FontFactory TIMES_BOLD

List of usage examples for com.itextpdf.text FontFactory TIMES_BOLD

Introduction

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

Prototype

String TIMES_BOLD

To view the source code for com.itextpdf.text FontFactory TIMES_BOLD.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:Gui.admin.NouveauConsulterinfoAdherent.java

private void RapportBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RapportBouttonActionPerformed

        String value1 = idadherenttxt.getText();
        String value2 = nomadherentTxt.getText();
        String value3 = prenomAdhrentTxt.getText();
        String value4 = adresseAdherentTxt.getText();
        String value5 = mdpAdherentTXT.getText();
        String value6 = telAdherentTXT.getText();
        String value7 = nbrReclamationsTxt.getText();

        try {/*from www  .  ja v a 2s.co m*/
            // pagesize.A4.rotate() pour voir le rapport dans IDE 
            com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

            if ((new File("rapport.pdf")).exists()) {

                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler rapport.pdf");
                p.waitFor();

            } else {

                System.out.println("File is not exists");

            }

            document.open();
            // Date
            document.add(new Paragraph(new Date().toString()));
            document.add(new Paragraph("Rapport Statistiques",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
            document.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------------------------------------------------------------------------------"));

            // ajoute un tableau dans le rapport 

            //                  PdfPTable table = new PdfPTable(4);
            //                  
            //                   PdfPCell cell = new PdfPCell(new Paragraph("Informations Adhrents"));
            //                     // le titre du tableau 
            //                  cell.setColspan(10);
            //                  cell.setBackgroundColor(BaseColor.GREEN);
            //                  table.addCell(cell);

            //                  table.addCell("Id Adhrent");
            //                  table.addCell("Nom de l'adhrent");
            //                  table.addCell("Prnom de l'adhrent");
            //                  table.addCell("Numro de l'adhrent");
            //                  document.add(table);
            // le titre du tableau 

            // ajouter l'image dans le fichier pdf 
            Image image = Image.getInstance("statistiques.png");
            document.add(new Paragraph("statistiques.png"));
            document.add(image);

            // document.add(new Paragraph("Salut sindoud", FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD, BaseColor.BLUE)));

            //document.add(new Paragraph (new Date().toString()));

            PdfPTable table = new PdfPTable(6);
            PdfPCell cell = new PdfPCell(new Paragraph("Titre"));
            cell.setColspan(4);
            //  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.GREEN);
            table.addCell("id de l'adherent");
            table.addCell(value1);
            table.addCell("Nom de l'adhrent");
            table.addCell(value2);
            table.addCell("Prnom de l'adhrent");
            table.addCell(value3);
            table.addCell("adresse de l'adhrent");
            table.addCell(value4);
            table.addCell("mot de passe de l'adherent");
            table.addCell(value5);
            table.addCell("tel de l'adherent ");
            table.addCell(value6);
            table.addCell("nombre de reclamations");
            table.addCell(value7);

            document.add(table);

            document.close();
            //com.itextpdf.text.Image image1= com.itextpdf.text.Image.getInstance("statistiques.png");
            // image1.scaleAbsolute(400,300);
            //document.add(image1);
            //PdfContentByte cb= writer.getDirectContent();
            JOptionPane.showMessageDialog(null, "rapport enregistr");
        }

        catch (DocumentException | IOException | InterruptedException | HeadlessException e) {

            JOptionPane.showMessageDialog(null, e);

        }
        //
    }

From source file:GUI.FrameUserPanier.java

private void BtnValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnValiderActionPerformed

    jLabel8.setText("" + CalculSomme());

    String val1 = TFidpan.getText();
    String val2 = TFnomut.getText();
    String val3 = TFNomprod.getText();
    String val4 = TFnombreprod.getText();
    String val5 = TFdescription.getText();
    try {/*from   w  ww.j a v a  2s .  c o  m*/

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
        document.open();
        document.add(new Paragraph("VotrePanier",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLUE)));
        document.add(new Paragraph(new Date().toString()));
        PdfPTable table = new PdfPTable(5);

        PdfPCell cell = new PdfPCell(new Paragraph("Mes achats"));

        cell.setColspan(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.BLUE);
        table.addCell(cell);

        table.addCell("IdPanier");
        table.addCell("NomUtilsateur");
        table.addCell("Nomprod");
        table.addCell("Nombreprod");
        table.addCell("Description");
        cell.setBackgroundColor(BaseColor.BLUE);

        int i = TablePanier.getRowCount();
        TableModel model = TablePanier.getModel();

        for (int j = 0; j < i; j++) {
            val1 = model.getValueAt(j, 0).toString();
            val2 = model.getValueAt(j, 2).toString();
            val3 = model.getValueAt(j, 4).toString();
            val4 = model.getValueAt(j, 5).toString();
            val5 = model.getValueAt(j, 6).toString();

            table.addCell(val1);
            table.addCell(val2);
            table.addCell(val3);
            table.addCell(val4);
            table.addCell(val5);

        }
        int z = TablePanier.getRowCount();
        model = TablePanier.getModel();
        float sum = 0;
        int bonus = 0;
        float net = 0;
        for (int j = 0; j < z; j++) {
            String x = model.getValueAt(j, 3).toString();
            int idprod = Integer.parseInt(x);
            String q = model.getValueAt(j, 5).toString();
            int qu = Integer.parseInt(q);
            Produit p = pdao.findByprodId(idprod);
            sum += p.getPrix() * qu;
            bonus += (p.getPtbonus() * qu);
            net += sum - (p.getReduction() * qu);
        }

        table.addCell("Somme: " + sum);
        table.addCell("");

        table.addCell("Net: " + net);
        table.addCell("");
        table.addCell("Bonus :" + bonus);

        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Report Saved");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:jfx_horario.jefatura.JefaturaController.java

private void crearPdf(File fichero, int opcion) {
    // mtodo para generar un pdf
    try {/*from   ww w.j  a v  a 2  s .  c  o  m*/
        OutputStream file = new FileOutputStream(fichero);
        Document document = new Document();
        PdfWriter.getInstance(document, file);
        document.open();
        Font titleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, 18, BaseColor.BLACK);
        Paragraph docTitle = new Paragraph((String) comboProfes.getSelectionModel().getSelectedItem(),
                titleFont);
        document.add(docTitle);
        Font textH1 = FontFactory.getFont(FontFactory.TIMES_ITALIC, 14, BaseColor.BLACK);
        switch (opcion) {
        case 0:
            crearTablaEnPDF(document, textH1);
            break;
        case 1:
            crearListaClasesDiariasPDF(document, textH1);
            break;
        case 2:
            crearTablaEnPDF(document, textH1);
            crearListaClasesDiariasPDF(document, textH1);
            break;
        }
        document.close();
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:login.DigiHoInitial.java

private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton21ActionPerformed
    // TODO add your handling code here:
    Calendar timer = Calendar.getInstance();
    timer.getTime();//from  ww  w.  jav a 2  s  .co  m
    SimpleDateFormat Tdate = new SimpleDateFormat("dd-MMM-yyy");
    jTextField17.setText(Tdate.format(timer.getTime()));
    jLabel15.setText("");
    Random rand = new Random();
    int number, number1;
    number = rand.nextInt(8999);
    number1 = 1000 + number;

    jTextField11.setText(jTextField11.getText() + number1);

    Document doc = new Document();
    try {
        PdfWriter.getInstance(doc,
                new FileOutputStream("f:\\DiGiho\\Registration Form\\" + jTextField11.getText() + ".pdf"));
        doc.open();
        Paragraph para = new Paragraph();
        doc.add(new Paragraph("\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
        doc.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n"));
        doc.add(new Phrase("Customer ID         "));
        doc.add(new Phrase(jTextField11.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                                    Date          "
                + jTextField17.getText() + "   \n\n"));
        doc.add(new Phrase("Name:-                   "));
        doc.add(new Phrase(jTextField5.getText() + ". " + jTextField6.getText() + " " + jTextField1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nFather's Name:-     "));
        doc.add(new Phrase(jTextField2.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nAddress                "));
        doc.add(new Phrase(jTextField3.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nBlock                    "));
        doc.add(new Phrase(jTextField16.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                           District                  "));
        doc.add(new Phrase(jTextField10.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nCity                       "));
        doc.add(new Phrase(jTextField15.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                                Pin Code                  "));
        doc.add(new Phrase(jTextField9.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase());
        doc.add(new Phrase("\nState                    "));
        doc.add(new Phrase(jTextField14.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                                   Date of Birth             "));
        doc.add(new Phrase(jTextField12.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nMoblie No.           "));
        doc.add(new Phrase(jTextField7.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("                                         Phone No.                 "));
        doc.add(new Phrase(jTextField13.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase());
        doc.add(new Phrase("\nEmail address          "));
        doc.add(new Phrase(jTextField8.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\nOccupation:          "));
        doc.add(new Phrase(a, FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(para);
        doc.add(new Phrase(
                "          \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n                         "
                        + jTextField6.getText() + "  " + jTextField1.getText()));
        doc.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DigiHoInitial.class.getName()).log(Level.SEVERE, null, ex);
    }
    JOptionPane.showMessageDialog(null, "File has been created", "deeps message", JOptionPane.PLAIN_MESSAGE);

}

From source file:login.DigiHoInitial.java

private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton22ActionPerformed
    // TODO add your handling code here:
    Document doc = new Document();
    try {//w w w  .j  av a2  s .co m
        PdfWriter.getInstance(doc,
                new FileOutputStream("F:\\DiGiho\\Customer Recipt\\" + jTextField11.getText() + ".pdf"));
        doc.open();
        doc.add(new Phrase("\n\n\n\n\n\n\n"));
        doc.add(new Phrase(
                "                                                                                                              Date:"));
        doc.add(new Phrase(jTextField17.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\n\n\n           Customer ID.:      "));
        doc.add(new Phrase(jTextField11.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));

        doc.add(new Phrase("\n           Name:                 "));
        doc.add(new Phrase(jTextField5.getText() + "  " + jTextField6.getText() + "  " + jTextField1.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\n           Father's Name:   "));
        doc.add(new Phrase(jTextField2.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\n           Address:             "));
        doc.add(new Phrase(
                jTextField3.getText() + "  " + jTextField16.getText() + "  " + jTextField10.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\n           Mobile:                "));
        doc.add(new Phrase(jTextField7.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.add(new Phrase("\n           Email ID.:            "));
        doc.add(new Phrase(jTextField8.getText(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, BaseColor.BLACK)));
        doc.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DigiHoInitial.class.getName()).log(Level.SEVERE, null, ex);
    }
    JOptionPane.showMessageDialog(null, "Recipt has been created", "deeps message",
            JOptionPane.INFORMATION_MESSAGE);
}

From source file:ManagementPackage.ServiceEnd.java

private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed
    // TODO add your handling code here:
    Document doc = new Document();
    try {//w w w. j  av a2  s .  co m
        long time = new Date().getTime();
        TransNo = "" + time;
        PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10)));
        cell3.setColspan(2);
        cell3.setPaddingBottom(10);
        cell3.setPaddingTop(10);
        cell3.setBorder(2);
        cell3.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell3);

        PdfPCell cell4 = new PdfPCell(
                new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10)));
        cell4.setColspan(3);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        //table.addCell("Sl No");
        table.addCell("Product Name");
        table.addCell("Rate");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                //String sl_no = rs.getString("sl_no");
                String product_name = rs.getString("product_name");
                String rate = rs.getString("rate");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");

                //table.addCell(sl_no);
                table.addCell(product_name);
                table.addCell(rate);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);
            }
            rs.close();
            pst.close();

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

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText()));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText()));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user));
        celltxtTotalPaid.setColspan(2);
        //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid0.setColspan(1);
        celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid0);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText()));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        savePermanently();
        clearTempTable();
        //JOptionPane.showMessageDialog(null, "Report Created!");

        // open PDF file
        File file = new File("Invoices\\Invoices" + time + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

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

From source file:ManagementPackage.Setting.java

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    // TODO add your handling code here:
    totalAdjustment = 0;/*www.  j av a 2 s .c  o m*/
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc, new FileOutputStream("Reports\\Daily" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Daily Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date = '"
                + formatedDate + "'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

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

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Daily" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

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

From source file:ManagementPackage.Setting.java

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

    // TODO add your handling code here:
    totalAdjustment = 0;//from   w ww  . j  a v  a 2 s .  c om
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc,
                new FileOutputStream("Reports\\Monthly" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Monthly Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%"
                + month + "%'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

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

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Monthly" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

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

From source file:ManagementPackage.Setting.java

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed

    // TODO add your handling code here:
    totalAdjustment = 0;//from  w ww  . j a  v  a  2  s. co  m
    totalTotalPaid = 0;
    total = 0;

    Document doc = new Document();
    try {
        long time = new Date().getTime();
        PdfWriter.getInstance(doc,
                new FileOutputStream("Reports\\Yearly" + time + " " + formatedDate + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(5);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Yearly Report\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell4 = new PdfPCell(new Paragraph("Date: " + formatedDateTime));
        cell4.setColspan(10);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        table.addCell("Transaction No");
        table.addCell("Billed By");
        table.addCell("Product Name");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String PrevTransNo = " ";
        String query = "select trans_no, product_name, qty, amount, trans_by from trans_details where date like '%"
                + year + "%'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                String NewTransNo = rs.getString("trans_no");
                String product_name = rs.getString("product_name");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");
                String trans_by = rs.getString("trans_by");

                total = total + Float.parseFloat(amount);

                if (PrevTransNo.equals(NewTransNo))
                    table.addCell(" ");
                else {
                    table.addCell(NewTransNo);
                    String query1 = "select adjustment, total_paid from paid_amount where trans_no = '"
                            + NewTransNo + "'";
                    pst1 = con1.prepareStatement(query1);
                    rs1 = pst1.executeQuery();
                    String adjustment = rs1.getString("adjustment");
                    String total_paid = rs1.getString("total_paid");

                    totalAdjustment = totalAdjustment + Float.parseFloat(adjustment);
                    totalTotalPaid = totalTotalPaid + Float.parseFloat(total_paid);

                    rs1.close();
                    pst1.close();
                }

                PrevTransNo = rs.getString("trans_no");
                table.addCell(trans_by);
                table.addCell(product_name);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);

            }
            rs.close();
            pst.close();

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

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph("" + total));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph("" + totalAdjustment));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid.setColspan(3);
        celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph("" + totalTotalPaid));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        //JOptionPane.showMessageDialog(null, "Report Created!");
        // open PDF file
        File file = new File("Reports\\Yearly" + time + " " + formatedDate + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

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

From source file:Measurment_Result_Record.MeasurmentSetup.java

private void jMenuItem_exportpdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_exportpdfActionPerformed
    // TODO add your handling code here:
    // TODO add your handling code here:
    try {/*from www  .j  ava  2s .co m*/
        // TODO add your handling code here:
        JFileChooser fchooser = new JFileChooser();
        int status = fchooser.showSaveDialog(null);
        if (status != JFileChooser.APPROVE_OPTION)
            return;
        fchooser.setDialogTitle("Save the Measurment result to pdf.");
        File selectedF = fchooser.getSelectedFile();
        String filename = selectedF.getAbsolutePath();
        //get the file path to save the pdf
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));
        document.open();
        //add the IPELS logo and title
        int size = 30;
        com.itextpdf.text.Font titleFont;
        titleFont = FontFactory.getFont(FontFactory.TIMES_BOLD, size, com.itextpdf.text.Font.BOLD,
                BaseColor.BLUE);
        Paragraph ipels = new Paragraph("IPELS", titleFont);
        ipels.setAlignment(Element.ALIGN_CENTER);

        document.add(ipels);
        titleFont.setSize(25);
        Paragraph para = new Paragraph("Measurment result \n ", titleFont);
        para.setAlignment(Element.ALIGN_CENTER);
        document.add(para);

        //loop through all the measurmentsetups tables and add each of them to the document
        for (MeasurmentSetup mesSetup : this.presenter.allMeasurmentSetups) {
            addResultTablesTotheDocument(document, mesSetup.recordTablePreview, mesSetup.getMeasurmentTitle());
        }

        //close the document
        document.close();
        //preview the document
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filename + ".pdf");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE);
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Save to pdf", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "opening pdf", JOptionPane.ERROR_MESSAGE);
    }
}