Example usage for com.itextpdf.text Font BOLD

List of usage examples for com.itextpdf.text Font BOLD

Introduction

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

Prototype

int BOLD

To view the source code for com.itextpdf.text Font BOLD.

Click Source Link

Document

this is a possible style.

Usage

From source file:Compras.reportePedidos.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);//from ww w.ja va2s.c  o  m
    if (t_datos.getRowCount() > 0) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                try {
                    DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                    formatoPorcentaje.setMinimumFractionDigits(2);
                    session.beginTransaction().begin();
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    //Orden ord=buscaApertura();
                    PDF reporte = new PDF();
                    Date fecha = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
                    String valor = dateFormat.format(fecha);

                    reporte.Abrir2(PageSize.LETTER.rotate(), "Reporte", ruta + ".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 5, Font.BOLD);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = Element.ALIGN_CENTER;
                    int izquierda = Element.ALIGN_LEFT;
                    int derecha = Element.ALIGN_RIGHT;
                    float[] tam_pdf = new float[] { 10, 25, 13, 18, 10, 50, 50, 60, 18, 18, 15 };

                    PdfPTable tabla = reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT);

                    cabecera(reporte, bf, tabla);
                    int ren = 0;
                    double dm = 0d, cam = 0d, min = 0d, med = 0d, max = 0d, pin = 0d, tot = 0d;
                    for (int i = 0; i < t_datos.getRowCount(); i++) {
                        for (int j = 0; j < t_datos.getColumnCount(); j++) {
                            if (t_datos.getColumnName(j).compareTo("Monto tot.") == 0) {
                                if (t_datos.getValueAt(i, j) != null)
                                    tabla.addCell(
                                            reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, j)),
                                                    font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                                else
                                    tabla.addCell(reporte.celda("0.00", font, contenido, derecha, 0, 1,
                                            Rectangle.RECTANGLE));
                            } else {
                                if (t_datos.getValueAt(i, j) != null)
                                    tabla.addCell(reporte.celda("" + t_datos.getValueAt(i, j), font, contenido,
                                            izquierda, 0, 1, Rectangle.RECTANGLE));
                                else
                                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                            Rectangle.RECTANGLE));
                            }
                        }
                        /*if(ren==38)
                        {
                        reporte.agregaObjeto(tabla);
                        reporte.writer.newPage();
                        tabla=reporte.crearTabla(tam_pdf.length, tam_pdf, 100, Element.ALIGN_LEFT);
                        cabecera(reporte, bf, tabla);
                        ren=-1;
                        }
                        ren++;*/
                    }
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                } finally {
                    if (session != null)
                        if (session.isOpen())
                            session.close();
                }
            }
        }
    }
}

From source file:Compras.reportePedidos.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla) {
    reporte.contenido.setLineWidth(0.5f);
    reporte.contenido.setColorStroke(new GrayColor(0.2f));
    reporte.contenido.setColorFill(new GrayColor(0.9f));
    reporte.contenido.roundRectangle(30, 700, 210, 45, 5);
    reporte.contenido.roundRectangle(250, 700, 325, 45, 5);
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction().begin();//  www  .  j a  v  a2  s  .  co  m
    Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
    reporte.inicioTexto();
    reporte.contenido.setFontAndSize(bf, 14);
    reporte.contenido.setColorFill(BaseColor.BLACK);
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 30, 585, 0);
    reporte.contenido.setFontAndSize(bf, 8);
    reporte.contenido.setColorFill(BaseColor.BLACK);
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Reporte de pedidos", 30, 575, 0);
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
            "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 585, 0);
    reporte.finTexto();
    if (session != null)
        if (session.isOpen())
            session.close();

    //agregamos renglones vacios para dejar un espacio
    reporte.agregaObjeto(new Paragraph(" "));

    Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

    BaseColor cabecera = BaseColor.GRAY;
    BaseColor contenido = BaseColor.WHITE;
    int centro = Element.ALIGN_CENTER;
    int izquierda = Element.ALIGN_LEFT;
    int derecha = Element.ALIGN_RIGHT;

    tabla.addCell(reporte.celda("Pedido", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Fecha", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("O. Taller", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Usuario", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Prov.", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Nombre de Proveedor", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Facturar a", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Observaciones", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Autorizo1", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Autorizo2", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("Monto Tot", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
}

From source file:Compras.reportePedidos.java

public void cabeceraReporte(PDF reporte, BaseFont bf, PdfPTable tabla) {
    reporte.contenido.setLineWidth(0.5f);
    reporte.contenido.setColorStroke(new GrayColor(0.2f));
    reporte.contenido.setColorFill(new GrayColor(0.9f));
    reporte.contenido.roundRectangle(30, 700, 210, 45, 5);
    reporte.contenido.roundRectangle(250, 700, 325, 45, 5);
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction().begin();//from   ww  w.java2  s .  com
    Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
    reporte.inicioTexto();
    reporte.contenido.setFontAndSize(bf, 14);
    reporte.contenido.setColorFill(BaseColor.BLACK);
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 30, 585, 0);
    reporte.contenido.setFontAndSize(bf, 8);
    reporte.contenido.setColorFill(BaseColor.BLACK);
    String cabeza = "Reporte";
    if (l_id_cliente.getText().compareTo("") != 0 && t_datos.getRowCount() > 0) {
        cabeza += " Proveedor: " + t_datos.getValueAt(0, 5).toString();
    }
    if (t_fecha1.getText().compareTo("AAAA-MM-DD") != 0)
        cabeza += " del: " + t_fecha1.getText();
    if (t_fecha2.getText().compareTo("AAAA-MM-DD") != 0)
        cabeza += "  al: " + t_fecha2.getText();
    if (t_orden.getText().compareTo("") != 0)
        cabeza += "  Orden: " + t_orden.getText();
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, cabeza, 30, 575, 0);
    String texto = "";
    int[] lista = t_datos.getSelectedRows();
    if (t_datos.getSelectedRows().length > 0) {
        for (int x = 0; x < t_datos.getSelectedRows().length; x++) {
            texto += t_datos.getValueAt(lista[x], 0) + ", ";
        }
    } else {
        if (t_datos.getRowCount() > 0) {
            for (int x = 0; x < t_datos.getRowCount(); x++) {
                texto += t_datos.getValueAt(x, 0) + ", ";
            }
        }
    }
    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
            "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 585, 0);
    reporte.finTexto();
    if (session != null)
        if (session.isOpen())
            session.close();

    //agregamos renglones vacios para dejar un espacio
    reporte.agregaObjeto(new Paragraph(" "));

    Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);

    BaseColor cabecera = BaseColor.GRAY;
    BaseColor contenido = BaseColor.WHITE;
    int centro = Element.ALIGN_CENTER;
    int izquierda = Element.ALIGN_LEFT;
    int derecha = Element.ALIGN_RIGHT;

    tabla.addCell(
            reporte.celda("MATERIAL PEDIDOS:" + texto, font, cabecera, centro, 8, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("PEDIDO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("NP", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("DESCRIPCIN", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("CANT", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("MED", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("PRECIO", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("ORDEN", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    tabla.addCell(reporte.celda("PARTIDA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
}

From source file:Contabilidad.RCuentas.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from  w  w  w  . jav  a 2 s .  co  m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 570, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;
        if (op == 1) {
            if (t_fecha3.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " apartir del " + t_fecha3.getText();

            if (t_fecha4.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " al " + t_fecha4.getText();
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 560, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 750, 570, 0);
        if (op == 1) {
            if (valores != null) {
                String val = "Estatus: ";
                if (lista.getSelectedValues().length > 0) {
                    for (int m = 0; m < valores.length; m++) {
                        val += valores[m].toString() + ", ";
                    }
                    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                } else {
                    for (int mm = 0; mm < lista.getModel().getSize(); mm++) {
                        val += lista.getModel().getElementAt(mm).toString() + ", ";
                    }
                    reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT, val, 750, 560, 0);
                }
            }
        }

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        if (op == 1) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Controlador.ControladorClasificacion.java

/**
 * Mtodo generarPDF que genera el PDF con la clasificacin al pulsar el
 * botn generar PDF// w  ww .j  a  va  2 s.c o  m
 *
 * @throws FileNotFoundException salta la excepcion
 * @throws DocumentException salta la excepcion
 * @throws IOException salta la excepcion
 */
public void generarPDF() throws FileNotFoundException, DocumentException, IOException {

    Calendar cal = Calendar.getInstance();
    String time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(cal.getTime());

    File file = new File("Clasificacion.pdf");
    FileOutputStream fileout = new FileOutputStream(file.getAbsolutePath());
    Document document = new Document();
    PdfWriter.getInstance(document, fileout);

    Font fuente1 = new Font();
    Font fuente2 = new Font();
    Font fuente3 = new Font();
    fuente1.setStyle(Font.BOLD | Font.ITALIC | Font.UNDERLINE);
    fuente1.setSize(18);
    fuente1.setColor(0, 51, 204);
    fuente2.setStyle(Font.BOLD | Font.ITALIC);
    fuente2.setColor(0, 51, 204);
    fuente2.setSize(13);
    fuente3.setStyle(Font.BOLD | Font.ITALIC);
    fuente3.setSize(16);
    fuente3.setColor(255, 153, 0);

    document.open();

    Paragraph pa = new Paragraph("Fecha y hora: " + time);

    pa.setAlignment(Element.ALIGN_RIGHT);
    document.add(pa);

    /*String url = "imagenPDF.jpg";
    File file2 = new File(url);
    FileInputStream filein = new FileInputStream(file2.getAbsolutePath());
    //String url = "./imagenPDF.jpg";
    Image imagen = Image.getInstance(filein.getFD());  
    //System.out.println(file2.getAbsolutePath());
    imagen.scalePercent(20);
    document.add(imagen);*/
    document.add(new Paragraph("\n"));
    Paragraph p3 = new Paragraph("GESTOR DE CAMPEONATO DE BALONCESTO", fuente1);
    p3.setAlignment(Element.ALIGN_CENTER);
    document.add(p3);

    document.add(new Paragraph("\n"));
    String tipo_competicion = FicherosTipo.leerFichero();

    if (tipo_competicion.contains("Copa")) {
        Paragraph pa1 = new Paragraph("COPA", fuente3);
        pa1.setAlignment(Element.ALIGN_CENTER);
        document.add(pa1);
        document.add(new Paragraph(
                "---------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph("\n"));
        int jornada_maxima = PartidoDAO.obtenerJornadaActual();

        for (int i = jornada_maxima; i > 0; i--) {
            List<Partido> listarPartidosJornada = PartidoDAO.listarPartidosJornada(i);
            for (Partido p : listarPartidosJornada) {

                List<PartidoJugado> listarEquiposporPartido = PartidoJugadoDAO
                        .listarEquiposporPartido(p.getIdPartido());

                int equipoA = listarEquiposporPartido.get(0).getIdEquipo();
                int equipoB = listarEquiposporPartido.get(1).getIdEquipo();

                Paragraph p2 = new Paragraph(
                        "Equipo A: " + EquipoDAO.obtenerNombreEquipo(equipoA) + " - Equipo B: "
                                + EquipoDAO.obtenerNombreEquipo(equipoB) + " - Resultado: " + p.getResultado(),
                        fuente2);
                p2.setAlignment(Element.ALIGN_LEFT);
                document.add(p2);
            }

        }

    } else if (tipo_competicion.contains("Liga")) {
        Paragraph pa1 = new Paragraph("LIGA", fuente3);
        pa1.setAlignment(Element.ALIGN_LEFT);
        document.add(pa1);
        document.add(new Paragraph(
                "---------------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph("\n"));
        List<Equipo> obtenerTodosEquipos = EquipoDAO.obtenerTodosEquipos();
        Collections.sort(obtenerTodosEquipos);
        System.out.println(obtenerTodosEquipos);
        for (Equipo p : obtenerTodosEquipos) {
            Paragraph pa2 = new Paragraph(p.getNombre(), fuente2);
            pa2.setAlignment(Element.ALIGN_LEFT);
            document.add(pa2);
        }

    }
    document.close();
    File myfile = new File("Clasificacion.pdf");
    Desktop.getDesktop().open(myfile);
}

From source file:Controlador.ControladorCrearPase.java

public void generaPDF(String Prueba, String Causa, Integer idCita, Integer idPaciente, Integer idPersona)
        throws FileNotFoundException, DocumentException, IOException {

    Calendar cal = Calendar.getInstance();
    String time = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(cal.getTime());
    String timename = new SimpleDateFormat("yyyyMMddHHmm").format(cal.getTime());

    File file = new File("PaseServicio" + timename + ".pdf");
    FileOutputStream fileout = new FileOutputStream(file);
    Document document = new Document();
    PdfWriter writer;/*  w w w. j  a  v  a  2 s  .c  o  m*/
    writer = PdfWriter.getInstance(document, fileout);

    Font fuente = new Font();
    Font fuente2 = new Font();
    Font fuente3 = new Font();

    // fuente.setColor(BaseColor.BLUE);
    fuente.setStyle(Font.UNDERLINE | Font.BOLDITALIC);
    fuente2.setStyle(Font.BOLD);
    fuente2.setSize(12);
    fuente3.setSize(20);
    fuente3.setStyle(Font.BOLD);

    document.open();
    document.add(new Paragraph("\n \n \n \n \n"));
    document.add(new Paragraph("Clinica Mdica INFTEL", fuente3));

    String imageUrl = "src/Imagen/logo.png";
    //  String imagen="src\Imagen\logo.png"; 
    Image image = Image.getInstance(imageUrl);
    image.setAbsolutePosition(300, 750);
    image.scalePercent(80f);
    document.add(image);

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

    document.add(new Paragraph("DATOS DEL PACIENTE", fuente));
    document.add(new Paragraph(" "));
    document.add(
            new Paragraph("Apellidos y Nombre : " + paciente.getApellidos() + ", " + paciente.getNombre()));
    document.add(new Paragraph("NIF : " + paciente.getNif()));
    document.add(new Paragraph("NSS : " + paciente.getNumSS()));
    document.add(new Paragraph("Direccion : " + paciente.getDireccion()));
    document.add(new Paragraph("Telefono : " + paciente.getTelefono()));
    document.add(new Paragraph("Email : " + paciente.getEmail()));
    document.add(new Paragraph("ID Paciente : " + idPaciente));

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

    document.add(new Paragraph("DATOS ", fuente));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Prueba : ", fuente2));
    document.add(new Paragraph(Prueba));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    document.add(new Paragraph("Causa : ", fuente2));
    document.add(new Paragraph(Causa));
    document.add(new Paragraph(" "));
    document.add(new Paragraph(" "));

    absText(writer, time, 450, 50);

    document.close();
    File myfile = new File("PaseServicio" + timename + ".pdf");
    Desktop.getDesktop().open(myfile);
}

From source file:Controlador.EmailWithPdf.java

/**
 * Writes the content of a PDF file (using iText API)
 * to the {@link OutputStream}.// ww  w  . j a  v  a2s  . c  o m
 * @param outputStream {@link OutputStream}.
 * @throws Exception
 */
public void writePdf(OutputStream outputStream) throws Exception {
    Document document = new Document(PageSize.LETTER, 50, 50, 50, 30);
    Font boldFontTitulo = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
    Font boldFontTexto = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
    Font FontTexto = new Font(Font.FontFamily.HELVETICA, 12);

    // document.setPageSize(null);
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    Image imagen = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\BSeguroLogo.png");
    Image imagen2 = Image.getInstance("D:\\ALEX\\Bseguros\\web\\img\\Aseguradoras\\mapfre.png");

    DateFormat df = new SimpleDateFormat("dd/MM/YYYY");
    Calendar cdos = Calendar.getInstance();
    Date datediamas = new Date();
    Date dateaniomas = new Date();
    cdos.add(Calendar.DATE, 1);
    datediamas = cdos.getTime();
    String fechadiamas = df.format(datediamas);
    cdos.add(Calendar.YEAR, 1);
    dateaniomas = cdos.getTime();
    String fechavencimiento = df.format(dateaniomas);
    document.open();

    PdfContentByte canvas = writer.getDirectContent();
    Rectangle rect = new Rectangle(36, 36, 579, 756);
    rect.setBorder(Rectangle.BOX);
    rect.setBorderWidth(2);
    canvas.rectangle(rect);

    //         Rectangle rect= new Rectangle(36,108);
    //         rect.setBorder(Rectangle.BOX);
    //         
    //rect.setBorderColor(BaseColor.BLACK);
    //rect.setBorderWidth(2);
    //document.add(rect);
    document.addTitle("Cotizacion");
    document.addSubject("Cotizacion");
    document.addKeywords("Cotizacion, seguros");
    document.addAuthor("BSeguro");
    document.addCreator("Bseguro");

    imagen.scaleAbsoluteHeight(30f);
    imagen.setAbsolutePosition(45f, 720f);
    imagen2.scaleAbsoluteHeight(30f);
    imagen2.setAbsolutePosition(450f, 720f);
    document.add(imagen);
    document.add(imagen2);

    Paragraph paragraph2 = new Paragraph("DATOS DE TU POLIZA" + fechadiamas + " hasta: " + fechavencimiento,
            boldFontTitulo);
    Paragraph paragraph3 = new Paragraph(
            "DhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhATOS DE TU POLIZA",
            boldFontTitulo);

    paragraph2.setAlignment(Element.ALIGN_CENTER);

    document.add(paragraph2);
    document.add(paragraph3);

    document.close();

}

From source file:Controlador.PDF.java

public String escribePDF(String nombre) {
    FileOutputStream ficheroPdf = null;

    Random r = new Random();
    r.setSeed(System.currentTimeMillis());

    String f_nombre = "cons" + nombre + r.nextInt(9000) + ".pdf";

    try {//from w  w w . ja  v a  2s . c  o  m

        Document documento = new Document();

        String basePath = new File("").getAbsolutePath();
        String[] parts = basePath.split("/");

        final String path = "/" + parts[1] + "/" + parts[2] + "/NetBeansProjects/pag_ingles/web/" + f_nombre;
        ficheroPdf = new FileOutputStream(path);

        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        documento.open();

        Image foto = Image.getInstance(
                "/" + parts[1] + "/" + parts[2] + "/NetBeansProjects/pag_ingles/web/img/escuela.png");
        foto.scaleToFit(200, 200);
        foto.setAlignment(Chunk.ALIGN_RIGHT);
        documento.add(foto);
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));

        documento.add(new Paragraph("Darktech Anglo Institute",
                FontFactory.getFont("Courier-Bold", 30, Font.UNDERLINE, BaseColor.BLUE)));

        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));

        documento.add(new Paragraph("        OTORGA LA PRESENTEaaa",
                FontFactory.getFont("ARIAL", 30, Font.NORMAL, BaseColor.BLACK)));

        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));

        documento.add(new Paragraph("            CONSTANCIA",
                FontFactory.getFont("ARIAL", 30, Font.NORMAL, BaseColor.BLACK)));

        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));

        documento.add(new Paragraph("  A :       " + nombre,
                FontFactory.getFont("ARIAL", 20, Font.BOLD, BaseColor.BLACK)));

        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));
        documento.add(new Paragraph("           "));

        documento.add(new Paragraph("POR HABER CONCLUIDO CON EXITO EL CURSO DE INGLES.",
                FontFactory.getFont("ARIAL", 14, Font.NORMAL, BaseColor.BLACK)));

        documento.close();
        ficheroPdf.close();

        Thread.sleep(3000);

    } catch (DocumentException | FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();

    } catch (InterruptedException ex) {
        Logger.getLogger(PDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            ficheroPdf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return f_nombre;
}

From source file:controlador.PDFServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w w w.j  a  v a 2  s . c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, BadElementException, DocumentException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        this.cliente = new ClienteDAO();

        ArrayList c = cliente.listarTodo();

        FileOutputStream archivo = new FileOutputStream(
                "C:\\Users\\ayoro\\OneDrive\\Documents\\NetBeansProjects\\Proyecto2\\ExpoturismoDriver\\archivo.pdf");
        Document documento = new Document();
        PdfWriter.getInstance(documento, archivo);
        documento.open();
        documento.add(new Paragraph("Clientes!"));
        documento.add(new Paragraph("Pruebita del primer pdf", FontFactory.getFont("arial", // fuente
                22, // tamao
                Font.ITALIC, // estilo
                BaseColor.CYAN))); // color

        documento.add(
                new Paragraph("Nueva tablita", FontFactory.getFont("arial", 28, Font.BOLD, BaseColor.BLUE)));
        documento.add(Chunk.NEWLINE);
        PdfPTable tabla = new PdfPTable(4);
        Paragraph ced = new Paragraph("Cdula", FontFactory.getFont("arial", 12, Font.BOLD, BaseColor.BLACK));
        Paragraph nom = new Paragraph("Nombre", FontFactory.getFont("arial", 12, Font.BOLD, BaseColor.BLACK));
        Paragraph cor = new Paragraph("Correo", FontFactory.getFont("arial", 12, Font.BOLD, BaseColor.BLACK));
        Paragraph tel = new Paragraph("Telfono",
                FontFactory.getFont("arial", 12, Font.BOLD, BaseColor.BLACK));
        tabla.addCell(ced);
        tabla.addCell(nom);
        tabla.addCell(cor);
        tabla.addCell(tel);

        for (int i = 0; i < c.size(); i += 4) {
            tabla.addCell("" + c.get(i));
            tabla.addCell((String) c.get(i + 1));
            tabla.addCell((String) c.get(i + 2));
            tabla.addCell("" + c.get(i + 3));
        }
        documento.add(tabla);
        documento.add(new Paragraph("Finito"));
        documento.add(new Paragraph("Prueba 2"));
        documento.close();

        response.sendRedirect("opciones.jsp");
    }
}

From source file:ControleurClients.ControleurClients.java

private void pageCommandes(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DocumentException {
    request.setAttribute("attente", commandef.getAttente(clientConnect));
    request.setAttribute("cours", commandef.getCours(clientConnect));
    request.setAttribute("effectuee", commandef.getEffectuee(clientConnect));

    List<Commande> attente = commandef.getAttente();
    List<Commande> cours = commandef.getCours();
    List<Commande> effectue = commandef.getEffectuee();
    if (!attente.isEmpty()) {
        for (Commande c : attente) {
            Document document1 = new Document();
            PdfWriter.getInstance(document1,
                    new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente"
                            + c.getId().toString() + ".pdf"));

            document1.open();//from  w  ww.jav  a 2 s.c om
            Paragraph text = new Paragraph();
            text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("En attente : Commande n" + c.getId().toString(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));

            document1.add(text);

            Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC));
            p.setAlignment(Element.ALIGN_RIGHT);
            p.add(new Paragraph(" "));
            p.add(new Paragraph(" "));
            document1.add(p);

            Paragraph text1 = new Paragraph();
            text1.add(new Paragraph(
                    "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase()
                            + c.getClient().getNom().substring(1) + " "
                            + c.getClient().getPrenom().substring(0, 1).toUpperCase()
                            + c.getClient().getPrenom().substring(1),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            text1.add(new Paragraph("Email: " + c.getClient().getEmail(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));

            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));

            document1.add(text1);

            PdfPTable table = new PdfPTable(3);
            //On crer l'objet cellule.
            PdfPCell cell;

            cell = new PdfPCell(new Phrase("Facture"));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("Nom du Dvd"));
            cell.setRowspan(1);
            table.addCell(cell);
            //contenu du tableau.
            table.addCell("Quantit");
            table.addCell("Prix");

            for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) {

                Dvd dvd = (Dvd) entry.getKey();
                Object value = entry.getValue();
                //Image dvdimage = Image.getInstance(dvd.getImage());
                //On crer un objet table dans lequel on intialise a taille.

                cell = new PdfPCell(new Phrase(dvd.getTitre()));
                cell.setRowspan(1);
                table.addCell(cell);

                table.addCell(String.valueOf(value));
                table.addCell(String.valueOf(dvd.getPrix()));

            }

            cell = new PdfPCell(new Phrase("Total: " + String.valueOf(c.getMontant()) + " "));
            cell.setColspan(3);

            table.addCell(cell);

            document1.add(table);
            Paragraph p1 = new Paragraph();
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble",
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            p1.setAlignment(Element.ALIGN_RIGHT);
            document1.add(p1);
            document1.close();
        }
    }

    if (!cours.isEmpty()) {
        for (Commande c : cours) {
            Document document1 = new Document();
            PdfWriter.getInstance(document1,
                    new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours"
                            + c.getId().toString() + ".pdf"));

            document1.open();
            Paragraph text = new Paragraph();
            text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("En cours : Commande n" + c.getId().toString(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));

            document1.add(text);

            Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC));
            p.setAlignment(Element.ALIGN_RIGHT);
            p.add(new Paragraph(" "));
            p.add(new Paragraph(" "));
            document1.add(p);

            Paragraph text1 = new Paragraph();
            text1.add(new Paragraph(
                    "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase()
                            + c.getClient().getNom().substring(1) + " "
                            + c.getClient().getPrenom().substring(0, 1).toUpperCase()
                            + c.getClient().getPrenom().substring(1),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            text1.add(new Paragraph("Email: " + c.getClient().getEmail(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));

            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));

            document1.add(text1);

            PdfPTable table = new PdfPTable(3);
            //On crer l'objet cellule.
            PdfPCell cell;

            cell = new PdfPCell(new Phrase("Facture"));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("Nom du Dvd"));
            cell.setRowspan(1);
            table.addCell(cell);
            //contenu du tableau.
            table.addCell("Quantit");
            table.addCell("Prix");

            for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) {

                Dvd dvd = (Dvd) entry.getKey();
                Object value = entry.getValue();
                //Image dvdimage = Image.getInstance(dvd.getImage());
                //On crer un objet table dans lequel on intialise a taille.

                cell = new PdfPCell(new Phrase(dvd.getTitre()));
                cell.setRowspan(1);
                table.addCell(cell);

                table.addCell(String.valueOf(value));
                table.addCell(String.valueOf(dvd.getPrix()));

            }

            cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " "));
            cell.setColspan(3);

            table.addCell(cell);

            document1.add(table);
            Paragraph p1 = new Paragraph();
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble",
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            p1.setAlignment(Element.ALIGN_RIGHT);
            document1.add(p1);
            document1.close();
        }
    }

    if (!effectue.isEmpty()) {
        for (Commande c : effectue) {
            new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente" + c.getId().toString()
                    + ".pdf").delete();
            new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours" + c.getId().toString()
                    + ".pdf").delete();

            Document document1 = new Document();
            PdfWriter.getInstance(document1,
                    new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/effectue"
                            + c.getId().toString() + ".pdf"));

            document1.open();
            Paragraph text = new Paragraph();
            text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));
            text.add(new Paragraph("Effectue : Commande n" + c.getId().toString(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)));
            text.add(new Paragraph(" "));
            text.add(new Paragraph(" "));

            document1.add(text);

            Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC));
            p.setAlignment(Element.ALIGN_RIGHT);
            p.add(new Paragraph(" "));
            p.add(new Paragraph(" "));
            document1.add(p);

            Paragraph text1 = new Paragraph();
            text1.add(new Paragraph(
                    "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase()
                            + c.getClient().getNom().substring(1) + " "
                            + c.getClient().getPrenom().substring(0, 1).toUpperCase()
                            + c.getClient().getPrenom().substring(1),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            text1.add(new Paragraph("Email: " + c.getClient().getEmail(),
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));

            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));
            text1.add(new Paragraph(" "));

            document1.add(text1);

            PdfPTable table = new PdfPTable(3);
            //On crer l'objet cellule.
            PdfPCell cell;

            cell = new PdfPCell(new Phrase("Facture"));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase("Nom du Dvd"));
            cell.setRowspan(1);
            table.addCell(cell);
            //contenu du tableau.
            table.addCell("Quantit");
            table.addCell("Prix");

            for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) {

                Dvd dvd = (Dvd) entry.getKey();
                Object value = entry.getValue();
                //Image dvdimage = Image.getInstance(dvd.getImage());
                //On crer un objet table dans lequel on intialise a taille.

                cell = new PdfPCell(new Phrase(dvd.getTitre()));
                cell.setRowspan(1);
                table.addCell(cell);

                table.addCell(String.valueOf(value));
                table.addCell(String.valueOf(dvd.getPrix()));

            }

            cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " "));
            cell.setColspan(3);

            table.addCell(cell);

            document1.add(table);

            Paragraph p1 = new Paragraph();
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" "));
            p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble",
                    new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)));
            p1.setAlignment(Element.ALIGN_RIGHT);
            document1.add(p1);
            document1.close();
        }

    }

    getServletContext().getRequestDispatcher("/WEB-INF/Commande.jsp").forward(request, response);
}