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

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

Introduction

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

Prototype

public void setSpacingBefore(final float spacing) 

Source Link

Document

Sets the spacing before this table.

Usage

From source file:Servlets.PDF.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/pdf");
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {/*from w w w . j  a v a  2s  .c  o m*/
        //obtengo datos de cliente,  reserva y total
        String rreserva = request.getParameter("reserva");
        String rcliente = request.getParameter("cliente");
        String rtotal = request.getParameter("total");
        //String rtipo = request.getParameter("esProv");

        // Obtener datos de cliente e items de reserva
        DtUsuario dtu = getDtUsuario(rcliente);
        String nombre = dtu.getNombre();
        String apellido = dtu.getApellido();
        String servicios = "";
        String promos = "";
        java.util.List<DtItemReserva> dtItems = listarItems(Integer.parseInt(rreserva)).getItems();
        Iterator<DtItemReserva> iter = dtItems.iterator();
        DtItemReserva dtItem;

        // Crear y abrir documento

        String HomeDeUSuario = System.getProperty("user.home");

        String ruta = HomeDeUSuario + "/Factura Reserva " + rreserva + ".pdf";

        FileOutputStream archivo = new FileOutputStream(ruta);

        PdfWriter writer = PdfWriter.getInstance(document, archivo);

        document.open();

        Date date = new Date();

        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String fecha = dateFormat.format(date);

        // Agregar marcador inicial

        // Crear y agregar prrafo simple
        Paragraph paragraph1 = new Paragraph();
        Image imagen = Image.getInstance("http://localhost:8084/Help4TravelingWeb/img/logo-icon2.png");
        imagen.scaleAbsolute(200f, 200f);

        imagen.setAbsolutePosition(10, 650);
        imagen.setSpacingAfter(20);
        paragraph1.add(imagen);
        document.add(paragraph1);
        //fecha
        Paragraph fecha1 = new Paragraph(fecha);

        //encabezado
        Paragraph futuros = new Paragraph("Futuros Tecnologos SRL");
        Paragraph rut = new Paragraph("RUT 123456789012");
        Paragraph direccion = new Paragraph(" Av. Gral. Rivera 3629");
        Paragraph telefono = new Paragraph(" Tel: 555-5412");
        Paragraph nombre_empresa = new Paragraph(" Help4Travelling");

        //datos cliente
        String nombrecliente = nombre.toUpperCase() + " " + apellido.toUpperCase();
        String direccioncliente = " ";
        String rutcliente = "consumidor final".toUpperCase();
        Paragraph cliente = new Paragraph("Cliente: " + nombrecliente);
        Paragraph dircliente = new Paragraph("Direccion: " + direccioncliente);
        Paragraph rutcli = new Paragraph("RUT: " + rutcliente);

        //datos boleta

        String factura = rreserva;
        Paragraph tipodoc = new Paragraph("Contado");
        Paragraph Nfac = new Paragraph(" N  " + factura);

        //alineaciones

        //fecha 
        fecha1.setAlignment(Element.ALIGN_RIGHT);

        //encabezado
        futuros.setAlignment(Element.ALIGN_CENTER);
        rut.setAlignment(Element.ALIGN_CENTER);
        direccion.setAlignment(Element.ALIGN_CENTER);
        telefono.setAlignment(Element.ALIGN_CENTER);

        //nombre empresa
        nombre_empresa.setAlignment(Element.ALIGN_LEFT);
        nombre_empresa.setSpacingBefore(10);
        nombre_empresa.setSpacingAfter(30);

        //datos de boleta
        tipodoc.setAlignment(Element.ALIGN_RIGHT);
        Nfac.setAlignment(Element.ALIGN_RIGHT);

        document.add(fecha1);
        document.add(futuros);
        document.add(rut);
        document.add(direccion);
        document.add(telefono);
        document.add(nombre_empresa);
        document.add(tipodoc);
        document.add(Nfac);
        document.add(cliente);
        document.add(dircliente);
        document.add(rutcli);

        PdfPTable tabla = new PdfPTable(4);
        tabla.setSpacingBefore(25);
        tabla.setSpacingAfter(25);

        //creo encabezado de tabla
        PdfPCell codigo = new PdfPCell(new Phrase("Proveedor".toUpperCase()));
        PdfPCell descripcion = new PdfPCell(new Phrase("descripcion".toUpperCase()));
        PdfPCell ecantidad = new PdfPCell(new Phrase("cantidad".toUpperCase()));
        PdfPCell eprecio = new PdfPCell(new Phrase("precio".toUpperCase()));

        tabla.setHeaderRows(1);
        tabla.setWidthPercentage(100f);

        //alineamos las frases del cabezal
        codigo.setHorizontalAlignment(Element.ALIGN_CENTER);
        descripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
        ecantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
        eprecio.setHorizontalAlignment(Element.ALIGN_CENTER);

        //agrego cabezal de tabla
        tabla.addCell(codigo);
        tabla.addCell(descripcion);
        tabla.addCell(ecantidad);
        tabla.addCell(eprecio);

        //obtengo datos de la reserva para imprimir las distintas rows

        while (iter.hasNext()) {
            dtItem = iter.next();
            Integer cantidad = dtItem.getCantidad();
            String oferta = dtItem.getOferta().getNombre();
            String precio;
            String proveedor;
            if (existeServicio(oferta)) {
                proveedor = getNkProveedorServicio(oferta);
                DtServicio dts = getDtServicio(oferta, proveedor);
                precio = String.valueOf(dts.getPrecio());
            } else {
                proveedor = getNkProveedorPromocion(oferta);
                DtPromocion dtp = getDTPromocion(oferta, proveedor);
                precio = dtp.getDescuento();
            }
            /*  String item = "<li>Nombre: <em>" + oferta + "</em>"
                + " - Cantidad: <em>" + cantidad + "</em>"
                + " - $:<em>" + precio + "</em>"
                + " - Proveedor: <em>" + proveedor + "</em></li>";*/
            //creo encabezado de tabla
            PdfPCell iproveedor = new PdfPCell(new Phrase(proveedor.toUpperCase()));

            PdfPCell icantidad = new PdfPCell(new Phrase(cantidad.toString()));
            PdfPCell iprecio = new PdfPCell(new Phrase(precio.toUpperCase()));

            tabla.setHeaderRows(1);

            //alineamos las frases del cabezal
            iproveedor.setHorizontalAlignment(Element.ALIGN_CENTER);
            icantidad.setHorizontalAlignment(Element.ALIGN_CENTER);
            iprecio.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(iproveedor);
            if (existeServicio(oferta)) {
                PdfPCell idescripcion = new PdfPCell(new Phrase("servicio: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            } else {
                PdfPCell idescripcion = new PdfPCell(new Phrase("Promo: " + oferta));
                idescripcion.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(idescripcion);
            }
            tabla.addCell(icantidad);
            tabla.addCell(iprecio);
        }

        /*      // las distintas rows de los articulos
              tabla.addCell(proveedor);
              tabla.addCell(oferta);
              tabla.addCell(cantidad);
              tabla.addCell(precio);
        */
        //el ulimo de la tabla que da el total

        PdfPCell celdaFinal = new PdfPCell(new Paragraph(""));
        PdfPCell celdaTotal = new PdfPCell(new Paragraph("total:"));
        PdfPCell celdaPrecioTotal = new PdfPCell(new Paragraph(rtotal));
        // Indicamos cuantas columnas ocupa la celda
        celdaFinal.setColspan(2);

        celdaTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        celdaPrecioTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);

        tabla.addCell(celdaFinal);
        tabla.addCell(celdaTotal);
        tabla.addCell(celdaPrecioTotal);
        document.add(tabla);
        document.close();
        if (request.getParameter("dispositivo").equals("true"))
            response.sendRedirect("Movil.Reservas.jsp");
        else
            response.sendRedirect("Usuario.jsp");
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnGenerateReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Accounts Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {// w w w  . java  2 s.c om
            String date = today.replace(":", "_");
            //New PDF File will be created as ACCReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            paragraph1 = new Paragraph("                Finalized Accounts Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);

            t.addCell(new PdfPCell(new Phrase("Description")));
            t.addCell(new PdfPCell(new Phrase("Credit(Rs.)")));
            t.addCell(new PdfPCell(new Phrase("Debit(Rs.)")));
            int rows = tblIncome.getRowCount();

            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 0) + "")));
                if (tblIncome.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 1) + "")));
                }
                if (tblIncome.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblIncome.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            float totalIncome = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 1) != null) {
                    totalIncome = totalIncome + Float.parseFloat(tblIncome.getValueAt(i, 1).toString());
                } else {
                    totalIncome = totalIncome + 0;
                }
            }
            paragraph1 = new Paragraph("Total Income (Rs.) : " + totalIncome + "");
            document.add(paragraph1);
            float totalExpences = 0;
            for (int i = 0; i < rows; i++) {
                if (tblIncome.getValueAt(i, 2) != null) {
                    totalExpences = totalExpences + Float.parseFloat(tblIncome.getValueAt(i, 2).toString());
                } else {
                    totalExpences = totalExpences + 0;
                }
            }
            DecimalFormat roundValue = new DecimalFormat("###.##");
            float expense = Float.parseFloat(roundValue.format(totalExpences));
            paragraph1 = new Paragraph("Total Expence (Rs.) : " + expense + "");
            document.add(paragraph1);
            float profit = 0;
            profit = totalIncome - expense;
            totProfit = profit;
            trigger1 = 1;
            paragraph1 = new Paragraph("Total Profit (Rs.) : " + profit + "" + "\n\n");
            document.add(paragraph1);
            String name = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + name);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Accounts Report named ACCReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Account Reports\\ACCReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Account Reports\\ACCReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }
        } catch (Exception ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:simz1.ManagerHomeScreen.java

private void btnFinalReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalReportActionPerformed
    int reply = JOptionPane.showConfirmDialog(null, "Do you wish to fianlize Products Report now?", "",
            JOptionPane.YES_NO_OPTION);
    if (reply == JOptionPane.YES_OPTION) {
        Document document = new Document(PageSize.A4);
        try {//from w w  w . j  a va 2  s  .  c  o  m
            String date = today.replace(":", "_");
            //New PDF File will be created as ProReport2016_01_01 //today's date
            PdfWriter.getInstance(document,
                    new FileOutputStream("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf"));
            document.open();
            Image image2 = Image.getInstance("C:\\#SIMZ\\logo1.jpg");
            document.add(image2);
            Paragraph paragraph1 = new Paragraph(
                    "Perera and Sons Bakers(pvt)Ltd.\nAddress: 1/52, Galle Road,Colombo 03.\nT.P:0112552225\n\n");
            document.add(paragraph1);
            //Following blank space is for the alignment of the topic
            paragraph1 = new Paragraph("                Finalized Products Report - " + today + "",
                    FontFactory.getFont(FontFactory.HELVETICA, 18));
            document.add(paragraph1);
            //adding a table
            PdfPTable t = new PdfPTable(3);
            t.setSpacingBefore(25);
            t.setSpacingAfter(25);
            t.addCell(new PdfPCell(new Phrase("Product Name")));
            t.addCell(new PdfPCell(new Phrase("Received Quantity")));
            t.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            int rows = tblReports.getRowCount();
            for (int i = 0; i < rows; i++) {
                t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 0) + "")));
                if (tblReports.getValueAt(i, 1) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 1) + "")));
                }
                if (tblReports.getValueAt(i, 2) == null) {
                    t.addCell(new PdfPCell(new Phrase("-")));
                } else {
                    t.addCell(new PdfPCell(new Phrase(tblReports.getValueAt(i, 2) + "")));
                }
            }
            document.add(t);
            paragraph1 = new Paragraph("Expired Item Details");
            document.add(paragraph1);
            PdfPTable t2 = new PdfPTable(2);
            t2.setSpacingBefore(25);
            t2.setSpacingAfter(25);
            t2.addCell(new PdfPCell(new Phrase("Product Name")));
            t2.addCell(new PdfPCell(new Phrase("Remained Quantity")));
            String dateToday = today.replace(":", "-");
            ResultSet rs = dbOps.getExpiredItemList(dateToday);
            while (rs.next()) {
                t2.addCell(new PdfPCell(new Phrase(rs.getString(1))));
                t2.addCell(new PdfPCell(new Phrase(rs.getString(3))));
            }
            document.add(t2);
            String user = dbOps.getName(name1.getText());
            paragraph1 = new Paragraph("Report Generated By : " + user);
            document.add(paragraph1);
            //view report
            int reply1 = JOptionPane.showConfirmDialog(null,
                    "Finalized Products Report named ProReportToday'sDate successfully generated.\nDo you want to view the report?",
                    "", JOptionPane.YES_NO_OPTION);
            trigger2 = 1;
            if (reply1 == JOptionPane.YES_OPTION) {
                if ((new File("C:\\#SIMZ\\Product Reports\\ProReport" + date + "" + ".pdf")).exists()) {

                    Process p = Runtime.getRuntime()
                            .exec("rundll32 url.dll,FileProtocolHandler C:\\#SIMZ\\Product Reports\\ProReport"
                                    + date + "" + ".pdf");
                    p.waitFor();
                }
            }

        } catch (SQLException | HeadlessException | IOException | InterruptedException | DocumentException ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(this, "File already exists!!!");
        }
        document.close();
    }
}

From source file:src.servlets.ManageAdmin.java

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

    Map m = request.getParameterMap();
    if (m.containsKey("GetPDF")) {
        try {
            String Report = getServletContext().getRealPath("") + "admin\\PDF_Report.pdf";

            FileOutputStream file = new FileOutputStream(Report);
            Document document = new Document();
            document.addAuthor("K00140908");
            PdfWriter.getInstance(document, file);
            ///////////////////////ADDING THE FILES TO PDF////////////////////
            //Inserting Image in PDF
            String uploadPath = getServletContext().getRealPath("") + "images\\logo.gif";

            Image img = Image.getInstance(uploadPath);

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            //            Inserting Title in PDF  ORIGINAL
            //            Font fontTitle=new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.WHITE);
            //            Chunk title=new Chunk("PDF GENERATION in Java with iText", fontTitle);
            //            title.setBackground(new BaseColor(255,102,0), 1f, 1f, 1f, 3f);
            //            title.setLineHeight(30f);
            //            title.setUnderline(BaseColor.BLACK,5f,0.5f,2f,0.5f,PdfContentByte.LINE_CAP_ROUND);
            Font fontTitle = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);
            Chunk title = new Chunk("Lit Realty System Report", fontTitle);
            title.setLineHeight(30f);

            //Inserting Table in PDF
            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100); // Sets the width percentage that the table will occupy in the page
            table.setSpacingAfter(10f);
            table.setSpacingBefore(15f);
            table.setWidths(new float[] { 2f, 2f, 2f }); // Sets relative width of table

            Font fontHeader = new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD, BaseColor.BLUE);
            PdfPCell headercell = new PdfPCell(new Phrase("Property Photo", fontHeader)); // Creates new cell in table
            headercell.setBackgroundColor(new BaseColor(230, 230, 243));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Property ID", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Price", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            PdfPCell cell1 = new PdfPCell(img, false);

            table.addCell(cell1);
            table.addCell("134000");
            table.addCell("213445");
            table.addCell("134000");

            //Inserting List
            com.itextpdf.text.List list = new com.itextpdf.text.List(true, 30);
            list.add(new ListItem("Example1"));
            list.add(new ListItem("Example2"));
            list.add(new ListItem("Example3"));

            //Adding elements into PDF Document
            document.open();

            document.add(img);
            document.add(title);

            document.add(Chunk.NEWLINE);
            document.add(table);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Properts By Agent X").setUnderline(+1f, -5f));
            //////////////////////GET Propertys From Entity///////////////
            List<Properties> allPropertiesList = PropertiesDB.getAllProperties();

            PdfPTable propertyTable = new PdfPTable(3);
            PdfPCell propertyHeadingcell1 = new PdfPCell(new Phrase("Photo"));
            PdfPCell propertyHeadingcell2 = new PdfPCell(new Phrase("Property ID"));
            PdfPCell propertyHeadingcell3 = new PdfPCell(new Phrase("Price"));

            propertyHeadingcell1.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell2.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell3.setBorder(Rectangle.NO_BORDER);

            propertyTable.addCell(propertyHeadingcell1);
            propertyTable.addCell(propertyHeadingcell2);
            propertyTable.addCell(propertyHeadingcell3);

            document.add(Chunk.NEWLINE);

            String uploadPathforPropertyPhoto = getServletContext().getRealPath("")
                    + "images\\properties\\thumbnails\\";

            Image propertyThumbnail;

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            for (Properties anProperty : allPropertiesList) {
                propertyThumbnail = Image.getInstance(uploadPathforPropertyPhoto + anProperty.getPhoto());
                PdfPCell propertycell1 = new PdfPCell(propertyThumbnail, false);
                propertycell1.setPaddingBottom(20);
                PdfPCell propertycell2 = new PdfPCell(new Phrase(anProperty.getListingNum().toString()));
                PdfPCell propertycell3 = new PdfPCell(new Phrase(anProperty.getPrice().toString()));

                propertycell1.setBorder(Rectangle.NO_BORDER);
                propertycell2.setBorder(Rectangle.NO_BORDER);
                propertycell3.setBorder(Rectangle.NO_BORDER);

                propertyTable.addCell(propertycell1);
                propertyTable.addCell(propertycell2);
                propertyTable.addCell(propertycell3);

            }
            document.add(Chunk.NEWLINE);
            document.add(propertyTable);
            //////////////////////GET Propertys From Entity///////////////

            document.close();
            file.close();

            System.out.println("Pdf created successfully ! :)");

            String filePath = Report;
            File downloadFile = new File(filePath);
            FileInputStream inStream = new FileInputStream(downloadFile);

            // if you want to use a relative path to context root:
            String relativePath = getServletContext().getRealPath("");
            System.out.println("relativePath = " + relativePath);

            // obtains ServletContext
            ServletContext context = getServletContext();

            // gets MIME type of the file
            String mimeType = context.getMimeType(filePath);
            if (mimeType == null) {
                // set to binary type if MIME mapping not found
                mimeType = "application/octet-stream";
            }
            System.out.println("MIME type: " + mimeType);

            // modifies response
            response.setContentType(mimeType);
            response.setContentLength((int) downloadFile.length());

            // forces download
            String headerKey = "Content-Disposition";
            String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
            response.setHeader(headerKey, headerValue);

            // obtains response's output stream
            OutputStream outStream = response.getOutputStream();

            byte[] buffer = new byte[4096];
            int bytesRead = -1;

            while ((bytesRead = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytesRead);
            }

            inStream.close();
            outStream.close();
            /////////////////

            processRequest(request, response);
        } catch (DocumentException ex) {
            Logger.getLogger(ManageAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addPersonalInformation(User user) throws DocumentException {

    Paragraph paragraph;//from w  ww.  j a  v a 2s .  c o  m
    PdfPCell cell;
    PdfPTable table;
    table = new PdfPTable(new float[] { 0.5f, 2f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.name + " " + user.surnames, font1);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.birthDate + "\n", font4);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph("Calle " + user.residenceAddress + " N " + user.residenceNumber + " "
            + user.residenceZipCode + " " + user.residenceCity + "\n", font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.phoneNumber, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph = new Paragraph(" ");
    cell.setBorder(PdfPCell.NO_BORDER);
    paragraph.setAlignment(Paragraph.ALIGN_RIGHT);
    cell.setPaddingRight(10);
    cell.addElement(paragraph);
    table.addCell(cell);

    //Second column
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingLeft(55);
    cell.setPaddingTop(0);

    paragraph = new Paragraph(user.email, font2);
    paragraph.setSpacingBefore(20);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.addElement(paragraph);
    table.addCell(cell);

    document.add(table);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addProfessionalExperience(List<ProfessionalExperience> experienceList) throws DocumentException {
    Paragraph paragraph;/*w ww.  j  ava2s.  com*/
    PdfPCell cell;
    PdfPTable table;

    for (int i = 0; i < experienceList.size(); i++) {

        table = new PdfPTable(new float[] { 1f, 0.5f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(5);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        if (i == 0) {
            paragraph = new Paragraph("Experiencia Profesional", font1);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph = new Paragraph("");
        }
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //Second column
        cell = new PdfPCell();
        cell.setPaddingLeft(10);
        cell.setPaddingTop(0);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("");
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(experienceList.get(i).job + "." + " " + experienceList.get(i).company, font2);
        cell.setBorder(PdfPCell.NO_BORDER);

        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //Second column
        cell = new PdfPCell();
        cell.setPaddingLeft(10);
        cell.setPaddingTop(0);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(experienceList.get(i).startDate + " - " + experienceList.get(i).endDate,
                font3);
        cell.addElement(paragraph);
        table.addCell(cell);

        document.add(table);
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addStudies(User user) throws DocumentException {
    Paragraph paragraph;//from   w  ww  .j  ava2 s.  c om
    PdfPCell cell;
    PdfPTable table;

    if (!user.studyTitle.equals("")) {
        table = new PdfPTable(new float[] { 1f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(5);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("Estudios", font1);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(user.studyTitle + "." + " " + user.studyLocation, font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        document.add(table);
    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addSoftware(List<Software> softwareList) throws DocumentException {
    Paragraph paragraph1;//  w  w w  .j a  va  2s .  c o  m
    Paragraph paragraph2;
    PdfPCell cell;
    PdfPTable table;
    table = new PdfPTable(new float[] { 1f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    for (int i = 0; i < softwareList.size(); i++) {
        cell.setBorder(PdfPCell.NO_BORDER);
        if (i == 0) {
            paragraph1 = new Paragraph("Programas informticos:", font1);
            paragraph2 = new Paragraph(
                    softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph1 = new Paragraph("");
            paragraph2 = new Paragraph(
                    softwareList.get(i).software + "." + " Nivel: " + softwareList.get(i).level, font2);
        }
        paragraph1.setAlignment(Paragraph.ALIGN_LEFT);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph1);
        cell.addElement(paragraph2);
    }
    table.addCell(cell);
    document.add(table);
}

From source file:utils.pdf.cv_templates.Template1.java

private void addSkills(User user, List<String> personalCharacteristics, List<Skill> skills)
        throws DocumentException {
    Paragraph paragraph;/*from  w  w w  .  j  a  v  a  2 s .  co m*/
    PdfPCell cell;
    PdfPTable table;

    List<String> rankedSkills = selectSkills(skills);
    if (personalCharacteristics.size() != 0 && rankedSkills.size() != 0) {
        table = new PdfPTable(new float[] { 1f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(5);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("Sobre mi...", font1);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(
                "Me defino como una persona de carcter " + personalCharacteristics.get(1).toLowerCase()
                        + " y " + personalCharacteristics.get(0).toLowerCase() + ".",
                font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("Entre mis puntos fuertes destacan las " + rankedSkills.get(0).toLowerCase()
                + " y las " + rankedSkills.get(1).toLowerCase() + ".", font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph(
                "Considero que soy una persona activa que presenta " + rankedSkills.get(2).toLowerCase() + ".",
                font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        //First column
        cell = new PdfPCell();
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph = new Paragraph("Adems, una de las caractersticas que me define es que soy "
                + personalCharacteristics.get(2).toLowerCase() + ".", font2);
        cell.setBorder(PdfPCell.NO_BORDER);
        paragraph.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph);
        table.addCell(cell);

        if (!user.drivingLicense.equals("No tengo carnet")) {
            //First column
            cell = new PdfPCell();
            cell.setBorder(PdfPCell.NO_BORDER);
            paragraph = new Paragraph("Permiso de conducir: " + user.drivingLicense + ".", font2);
            cell.setBorder(PdfPCell.NO_BORDER);
            paragraph.setAlignment(Paragraph.ALIGN_LEFT);
            cell.setPaddingRight(10);
            cell.setPaddingLeft(35);
            cell.addElement(paragraph);
            table.addCell(cell);
        }

        document.add(table);

    }
}

From source file:utils.pdf.cv_templates.Template1.java

private void addAllTitle(List<Language> languageList, List<Course> courseList) throws DocumentException {
    Paragraph paragraph1;/*from ww  w  .j  av  a2 s. c o m*/
    Paragraph paragraph2;
    PdfPCell cell;
    PdfPTable table;
    table = new PdfPTable(new float[] { 0.85f, 1.7f, 0.6f });
    table.setWidthPercentage(100);
    table.setSpacingBefore(5);

    //First column
    cell = new PdfPCell();
    for (int i = 0; i < languageList.size(); i++) {
        cell.setBorder(PdfPCell.NO_BORDER);
        if (i == 0) {
            paragraph1 = new Paragraph("Idiomas:", font1);
            paragraph2 = new Paragraph(
                    languageList.get(i).language + "." + " Nivel: " + languageList.get(i).level, font2);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph1 = new Paragraph("");
            paragraph2 = new Paragraph(
                    languageList.get(i).language + "." + " Nivel: " + languageList.get(i).level, font2);
        }
        paragraph1.setAlignment(Paragraph.ALIGN_LEFT);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph1);
        cell.addElement(paragraph2);
    }
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    for (int j = 0; j < courseList.size(); j++) {
        cell.setBorder(PdfPCell.NO_BORDER);
        if (j == 0) {
            paragraph1 = new Paragraph("Cursos:", font1);
            paragraph2 = new Paragraph(
                    courseList.get(j).name + "." + " Expedido por: " + courseList.get(j).company, font2);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph1 = new Paragraph("");
            paragraph2 = new Paragraph(
                    courseList.get(j).name + "." + " Expedido por: " + courseList.get(j).company, font2);
        }
        paragraph1.setAlignment(Paragraph.ALIGN_LEFT);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph1);
        cell.addElement(paragraph2);
    }
    table.addCell(cell);

    //First column
    cell = new PdfPCell();
    for (int j = 0; j < courseList.size(); j++) {
        cell.setBorder(PdfPCell.NO_BORDER);
        if (j == 0) {
            paragraph1 = new Paragraph(" ", font1);
            paragraph2 = new Paragraph(courseList.get(j).length + " Horas", font3);
            cell.setBorder(PdfPCell.NO_BORDER);
        } else {
            paragraph1 = new Paragraph("");
            paragraph2 = new Paragraph(courseList.get(j).length + " Horas", font3);
        }
        paragraph1.setAlignment(Paragraph.ALIGN_LEFT);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);
        cell.setPaddingRight(10);
        cell.setPaddingLeft(35);
        cell.addElement(paragraph1);
        cell.addElement(paragraph2);
    }
    table.addCell(cell);

    document.add(table);
}