Example usage for com.itextpdf.text Document setPageSize

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

Introduction

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

Prototype


public boolean setPageSize(Rectangle pageSize) 

Source Link

Document

Sets the pagesize.

Usage

From source file:ExternalNonFormClasses.PDFEnator.java

public void createProfilePDF(String id, ArrayList<String> data) {
    this.data_title = "Citizen Profile";
    this.table = null;
    this.caller = 4;
    this.row = 17;
    this.column = 2;
    this.personID = id;
    this.totalDataSize = row * column;
    tableHeaderData = new ArrayList<>();
    tableHeaderData.add("Label");
    tableHeaderData.add("Information");

    ArrayList<String> dataAll = data;

    try {/*from  w ww  . j  ava 2s .  co  m*/
        getHeader();
        Document doc = new Document();
        PdfWriter writer = PdfWriter.getInstance(doc,
                new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf"));
        Rectangle one = new Rectangle(PageSize.LETTER);
        doc.setPageSize(one);
        //doc.setMargins(1, 1, 1, 1);
        doc.open();
        PdfContentByte canvas = writer.getDirectContent();
        Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11);
        x = one.getWidth();
        y = one.getHeight();
        tableX = (x / 2) - 235;
        tableY = y - 180;

        Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font);
        para.setAlignment(Element.ALIGN_CENTER);
        doc.add(para);
        Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font);
        para2.setAlignment(Element.ALIGN_CENTER);
        doc.add(para2);
        Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font);
        para3.setAlignment(Element.ALIGN_CENTER);
        doc.add(para3);
        Paragraph para4 = new Paragraph(data_title, font);
        para4.setAlignment(Element.ALIGN_CENTER);
        doc.add(para4);

        PdfPTable pdftable;
        pdftable = writeHeaders(font);
        int counter = 1, rowCounter = 0, columnCounter = 0;
        int yIncrementor = 16;
        String label = null, value = null;
        System.out.println(dataAll.size());
        while (counter <= this.row) {
            switch (counter - 1) {
            case 0:
                label = "Citizen ID";
                value = id;
                break;
            case 1:
                label = "Last Name";
                value = dataAll.get(counter - 2);
                break;
            case 2:
                label = "First Name";
                value = dataAll.get(counter - 2);
                break;
            case 3:
                label = "Middle Name";
                value = dataAll.get(counter - 2);
                break;
            case 4:
                label = "Name Suffix";
                value = dataAll.get(counter - 2);
                break;
            case 5:
                label = "Date of Birth";
                value = dataAll.get(counter - 2);
                break;
            case 6:
                label = "Gender";
                value = dataAll.get(counter - 2);
                break;
            case 7:
                label = "Address";
                value = dataAll.get(counter - 2);
                break;
            case 8:
                label = "Age";
                value = dataAll.get(counter - 2);
                break;
            case 9:
                label = "Place of Birth";
                value = dataAll.get(counter - 2);
                break;
            case 10:
                label = "Civil Status";
                value = dataAll.get(counter - 2);
                break;
            case 11:
                label = "Contact";
                value = dataAll.get(counter - 2);
                break;
            case 12:
                label = "Zip Code";
                value = dataAll.get(counter - 2);
                break;
            case 13:
                label = "Precinct Number";
                value = dataAll.get(counter - 2);
                break;
            case 14:
                label = "Occupation";
                value = dataAll.get(counter - 2);
                break;
            case 15:
                label = "Email Address";
                value = dataAll.get(counter - 2);
                break;
            case 16:
                label = "Religion";
                value = dataAll.get(counter - 2);
                break;
            }
            if (value.length() <= 0) {
                value = "N/A";
            }

            System.out.println(label + ": " + value);
            PdfPCell cell1 = new PdfPCell(new Paragraph(label, font));
            cell1.setPaddingBottom(5);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            pdftable.addCell(cell1);

            PdfPCell cell2 = new PdfPCell(new Paragraph(value, font));
            cell2.setPaddingBottom(5);
            cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
            pdftable.addCell(cell2);

            if (counter > 0 && (counter % column) == 0) { //if there are 4 columns
                yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus
                rowCounter++; //move to next row
                columnCounter = 0; //back to start column
                boolean newPage = false;

                if ((tableY - ((yIncrementor - 16) + 80)) <= 72 || (tableY - (yIncrementor + 80)) <= 72) { //if it exceeds 1 inch in footer, new page
                    newPage = true;
                }

                if (newPage) {
                    pdftable.completeRow();
                    pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page
                    doc.newPage(); //create new page
                    pdftable = writeHeaders(font); //write headers to new page
                    yIncrementor = 16; //restore default
                }
            }
            counter++;
        }
        pdftable.completeRow();
        pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas);
        doc.close();

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

}

From source file:figtree.application.FigTreePDF.java

License:Open Source License

static public void createGraphic(int width, int height, String treeFileName, String graphicFileName) {

    try {//from ww  w  .j a v a  2s.  c  o  m
        BufferedReader bufferedReader = new BufferedReader(new FileReader(treeFileName));
        String line = bufferedReader.readLine();
        while (line != null && line.length() == 0) {
            line = bufferedReader.readLine();
        }

        bufferedReader.close();

        boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS"));

        Reader reader = new FileReader(treeFileName);

        Map<String, Object> settings = new HashMap<String, Object>();

        ExtendedTreeViewer treeViewer = new ExtendedTreeViewer();
        ControlPalette controlPalette = new BasicControlPalette(200,
                BasicControlPalette.DisplayMode.ONLY_ONE_OPEN);
        FigTreePanel figTreePanel = new FigTreePanel(null, treeViewer, controlPalette);

        // First of all, fully populate the settings map so that
        // all the settings have defaults
        controlPalette.getSettings(settings);

        List<Tree> trees = new ArrayList<Tree>();

        if (isNexus) {
            FigTreeNexusImporter importer = new FigTreeNexusImporter(reader);
            trees.add(importer.importNextTree());

            // Try to find a figtree block and if found, parse the settings
            while (true) {
                try {
                    importer.findNextBlock();
                    if (importer.getNextBlockName().equalsIgnoreCase("FIGTREE")) {
                        importer.parseFigTreeBlock(settings);
                    }
                } catch (EOFException ex) {
                    break;
                }
            }
        } else {
            NewickImporter importer = new NewickImporter(reader, true);
            trees.add(importer.importNextTree());
        }

        if (trees.size() == 0) {
            throw new ImportException("This file contained no trees.");
        }

        treeViewer.setTrees(trees);

        controlPalette.setSettings(settings);

        treeViewer.getContentPane().setSize(width, height);

        OutputStream stream;
        if (graphicFileName != null) {
            stream = new FileOutputStream(graphicFileName);
        } else {
            stream = System.out;
        }

        Document document = new Document();
        document.setPageSize(new com.itextpdf.text.Rectangle(width, height));
        try {
            PdfWriter writer = PdfWriter.getInstance(document, stream);
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(width, height);
            Graphics2D g2 = tp.createGraphics(width, height);
            tp.setWidth(width);
            tp.setHeight(height);
            treeViewer.getContentPane().print(g2);
            g2.dispose();
            tp.sanityCheck(); // all the g2 content is written to tp, not cb
            cb.addTemplate(tp, 0, 0);
            cb.sanityCheck();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();

    } catch (ImportException ie) {
        throw new RuntimeException("Error writing graphic file: " + ie);
    } catch (IOException ioe) {
        throw new RuntimeException("Error writing graphic file: " + ioe);
    }

}

From source file:Forms.AddCustomers.java

private void cardBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cardBtnActionPerformed
    String name = fNameTxt.getText() + " " + lNameTxt.getText();
    String cid = cusIdTxt.getText();
    Document document = new Document();
    Rectangle test = new Rectangle(350, 200);
    BaseColor color = new BaseColor(63, 72, 204);
    test.setBackgroundColor(color);//w  ww.  ja v  a  2  s.  c  om
    document.setPageSize(test);

    File theDir = new File("E:\\CustomerCard");

    // if the directory does not exist, create it
    if (!theDir.exists()) {
        //System.out.println("creating directory: " + directoryName);
        boolean result = false;

        try {
            theDir.mkdir();
            result = true;
        } catch (SecurityException se) {
            System.out.println(se.getMessage());
        }
    }

    try {
        PdfWriter.getInstance(document, new FileOutputStream("E:\\CustomerCard\\card(" + cid + ").pdf"));

        document.open();
        //Image image;

        //image = Image.getInstance("api.png");

        //document.add(image);

        document.add(new Paragraph("           Customer Discount Card",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD, BaseColor.GRAY)));
        document.add(new Paragraph("     "));
        document.add(new Paragraph("              Name : " + name,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK)));
        document.add(new Paragraph("     "));
        document.add(new Paragraph("              Card ID: " + cid,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK)));
        document.close();

        try {
            //Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+"E:\\CustomerCard\\card("+cid+").pdf");
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "
                    + "C:\\Users\\Vidu\\Desktop\\CustomerIDCard\\card(" + cid + ").pdf");
        } catch (Exception ex) {
            Logger.getLogger(SellPage.class.getName()).log(Level.SEVERE, null, ex);
        }
        //document.add(new Paragraph(date,FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL,BaseColor.BLACK)));
        fNameTxt.setText("");
        lNameTxt.setText("");
        cusIdTxt.setText("");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Forms.SellPage.java

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

    CashType c = new CashType();
    c.setVisible(true);//from  ww  w. ja v a2s . c  om

    c.jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            String receive = c.jTextField1.getText();
            if (receive.equalsIgnoreCase("")) {
                JOptionPane.showMessageDialog(null, "Enter Amount");
            } else if (!receive.matches("[0-9]+")) {
                JOptionPane.showMessageDialog(null, "Enter Valid Amount");
                c.jTextField1.setText("");
            } else {
                float rec = Float.parseFloat(receive);
                //create sell
                String b = "sellno" + jTextField3.getText();

                if (CreatingSell(b)) {
                    System.out.println("Success is final");
                }

                ///code for updatng solddtime

                if (new SoldTimeUpdater().getToday(b)) {
                    System.out.println("soldtime updated");
                }

                ////code for updating sold

                String sq = "SELECT * FROM " + b;

                try {

                    Connection con = (Connection) DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");
                    Statement s = (Statement) con.prepareStatement(sq);

                    ResultSet rs = s.executeQuery(sq);

                    while (rs.next()) {
                        String name = rs.getString(2);
                        String price = rs.getString(4);
                        String buy_price = rs.getString(7);
                        String type = rs.getString(8);
                        String qua = rs.getString(3);

                        if (new SellTable().SearchExistItem(name, price + "", "sold")) {

                            new SellTable().updateItem("sold", name, Float.parseFloat(price), qua);

                        }

                        else if (new SellTable().addItem("sold", name, Float.parseFloat(price), " 2%",
                                Float.parseFloat(buy_price), type, qua)) {

                        } else {
                            JOptionPane.showMessageDialog(null, "problem");
                        }
                    }

                } catch (Exception e) {

                }

                //code for invoice

                float a = 0;

                int length;
                String sql = "SELECT * FROM " + b;

                File theDir = new File("E:\\Recept");

                // if the directory does not exist, create it
                if (!theDir.exists()) {
                    //System.out.println("creating directory: " + directoryName);
                    boolean result = false;

                    try {
                        theDir.mkdir();
                        result = true;
                    } catch (SecurityException se) {
                        //handle it
                    }
                }

                try {

                    Connection con = (Connection) DriverManager
                            .getConnection("jdbc:mysql://localhost:3306/nafis", "root", "");
                    Statement s = (Statement) con.prepareStatement(sql);

                    ResultSet rs = s.executeQuery(sql);

                    Document document = new Document();

                    Rectangle test = new Rectangle(223, 380);
                    document.setPageSize(test);
                    PdfWriter.getInstance(document, new FileOutputStream("E:\\Recept\\" + b + ".pdf"));
                    document.open();
                    document.addCreationDate();
                    document.add(new Paragraph("                        INVOICE",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    //document.add(new Paragraph("--------------------------------------------------------",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));
                    document.add(new Paragraph("          " + new Date().toString(),
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("                      INVOICE NO:" + jTextField3.getText(),
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("Product                 Qty          Price         Total",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.UNDERLINE, BaseColor.BLACK)));
                    //document.add(new Paragraph("--------------------------------------------------------",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));

                    while (rs.next()) {
                        String name = rs.getString(2);
                        String qua = rs.getString(3);
                        String rate = rs.getString(4);
                        String amount = rs.getString(6);
                        a = a + Float.parseFloat(amount);
                        if (name.length() <= 25) {
                            length = name.length();
                        } else {
                            length = 25;
                        }
                        document.add(new Paragraph(name.substring(0, length),
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                        document.add(new Paragraph(
                                "                               " + qua + "             " + rate
                                        + "            " + amount + "",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                        //document.add(new Paragraph("                                        ",FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL,BaseColor.BLACK)));
                        //t.addCell(rate);
                        //t.addCell(amount);

                    }

                    //document.add(new Paragraph("                                   "));
                    //document.add(new Paragraph("                                   "));
                    document.add(new Paragraph("--------------------------------------------------------",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph(
                            "                                                Total=" + a + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    //document.add(new Paragraph("                                   "));
                    //document.add(new Paragraph("                                   "));
                    if (jTextField6.getText().equalsIgnoreCase("") == false) {
                        float dis = Float.parseFloat(jTextField6.getText());
                        a = a - ((a * dis) / 100);

                        document.add(new Paragraph(
                                "Customer ID =" + jTextField4.getText() + "  After Discount=" + a + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    }
                    if (jTextField8.getText().equalsIgnoreCase("") == false) {
                        float dis = Float.parseFloat(jTextField8.getText());
                        a = a - ((a * dis) / 100);

                        document.add(new Paragraph(
                                "Discount =" + jTextField8.getText() + "%    After Discount=" + a + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    }

                    if (jTextField7.getText().equalsIgnoreCase("") == false) {
                        float vat = Float.parseFloat(jTextField7.getText());
                        float v = (a * vat) / 100;
                        a = a + ((a * vat) / 100);

                        document.add(new Paragraph(
                                "Vat =" + jTextField7.getText() + "%               Vat=" + v + "tk",
                                FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    }
                    document.add(new Paragraph("                                     Net Amount=" + a + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("                              Receive Amount=" + rec + "tk",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph(
                            "                             Returned Amount=" + (rec - a) + "tk     ",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    document.add(new Paragraph("         Goods Once Sold Can not be Return",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("--------------------------------------------------------",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));
                    document.add(new Paragraph("             Unity Point Of Sales System",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)));

                    document.close();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "problem in memoo");
                }

                ///////////////////////////
                //to open pdf invoice
                try {

                    Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler " + "E:\\Recept\\" + b + ".pdf");
                } catch (IOException ex) {
                    Logger.getLogger(SellPage.class.getName()).log(Level.SEVERE, null, ex);
                }

                ////update todaySell

                Date dNow = new Date();

                SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");

                String date = "" + ft.format(dNow);

                if (new updatingTodaySell().checkdate(date)) {

                    System.out.println("updating");
                    String read = "SELECT * FROM " + b;

                    try {

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

                        Statement s = (Statement) con.prepareStatement(read);

                        ResultSet rs = s.executeQuery(read);

                        while (rs.next()) {

                            String name = rs.getString(2);
                            String price = rs.getString(4);
                            String buy_price = rs.getString(7);
                            String type = rs.getString(8);
                            String qua = rs.getString(3);

                            if (new updatingTodaySell().searchtodaysell(name, buy_price)) {

                                System.out.println(qua);
                                new updatingTodaySell().update(name, qua, buy_price, date);
                                System.out.println("update done");
                            } else {

                                new updatingTodaySell().add(name, qua, price, buy_price, type, date);

                            }

                        }

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

                } else {

                    String sqldrop = "DELETE FROM `todaysell` WHERE 1";

                    try {

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

                        Statement s = (Statement) con.prepareStatement(sqldrop);

                        s.execute(sqldrop);

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

                    String adddate = "INSERT INTO `todaysell`(`no`, `name`, `quantity`, `price`, `buyprice`, `type`, `date`) VALUES (NULL,'a','0','0','0','NULL','"
                            + date + "')";

                    try {

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

                        Statement s = (Statement) con.prepareStatement(adddate);

                        s.execute(adddate);

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

                    String read = "SELECT * FROM " + b;

                    try {

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

                        Statement s = (Statement) con.prepareStatement(read);

                        ResultSet rs = s.executeQuery(read);

                        while (rs.next()) {

                            String name = rs.getString(2);
                            String price = rs.getString(4);
                            String buy_price = rs.getString(7);
                            String type = rs.getString(8);
                            String qua = rs.getString(3);

                            new updatingTodaySell().add(name, qua, price, buy_price, type, date);
                        }

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

                }

                //droping previous sell
                int num = Integer.parseInt(jTextField3.getText());
                String ab = "sellno" + num;

                String sql1 = "SELECT * FROM information_schema.tables WHERE table_schema = 'nafis' AND table_name = '"
                        + ab + "' LIMIT 1";

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

                    Statement s = (Statement) con.prepareStatement(sql1);

                    ResultSet rs = s.executeQuery(sql1);

                    if (rs.next()) {
                        if (new SellTable().dropTable(ab)) {

                            System.out.println("droped table " + ab);
                        } else {
                            JOptionPane.showMessageDialog(null, "problem cancelling");
                        }

                    }

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

                //To update the number of sellno in db

                new SellTable().updateSellNumber();
                sellno = new SellTable().getSellNumber();
                //To show sellno in frame
                jTextField3.setText(sellno + 1 + "");

                new SellTable().createtable("sellno" + jTextField3.getText());
                retreve();

                retreve("sellno" + jTextField3.getText());

                //

                ///clear discount
                jLabel12.setText("");
                jTextField4.setText("");
                jTextField5.setText("");
                jTextField6.setText("");
                jTextField2.setText("");

                c.dispose();

            }

        }

        private void matches(String string) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

    });

}

From source file:frames.main.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
    if (PRINTMODE.getSelectedIndex() == 0) {
        try {/*from   ww w. j a  va  2s.c  o  m*/

            //mrpno=Integer.parseInt(DTFrpno.getText());
            BaseFont unicode = BaseFont.createFont("c:/windows/fonts/ALGER.ttf", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            Font font1003 = new Font(unicode, 18, Font.ITALIC, new BaseColor(139, 0, 0));
            Font font1008 = new Font(unicode, 20, Font.BOLD, new BaseColor(101, 67, 33));
            Font font1004 = new Font(unicode, 14, Font.BOLD, new BaseColor(139, 0, 0));
            Font font1005 = new Font(unicode, 12, Font.UNDERLINE, new BaseColor(255, 0, 0));
            Font font1006 = new Font(unicode, 9, Font.BOLDITALIC, new BaseColor(101, 67, 33));
            Rectangle rect = new RectangleReadOnly(590, 470, 0);
            /////////////////////////////////////
            Font font100 = new Font(unicode, 10, Font.ITALIC, BaseColor.BLUE);
            Document document = new Document();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("REGISTRATION.pdf"));
            document.setPageSize(rect);
            document.open();
            // PdfContentByte cb = writer.getDirectContent();
            Font font111 = new Font(Font.FontFamily.COURIER, 16, Font.BOLD, BaseColor.ORANGE);
            com.itextpdf.text.Image image2 = com.itextpdf.text.Image
                    .getInstance("C:\\smart kid\\src\\frames\\logo.jpg");
            image2.scaleAbsolute(115f, 115f);
            image2.setAbsolutePosition(2, 350);
            document.add(image2);
            document.add(new Chunk(
                    "                                                                                         ",
                    font100));
            document.add(new Chunk("RECEIPT", font1005));
            //document.add(p);
            // document.add(new Paragraph( ));
            document.add(new Paragraph(
                    "                                  SMART KID CONVENT SCHOOL                 ", font1003));
            // document.add(new Chunk("                          SMART KID CONVENT SCHOOL                 ",font1003));
            // document.add(new Chunk("                                                              413A/23,HEERA NAGAR GURGAON.                        ",font100));
            document.add(new Paragraph(
                    "                                                                  413A/23,HEERA NAGAR GURGAON.                        ",
                    font100));
            // document.add(new Chunk("                                                                                            ph:9911752900,9891929835                 ",font100));
            document.add(new Paragraph(
                    "                                                                     ph:9911752900,9891929835                 ",
                    font100));
            // document.add(new Chunk("                                                          E-mail:info.smartkids@gmail.com",FontFactory.getFont(FontFactory.COURIER,9,Font.BOLDITALIC,BaseColor.DARK_GRAY)));
            document.add(new Paragraph("                                  E-mail:info.smartkids@gmail.com",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLDITALIC, BaseColor.DARK_GRAY)));

            document.add(new Paragraph("  "));
            PdfPTable table1 = new PdfPTable(4);
            PdfPCell c = new PdfPCell(new Paragraph("STUDENT PARTICULARS"));
            c.setColspan(4);
            c.setBackgroundColor(BaseColor.GREEN);
            c.setHorizontalAlignment(Element.ALIGN_CENTER);
            table1.addCell(c);
            table1.addCell("Student Name:");
            table1.addCell(new PdfPCell(new Paragraph(Dtf2.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN))));

            table1.addCell("Class:");
            table1.addCell(new Paragraph((String) Dtf5.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            table1.addCell("Section:");
            table1.addCell(new Paragraph((String) Dtf22.getText() + "     " + "Phone.:" + Dtf20.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            table1.addCell("Registration No:");
            table1.addCell(new PdfPCell(new Paragraph(Dtf1.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN))));
            table1.addCell("Session:");
            table1.addCell(new Paragraph("NA",
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            table1.addCell("Month:");
            table1.addCell(new Paragraph((String) Djc1.getSelectedItem(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            float[] ColumnWidths1 = new float[] { 12f, 19f, 10f, 24f };
            table1.setWidths(ColumnWidths1);
            table1.setWidthPercentage(113);
            document.add(table1);

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

            PdfPTable table = new PdfPTable(5);
            PdfPCell cc = new PdfPCell(new Paragraph("FEE INFORMATION"));
            cc.setBackgroundColor(BaseColor.GREEN);
            cc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cc.setColspan(5);
            table.addCell(cc);
            PdfPCell cell99 = new PdfPCell(new Paragraph("Sl No",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell90 = new PdfPCell(new Paragraph("Particulars",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell91 = new PdfPCell(new Paragraph("Cash",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell92 = new PdfPCell(new Paragraph("Cheque",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell93 = new PdfPCell(new Paragraph("Total",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell99);
            table.addCell(cell90);
            table.addCell(cell91);
            table.addCell(cell92);
            table.addCell(cell93);
            table.addCell("1");
            PdfPCell cell1 = new PdfPCell(new Paragraph("Registration Fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell1);
            table.addCell(Dtf11.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("2");
            PdfPCell cell2 = new PdfPCell(new Paragraph("Admission/Re admission fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell2);
            table.addCell(Dtf12.getText());
            table.addCell("  ");
            table.addCell(" ");
            table.addCell("3");
            PdfPCell cell3 = new PdfPCell(new Paragraph("Building fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell3);
            table.addCell(Dtf13.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("4");
            PdfPCell cell4 = new PdfPCell(new Paragraph("Annual Charge",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell4);
            table.addCell(Dtf14.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("5");
            PdfPCell cell14 = new PdfPCell(new Paragraph("Security (Refundable)",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell14);
            table.addCell(Dtf17.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("6");
            PdfPCell cell5 = new PdfPCell(new Paragraph("Tution",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell5);
            table.addCell(Dtf6.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("7");
            PdfPCell cell6 = new PdfPCell(new Paragraph("Total pupils fund",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell6);
            table.addCell(Dtf16.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("8");
            PdfPCell cell7 = new PdfPCell(new Paragraph("Computer Fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell7);
            table.addCell(Dtf7.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("9");
            PdfPCell cell8 = new PdfPCell(new Paragraph("Sports Fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell8);
            table.addCell(Dtf15.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("10");
            PdfPCell cell9 = new PdfPCell(new Paragraph("House exam Fee",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell9);
            table.addCell(Dtf8.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("11");
            PdfPCell cell10 = new PdfPCell(new Paragraph("Conveyance Charge",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell10);
            table.addCell(Dtf18.getText());
            table.addCell(" ");
            //table.addCell(" ");
            table.addCell("");
            PdfPCell cell12 = new PdfPCell(new Paragraph("12",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLD, BaseColor.BLACK)));
            PdfPCell cell13 = new PdfPCell(new Paragraph("Grand Total",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLD, BaseColor.BLACK)));

            table.addCell(cell12);
            table.addCell(cell13);

            table.addCell(
                    String.valueOf((Integer.parseInt(Dtf11.getText())) + (Integer.parseInt(Dtf12.getText()))
                            + (Integer.parseInt(Dtf13.getText())) + (Integer.parseInt(Dtf14.getText()))
                            + (Integer.parseInt(Dtf17.getText())) + (Integer.parseInt(Dtf6.getText()))
                            + (Integer.parseInt(Dtf16.getText())) + (Integer.parseInt(Dtf7.getText()))
                            + (Integer.parseInt(Dtf15.getText())) + (Integer.parseInt(Dtf8.getText()))
                            + (Integer.parseInt(Dtf18.getText())) + (Integer.parseInt(Dtf9.getText()))));

            float[] ColumnWidths = new float[] { 8f, 25f, 11f, 10f, 10f };
            table.setWidths(ColumnWidths);
            table.setWidthPercentage(113);
            table.completeRow();
            document.add(table);
            document.add(new Chunk(
                    "# Fee once paid is not refundable .                      For Smart kid convent school     Signature    "));
            //document.add(new Chunk("# The monthly fee has to be deposited before 10th of every month                            Signature "));
            JOptionPane.showMessageDialog(this, "receipt printed..");

            Dtf21.setText(String.valueOf(Integer.parseInt(Dtf21.getText()) + 1));
            document.close();
            ;
        } catch (Exception ee) {
            JOptionPane.showMessageDialog(this, ee);
        }
    } else if (PRINTMODE.getSelectedIndex() == 1) {
        try {

            //mrpno=Integer.parseInt(DTFrpno.getText());
            BaseFont unicode = BaseFont.createFont("c:/windows/fonts/ALGER.ttf", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            Font font1003 = new Font(unicode, 18, Font.ITALIC, new BaseColor(139, 0, 0));
            Font font1008 = new Font(unicode, 20, Font.BOLD, new BaseColor(101, 67, 33));
            Font font1004 = new Font(unicode, 14, Font.BOLD, new BaseColor(139, 0, 0));
            Font font1005 = new Font(unicode, 12, Font.UNDERLINE, new BaseColor(255, 0, 0));
            Font font1006 = new Font(unicode, 9, Font.BOLDITALIC, new BaseColor(101, 67, 33));
            Rectangle rect = new RectangleReadOnly(590, 460, 0);
            /////////////////////////////////////
            Font font100 = new Font(unicode, 10, Font.ITALIC, BaseColor.BLUE);
            Document document = new Document();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Feeslipp(MONTHLY).pdf"));
            document.setPageSize(rect);
            document.open();
            // PdfContentByte cb = writer.getDirectContent();
            Font font111 = new Font(Font.FontFamily.COURIER, 16, Font.BOLD, BaseColor.ORANGE);
            com.itextpdf.text.Image image2 = com.itextpdf.text.Image
                    .getInstance("C:\\smart kid\\src\\frames\\logo.jpg");
            image2.scaleAbsolute(115f, 115f);
            image2.setAbsolutePosition(2, 350);
            document.add(image2);
            Paragraph p = new Paragraph();
            p.add(new Chunk("                                                                      "));
            //p.add(new Chunk("RECEIPT",font1005));
            //document.add(p);
            document.add(new Chunk("                  RECEIPT", font1003));
            document.add(new Paragraph("                             SMART KID CONVENT SCHOOL                 ",
                    font1003));
            // document.add(new Chunk("                          SMART KID CONVENT SCHOOL                 ",font1003));
            // document.add(new Chunk("                                                              413A/23,HEERA NAGAR GURGAON.                        ",font100));
            document.add(new Paragraph(
                    "                                                              413A/23,HEERA NAGAR GURGAON.                        ",
                    font100));
            // document.add(new Chunk("                                                                                            ph:9911752900,9891929835                 ",font100));
            document.add(new Paragraph(
                    "                                                                  ph:9911752900,9891929835                 ",
                    font100));
            // document.add(new Chunk("                                                          E-mail:info.smartkids@gmail.com",FontFactory.getFont(FontFactory.COURIER,9,Font.BOLDITALIC,BaseColor.DARK_GRAY)));
            document.add(new Paragraph("                                 E-mail:info.smartkids@gmail.com",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLDITALIC, BaseColor.DARK_GRAY)));
            document.add(new Paragraph("  "));
            PdfPTable table1 = new PdfPTable(4);
            PdfPCell c = new PdfPCell(new Paragraph("STUDENT PARTICULARS"));
            c.setColspan(4);
            c.setBackgroundColor(BaseColor.GREEN);
            c.setHorizontalAlignment(Element.ALIGN_CENTER);
            table1.addCell(c);
            table1.addCell("Student Name:");
            table1.addCell(new PdfPCell(new Paragraph(Dtf2.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN))));
            table1.addCell("Class:");
            table1.addCell(new Paragraph(Dtf5.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            table1.addCell("Section:");
            table1.addCell(new Paragraph(Dtf21.getText() + "     " + "Phone.:" + Dtf20.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            table1.addCell("Registration No:");
            table1.addCell(new PdfPCell(new Paragraph(Dtf1.getText(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN))));
            table1.addCell("Month:");
            table1.addCell(new Paragraph((String) Djc1.getSelectedItem(),
                    FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLDITALIC, BaseColor.GREEN)));
            float[] ColumnWidths1 = new float[] { 12f, 19f, 10f, 24f };
            table1.setWidths(ColumnWidths1);
            table1.setWidthPercentage(113);
            document.add(table1);

            document.add(new Paragraph("  "));
            PdfPTable table = new PdfPTable(5);
            PdfPCell cc = new PdfPCell(new Paragraph("FEE INFORMATION"));
            cc.setBackgroundColor(BaseColor.GREEN);
            cc.setHorizontalAlignment(Element.ALIGN_CENTER);
            cc.setColspan(5);
            table.addCell(cc);
            PdfPCell cell99 = new PdfPCell(new Paragraph("Sl No",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell90 = new PdfPCell(new Paragraph("Particulars",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell91 = new PdfPCell(new Paragraph("Cash",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell92 = new PdfPCell(new Paragraph("Cheque",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            PdfPCell cell93 = new PdfPCell(new Paragraph("Total",
                    FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell99);
            table.addCell(cell90);
            table.addCell(cell91);
            table.addCell(cell92);
            table.addCell(cell93);
            table.addCell("1");
            PdfPCell cell1 = new PdfPCell(new Paragraph("TUITION FEE",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell1);
            table.addCell(Dtf6.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("2");
            PdfPCell cell2 = new PdfPCell(new Paragraph("COMPUTER FEE",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell2);
            table.addCell(Dtf7.getText());
            table.addCell("  ");
            table.addCell(" ");
            table.addCell("3");
            PdfPCell cell5 = new PdfPCell(new Paragraph("HOUSE EXAM FEE",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell5);
            table.addCell(Dtf8.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("4");
            PdfPCell cell6 = new PdfPCell(new Paragraph("FINES",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell6);
            table.addCell(Dtf9.getText());
            table.addCell(" ");
            table.addCell(" ");
            table.addCell("5");
            PdfPCell cell7 = new PdfPCell(new Paragraph("OTHERS",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK)));
            table.addCell(cell7);
            table.addCell(Dtf10.getText());
            table.addCell(" ");

            table.addCell("");

            PdfPCell cell9 = new PdfPCell(new Paragraph("6",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLD, BaseColor.BLACK)));
            PdfPCell cell8 = new PdfPCell(new Paragraph("Grand Total",
                    FontFactory.getFont(FontFactory.COURIER, 9, Font.BOLD, BaseColor.BLACK)));

            table.addCell(cell7);
            table.addCell(cell8);
            table.addCell(String.valueOf((Integer.parseInt(Dtf6.getText())) + (Integer.parseInt(Dtf7.getText()))
                    + (Integer.parseInt(Dtf8.getText())) + (Integer.parseInt(Dtf9.getText()))
                    + (Integer.parseInt(Dtf10.getText()))));

            float[] ColumnWidths = new float[] { 8f, 25f, 11f, 10f, 10f };
            table.setWidths(ColumnWidths);
            table.setWidthPercentage(113);
            table.completeRow();
            document.add(table);
            document.add(new Chunk(
                    "# Fee once paid is not refundable .                                                   For smart kid convent School     "));
            document.add(new Chunk(
                    "# The monthly fee has to be deposited before 10th of every month                            Signature "));
            JOptionPane.showMessageDialog(this, "receipt printed..");

            Dtf21.setText(String.valueOf(Integer.parseInt(Dtf21.getText()) + 1));
            document.close();
            ;
        } catch (Exception ee) {
            JOptionPane.showMessageDialog(this, ee);
        }
    } // TODO add your handling code here:
}

From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java

@Override
public void enregistrerBulletin() {
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) {

        if (eleveAnneeClasse.getId() != null) {
            classematieres.clear();//from w w w. j  av  a2s.  com
            matieres.clear();
            notesPropres.clear();
            matiereCompses.clear();
            eleveAnneeClasse = eleveAnneeClasseFacade.find(eleveAnneeClasse.getId());
            if (sequence != null) {
                Annee an = anneeFacade.findByEtatSingle(true);
                Eleveanneeclasse eleveClasse = eleveAnneeClasseFacade.getEleveAnneeClaseByAnneClasse(
                        eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee());
                if (eleveClasse != null) {
                    List<Naturematiere> nature = natureMatiereFacade.findAll();
                    if (!nature.isEmpty()) {
                        List<Evaluation> notes = evaluationFacadeLocal.getByEleveAnneeSequence(
                                eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee(),
                                sequence.getIdsequencean());

                        /*if (!notes.isEmpty()) {*/
                        try {

                            String bulletinName = "" + eleveAnneeClasse.getEleve().getNom() + "_"
                                    + eleveAnneeClasse.getEleve().getPrenom() + "_"
                                    + sequence.getIdsequence().getNom() + ".pdf";
                            Document bulletin = new Document();

                            PdfWriter.getInstance(bulletin, new FileOutputStream(Utilitaires.path + "/"
                                    + Utilitaires.repertoireParDefautBulletin + "/" + bulletinName));

                            bulletin.setMargins(5, 5, 5, 5);
                            bulletin.addCreator("School Manager");
                            bulletin.setPageSize(PageSize.A4);

                            bulletin.open();

                            //tableau qui va contenir les notes
                            PdfPTable table = new PdfPTable(5);
                            table.setComplete(true);

                            //entete de bulletin
                            table.addCell(
                                    PrintUtils.createPdfPCell("COLLEGE POZAM Anne Scolaire " + an.getCode()
                                            + " - " + (an.getCode() + 1) + " " + an.getTheme(), 5, detail));
                            table.addCell(PrintUtils.createPdfPCell(
                                    "BULLETIN DE NOTES DE : " + sequence.getIdsequence().getNom(), 5, true));
                            table.addCell(PrintUtils
                                    .createPdfPCell("Nom : " + eleveAnneeClasse.getEleve().getNom(), 2, false));

                            PdfPCell cellLogo = new PdfPCell(new Paragraph("  "));
                            cellLogo.setRowspan(2);
                            table.addCell(cellLogo);

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Matricule : " + eleveAnneeClasse.getEleve().getMatricule(), 2, false));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Prnom : " + eleveAnneeClasse.getEleve().getPrenom(), 2, false));

                            //table.addCell("kenne");
                            PdfPCell cellClasse = new PdfPCell(
                                    new Paragraph("Classe : " + eleveClasse.getIdclasse().getNom()));
                            cellClasse.setColspan(2);
                            table.addCell(cellClasse);

                            //debut de saisis de notes
                            PdfPTable entete = new PdfPTable(5);
                            table.addCell(new Paragraph("Dicipline"));
                            table.addCell(PrintUtils.createPdfPCell("Note ", true));
                            table.addCell(PrintUtils.createPdfPCell("Cofficient ", true));
                            table.addCell(PrintUtils.createPdfPCell("Total", true));
                            table.addCell(PrintUtils.createPdfPCell("Apprciation", true));

                            //partie qui contient es totaux
                            PdfPTable total = new PdfPTable(5);

                            int totalCoef = 0;
                            float totalPoint = 0;

                            classematieres = classeMatiereFacade
                                    .get(eleveAnneeClasse.getIdclasse().getIdclasse());
                            if (!classematieres.isEmpty()) {
                                for (Classematiere m : classematieres) {
                                    matieres.add(m.getIdmatiere());
                                }

                                /*for (Evaluation e : notes) {
                                 if (matieres.contains(e.getIdmatiere())) {
                                 notesPropres.add(e);
                                 matiereCompses.add(e.getIdmatiere());
                                 }
                                 }*/
                                for (int i = 0; i < nature.size(); i++) {
                                    table.addCell(
                                            PrintUtils.createPdfPCell("Matires " + nature.get(i).getLibelle(),
                                                    5, false, PrintUtils.blueFont));

                                    int totalCoefBloc = 0;
                                    int totalPointBloc = 0;

                                    for (int a = 0; a < matieres.size(); a++) {

                                        if (matiereCompses.contains(matieres.get(a))) {
                                            //if (Objects.equals(notesPropres.get(a).getIdmatiere(), nature.get(i).getIdnaturematiere())) {;
                                            //decompte des coefficient et nombre point globaux
                                            //totalCoef += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            // totalPoint += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();

                                            //decompte des coef et point par groupe                                          
                                            //totalCoefBloc += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //totalPointBloc += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //                                                    table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getNote(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + (notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient()), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getObservation(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC)));
                                            // }
                                        } else {
                                            if (Objects.equals(
                                                    matieres.get(a).getIdnaturematiere().getIdnaturematiere(),
                                                    nature.get(i).getIdnaturematiere())) {
                                                //decompte des coefficient et nombre point globaux
                                                //                                                    totalCoef += matieres.get(a).get
                                                totalPoint += 0;
                                                //decompte des coef et point par groupe                                          
                                                //                                                    totalCoefBloc += matieres.get(a).getCoeficient();
                                                totalPointBloc += 0;

                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("O", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("0", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("Pas encore valu",
                                                        true, new Font(Font.FontFamily.TIMES_ROMAN, 10,
                                                                Font.ITALIC)));
                                            }
                                        }
                                    }

                                    //le texte Total pour chaque bloc
                                    PdfPCell cellTotalBlocText = new PdfPCell(
                                            new Paragraph("Total Matires " + nature.get(i).getLibelle() + " ",
                                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                                    cellTotalBlocText.setColspan(2);
                                    table.addCell(cellTotalBlocText);

                                    table.addCell(PrintUtils.createPdfPCell("" + totalCoefBloc, true, new Font(
                                            Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell("" + totalPointBloc, 2, true,
                                            new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL,
                                                    BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell(
                                            "Moyenne Matires  " + nature.get(i).getLibelle(), 3, false,
                                            PrintUtils.blueFont));
                                    if (totalCoefBloc != 0) {
                                        table.addCell(PrintUtils.createPdfPCell(
                                                "" + (totalPointBloc / totalCoefBloc) + "/20", 2, true,
                                                PrintUtils.redFont));
                                    } else {
                                        table.addCell(PrintUtils.createPdfPCell("......", 2, true,
                                                PrintUtils.redFont));
                                    }
                                    table.addCell(PrintUtils.createPdfPCell("  ", 5, false));
                                }
                            } else {

                            }
                            //on ecrit totaux
                            table.addCell(PrintUtils.createPdfPCell("Totaux  ", 2, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));

                            //on met le total de coefficient
                            table.addCell(PrintUtils.createPdfPCell("" + totalCoef, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            //on met le total de point
                            table.addCell(PrintUtils.createPdfPCell("" + totalPoint, 2, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Moyenne de la " + sequence.getIdsequence().getNom(), 3, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLUE)));
                            if (totalCoef != 0) {
                                table.addCell(PrintUtils.createPdfPCell((totalPoint / totalCoef) + "/20", 2,
                                        true,
                                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED)));
                            }

                            bulletin.add(table);
                            bulletin.close();
                            JsfUtil.addSuccessMessage(
                                    "Opration russie,redirigez-vous dans le repertoire bulletin");
                        } catch (DocumentException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        /*} else {
                         JsfUtil.addErrorMessage("L'lve selectionn n a aucune note  la squence slectionne");
                         }*/
                    } else {
                        JsfUtil.addErrorMessage("Aucune nature de matiere parametre");
                    }
                } else {
                    JsfUtil.addErrorMessage("l'eleve n a pas de classe");
                }
            } else {
                JsfUtil.addErrorMessage("veuillez selectionner une squence !");
            }
        } else {
            JsfUtil.addErrorMessage("Veuillez selectionner un lve");
        }
    } else {
        String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html");
        } catch (IOException ex) {
            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ictproject.ReportGenerator.java

public void writer(String selected) {
    //        if (!folderForPDF.exists()) {
    //      if (folderForPDF.mkdir()) {
    //         System.out.println("Directory is created!");
    //      } else {
    //         System.out.println("Failed to create directory!");
    //      }//  www  . j  av a  2 s  . co  m
    //   }

    Document document = new Document(PageSize.A4);
    try {
        String path = "E:/" + selected + ".pdf";
        com.itextpdf.text.pdf.PdfWriter.getInstance(document, new FileOutputStream(path));
        document.open();
        Paragraph para = getParagraph(selected, "gulmi");
        document.add(para);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(getParagraph(selected, "janajatiAnusar"));
        document.add(janajatiAnusar(selected));
        document.add(getParagraph(selected, "pani ko sroth"));
        document.add(getPaniKoSroth(selected));

        document.newPage();
        document.add(getParagraph(selected, "name"));

        document.add(getParagraph(selected, "actual budget"));
        document.add(actualBudget(selected, "actualBudget"));
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(getParagraph(selected, "expected budget"));
        document.add(actualBudget(selected, "expectedBudget"));

        document.setPageSize(PageSize.A4.rotate());
        document.newPage();
        document.add(getParagraph(selected, "name"));
        document.add(getParagraph(selected, "sauchalayKoAwasta"));
        document.add(sauchalayKoAwasta(selected));

        document.newPage();
        document.add(getParagraph(selected, "name"));
        document.add(getParagraph(selected, "pani janya rog ko bibaran"));
        document.add(rogKoBibaran(selected));

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("error" + e.getMessage());
        ErrorPopup errorPopup = new ErrorPopup(e.getMessage());
        errorPopup.setVisible(true);
        errorPopup.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
}

From source file:info.longnetpro.examples.PdfLibExamples.java

public static void generatePdf()
        throws DocumentException, URISyntaxException, MalformedURLException, IOException {
    String licFile = getLicenseFilePath();
    loadLicenseFile(licFile);/*from   w  w  w. ja va  2  s  .c  om*/

    String dest = getTargetFilePath();
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(dest));
    Rectangle pageSize = PageSize.LETTER;
    Rectangle rect = new Rectangle(0f, 0f, 50f, 100f);
    rect.setBorder(15);
    rect.setBorderColor(BaseColor.RED);
    rect.setBorderWidth(.5f);
    rect.setBackgroundColor(BaseColor.BLUE);
    doc.setPageSize(pageSize);
    doc.open();

    Page page = new Page(pageSize.getWidth(), pageSize.getHeight());
    ContentBox rpage = page.margin(new Float[] { 10f, 50f, 10f, 50f });

    for (Anchor anchor : Anchor.values()) {
        ContentBox box = new ContentBox(50f, 100f);
        float offx = anchor.equals(Anchor.CENTER) ? -50f : 0f;
        float offy = anchor.equals(Anchor.CENTER) ? -50f : 0f;

        ContentBox rr = anchor.anchorElement(rpage, box, offx, offy);

        if (anchor.equals(Anchor.BOTTOM_LEFT)) {
            float[] dim = box.scaleByPercentage(0.5f);
            //rr = rr.reposition(dim[0], dim[1], Anchor.TOP_RIGHT);
        }

        rect.setLeft(rr.getLeft());
        rect.setBottom(rr.getBottom());
        rect.setRight(rr.getRight());
        rect.setTop(rr.getTop());
        doc.add(rect);
    }
    String imageFile = getImageFilePath();
    Image image = Image.getInstance(imageFile);

    float width = Measurement.dotsToUserUnits(image.getWidth(), 1200);
    float height = Measurement.dotsToUserUnits(image.getHeight(), 1200);

    System.out.println(width + " " + height);

    ContentBox img = Anchor.BOTTOM_LEFT.anchorElement(rpage, width, height);

    image.scaleToFit(width, height);
    image.setAbsolutePosition(img.getLeft(), img.getBottom());

    System.out.println(image.getWidth() + " " + image.getHeight());
    System.out.println(image.getAbsoluteX() + " " + image.getAbsoluteY());

    doc.add(image);
    doc.close();
}

From source file:IPDGES.ConcentForm.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*w w  w . j a  va2s.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 {
    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "FORMULARIO DE CONSTANCIA DE INFORMACION AL PACIENTE GES", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(Artculo 24, Ley 19.966)", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 2
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DATOS DEL PRESTADOR", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "INSTITUCIN (Hospital, Clnica, Consultorio,etc): " + institution, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "DIRECCION: " + address, type);
        p2 = new Paragraph(space, "CIUDAD: " + city, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "NOMBRE PERSONA QUE NOTIFICA: " + personName, type);
        p2 = new Paragraph(space, "RUT: " + rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "FONASA: " + patientFonasa, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "REGION: " + region, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type);
        p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);

        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORMACIN MDICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "CONFIRMACIN DIAGNSTICA GES:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, ges, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(  ) Confirmacin Diagnstica", type);
        p2 = new Paragraph(space, "(  ) Paciente en Tratamiento", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 5
        document.add(new Paragraph(space, "CONSTANCIA", subTitle));
        Paragraph text1 = new Paragraph(space,
                "Declaro que, con esta fecha y hora, he tomado conocimiento que tengo derecho a acceder a las Garantas Explcitas en Salud, siempre que la atencin sea otorgada en la red de Prestadores que me corresponde segn Fonasa o Isapre, a la que me encuentro adscrito",
                type);
        text1.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text1);
        document.add(new Paragraph(space, "IMPORTANTE", subTitle));
        Paragraph text2 = new Paragraph(space,
                "Tenga presente que s no se cumplen las garantas usted puede reclamar ante Fonasa o la Isapre, segn corresponda. Si la respuesta no es satisfactoria, usted puede recurrir en segunda instancia a la Superintendencia de Salud.",
                type);
        text2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text2);
        document.add(new Paragraph(space, "FECHA Y HORA DE NOTIFICACIN: " + "-", subTitle));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        //row 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORM DIAGNSTICO GES", subTitle);
        p2 = new Paragraph(space, "TOM CONOCIMIENTO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "(Firma de persona que notifica)", subTitle2);
        p2 = new Paragraph(space, "(Firma o huella digital  representante)", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 7
        document.add(new Paragraph(space,
                "En caso que la persona que tom conocimiento no sea el paciente, identificar.", type));

        //row 8
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Nombre:", type);
        p2 = new Paragraph(space, "R.U.T:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N Telfono Celular:", type);
        p2 = new Paragraph(space, "Direccin correo electrnico (e-mail):", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:IPDGES.IPD.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//  w  ww .  j  a v  a  2 s .co  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 {

    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Informe de Proceso Diagnstico", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 40);
        table.addCell(cellRow1);
        document.add(table);

        //row: 2         
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Fecha: " + dfDateInstance.format(date), type);
        p2 = new Paragraph(space, "Folio: " + numberFolio, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Servicio de Salud: " + healthService, type);
        p2 = new Paragraph(space, "Establecimiento: " + establishment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthTop(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Especialidad: " + speciality, type);
        p2 = new Paragraph(space, "Unidad: " + unit, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthBottom(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Paciente", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Historia clnica: " + clinicalHistory, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + patientName, type);
        p2 = new Paragraph(space, "Rut: " + Rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Sexo: " + sexo, type);
        p2 = new Paragraph(space, "Fecha de nacimiento: " + dfDateInstance.format(bornDate), type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Edad: " + age, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 5
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos Clnicos", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "* Slo para caso AUGE", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Problema de salud AUGE:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Confirma que el diagnstico pertenece al sistema AUGE? " + "()SI ()NO",
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "SubProblema Auge:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeSubProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosis, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Fundamentos de diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosticBasics, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Tratamiento e Indicaciones:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, treatment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space,
                "El tratamiento deber iniciarce a ms tardar el: " + dfDateInstance.format(treatmentInit),
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Profesional", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + professionalName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Rut: " + professionalRut, type);
        p2 = new Paragraph(space, "Firma del mdico", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}