Example usage for com.itextpdf.text Image setAlignment

List of usage examples for com.itextpdf.text Image setAlignment

Introduction

In this page you can find the example usage for com.itextpdf.text Image setAlignment.

Prototype


public void setAlignment(final int alignment) 

Source Link

Document

Sets the alignment for the image.

Usage

From source file:GUI.FacturasUsuariosGUI.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    try {//ww w. j a  v  a2s.  c  o m
        int fila = listarFacturas.getSelectedRow();
        if (fila != -1) {
            String cedula = (String) modeloFacturas.getValueAt(fila, 1);
            String numeroFactura = (String) modeloFacturas.getValueAt(fila, 0);

            SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Usuario u = us.recuperarUsuario(cedula);
            LinkedList<Factura> f = fs.recuperarFacturas(cedula);

            com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.LETTER, 50, 50, 50,
                    50);
            Image imagen, publicidad;
            imagen = Image.getInstance("src//IMG//logohd.png");
            imagen.setAlignment(Element.ALIGN_CENTER);
            imagen.scalePercent(60f);

            //publicidad
            //            publicidad = Image.getInstance("LOGO.png");
            //            publicidad.setAlignment(Element.ALIGN_CENTER);
            //            publicidad.scalePercent(40f);
            //            Document doc = new Document();
            //            PdfWriter
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("factura.pdf"));
            document.open();
            document.add(imagen);
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "|                                                   FACTURAS PARQUEADERO                                                   |"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("RUC: 0102030405067 "));
            document.add(new Paragraph("Numero Fact: 00000" + numeroFactura));
            document.add(new Paragraph("Cliente : " + u.getNombre() + " " + u.getApellido()));
            document.add(new Paragraph("N de cdula : " + u.getCedula()));
            document.add(
                    new Paragraph("Fecha : " + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("Placas : " + u.getVehiculo().getPlaca()));
            document.add(new Paragraph("Marca : " + u.getVehiculo().getMarca()));
            document.add(new Paragraph("Modelo : " + u.getVehiculo().getModelo()));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "| N |    FECHA Y HORA DE ENTRADA    |    FECHA Y HORA DE SALIDA    |      TIEMPO       |"));
            for (int i = 0; i < f.get(fila).getListaDetalleFacturas().size(); i++) {
                document.add(new Paragraph("|  " + (i + 1) + "  |             "
                        + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraEntrada())
                        + "             |            "
                        + fecha.format(f.get(fila).getListaDetalleFacturas().get(i).getFechaHoraSalida())
                        + "          |      " + f.get(fila).getListaDetalleFacturas().get(i).getTiempo()
                        + "      |"));
            }
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph("              Subtotal : " + f.get(fila).getSubtotal()));
            document.add(new Paragraph("              Iva : " + f.get(fila).getIva()));
            document.add(new Paragraph("              Total : " + f.get(fila).getTotal()));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.add(new Paragraph(
                    "____________________________________________________________________________"));
            document.close();
            File path = new File("factura.pdf");
            Desktop.getDesktop().open(path);
            this.setVisible(false);
            new ParqueaderoMAINGUI().setVisible(true);
        } else {
            JOptionPane.showMessageDialog(this, "Para generar un pdf debe seleccionar alguna factura");
        }
    } catch (Exception e) {
    }
}

From source file:GUI.Framenewventa.java

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

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {//from   w ww.  jav a2  s. c  o  m

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);
            ;
            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:GUI.frameNewVentaKit.java

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

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {/*from   www .  jav  a2 s  . co m*/

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);

            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:ihm.panneaux.GenererPdf.java

private void initComponement() throws FileNotFoundException, DocumentException, IOException {
    String DEST = "devis/devis-" + devis.getNumero() + ".pdf";
    OutputStream file = new FileOutputStream(new File(DEST));

    com.itextpdf.text.Document document = new com.itextpdf.text.Document();
    PdfWriter.getInstance((com.itextpdf.text.Document) document, file);
    // PAS TOUCHE
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));

    Rectangle rect = new Rectangle(30, 30, 550, 800);
    writer.setBoxSize("art", rect);
    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    writer.setPageEvent(event);/*from   w  ww  .  j a v a  2  s . c om*/
    document.open();
    PdfContentByte canvas = writer.getDirectContent();

    Image logo = Image.getInstance("images/logo.png");
    logo.scaleAbsolute(200, 57);

    // INFO DEVIS
    Image devisImg = Image.getInstance("images/imgDevis.png");
    devisImg.scaleAbsolute(110, 34);
    devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150),
            (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2);
    Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Phrase numeroInfo = new Phrase("Numro  " + devis.getNumero(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413,
            devisImg.getScaledHeight() + 710, 0);
    Phrase dateInfo = new Phrase("Le  " + devis.getDate(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420,
            devisImg.getScaledHeight() + 695, 0);
    Image devisImgBordure = Image.getInstance("images/bordureDevis.png");
    devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660);
    devisImgBordure.scaleAbsolute(120, 122);

    // INFO ENTREPRISE
    Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD);
    Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210,
            devisImg.getScaledHeight() + 660, 0);
    Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149,
            devisImg.getScaledHeight() + 640, 0);
    Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113,
            devisImg.getScaledHeight() + 625, 0);
    Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png");
    bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610);

    // INFO CLIENT
    Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL);
    Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient);
    Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient);
    Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(),
            fontClient);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 595, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 580, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 565, 0);

    document.add(logo);
    document.add(devisImg);
    document.add(devisImgBordure);
    document.add(bordureEntreprise);

    // AJOUT DES DONNEES DU TABLEAUX 

    float[] columnWidths = { 14, 3, 4, 3, 4 };
    Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    fontCategorie.setColor(BaseColor.GREEN);

    PdfPTable table = new PdfPTable(columnWidths);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    table.setTotalWidth(PageSize.A4.getWidth() - 15);

    table.setSpacingBefore(150);

    table.setLockedWidth(true);

    Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD);
    Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE);

    PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier));
    cellChantier.setColspan(3);
    cellChantier.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellChantier);
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(new Phrase("Dsignation", Categorie));
    PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie));
    PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie));
    PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie));
    PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie));

    unite.setHorizontalAlignment(Element.ALIGN_CENTER);
    quantite.setHorizontalAlignment(Element.ALIGN_CENTER);
    prixht.setHorizontalAlignment(Element.ALIGN_CENTER);
    pvtht.setHorizontalAlignment(Element.ALIGN_CENTER);

    unite.setBorder(Rectangle.NO_BORDER);
    quantite.setBorder(Rectangle.NO_BORDER);
    prixht.setBorder(Rectangle.NO_BORDER);
    pvtht.setBorder(Rectangle.NO_BORDER);

    table.addCell(unite);
    table.addCell(quantite);
    table.addCell(prixht);
    table.addCell(pvtht);

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    double htTotalParcour = 0;
    double ttcTotalParcour = 0;

    if (this.EquipementDeChantier.isEmpty() == false) {
        table.addCell(new Phrase("Equipement De Chantier", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

        for (DevisContenu listeMaterielDevi : EquipementDeChantier) {

            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            /* BACKUP
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            table.addCell(listeMaterielDevi.getMateriel().getUnite());
            table.addCell(Double.toString(listeMaterielDevi.getQuantite()));
            table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+"");
            table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+"");
            */
            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Couverture.isEmpty() == false) {
        table.addCell(new Phrase("Couverture", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Couverture) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureArdoise.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Ardoise", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureArdoise) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureTuile.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Tuile", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureTuile) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (this.Demoussage.isEmpty() == false) {
        table.addCell(new Phrase("Demoussage", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Demoussage) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Velux.isEmpty() == false) {
        table.addCell(new Phrase("Velux", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Velux) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Zinguerie.isEmpty() == false) {
        table.addCell(new Phrase("Zinguerie", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Zinguerie) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Plancher.isEmpty() == false) {
        table.addCell(new Phrase("Plancher", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Plancher) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }

    ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour;

    LineDash solid = new SolidLine();
    PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc;

    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(new CustomBorder(null, null, null, solid));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL"));
    cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellSOUSTOTAL);
    table.addCell(new Phrase(""));
    double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2);
    String httotal = String.valueOf(prixHT_2Chiffre);
    cellhttotal = new PdfPCell(new Phrase(httotal + ""));
    cellhttotal.setBorder(Rectangle.NO_BORDER);
    cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cellhttotal);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    tva = new PdfPCell(new Phrase("TVA"));
    tva.setBorder(Rectangle.NO_BORDER);
    tva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(tva);

    getTva = new PdfPCell(new Phrase(devis.getTva() + "%"));
    getTva.setBorder(Rectangle.NO_BORDER);
    getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(getTva);

    String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100);
    double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2);
    cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + ""));
    cell2.setBorder(PdfPCell.NO_BORDER);
    cell2.setCellEvent(new CustomBorder(null, null, null, solid));
    cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell2);

    table.addCell("");
    table.addCell("");
    totalttc = new PdfPCell(new Phrase("Total TTC"));
    totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    totalttc.setBorder(PdfPCell.NO_BORDER);
    table.addCell(totalttc);
    table.addCell("");
    double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2);
    String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre));
    gettotalttc = new PdfPCell(new Phrase(ttctotal + ""));
    gettotalttc.setBorder(PdfPCell.NO_BORDER);
    gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(gettotalttc);

    table.setSpacingAfter(10);

    document.add(table);

    Pattern p = Pattern.compile("[.^\\.]+");
    String texte = devis.getInformationComplementaire();

    Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlue.setColor(BaseColor.BLUE);
    Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptRed.setColor(BaseColor.RED);
    Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlack.setColor(BaseColor.BLACK);

    Paragraph infoComp = new Paragraph();
    Image BonPourAccord = null;
    BonPourAccord = Image.getInstance("images/BonPourAccord.png");
    infoComp.setAlignment(Element.ALIGN_LEFT);
    BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT);

    String[] phrase = p.split(texte);
    for (int i = 0; i < phrase.length; i++) {
        if (i == 0 || i == 1) {
            infoComp.add(new Paragraph(phrase[i], infoComptBlue));
        }
        if (i == 2 || i == 3 || i == 4 || i == 5) {
            infoComp.add(new Paragraph(phrase[i], infoComptRed));

        }
        if (i > 5 && i <= 11)
            infoComp.add(new Paragraph(phrase[i], infoComptBlack));
        if (i > 11)
            infoComp.add(new Paragraph(phrase[i], infoComptRed));
    }
    /* A OPTIMISER */

    float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex());

    if (taille_tableau > 386) {
        document.newPage();
    }
    document.add(BonPourAccord);
    document.add(infoComp);

    document.close();

    EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis);
    this.CouvertureArdoise.clear();
    this.CouvertureTuile.clear();
    this.Demoussage.clear();
    this.EquipementDeChantier.clear();
    this.Velux.clear();
    this.Zinguerie.clear();
    this.Couverture.clear();
    this.Plancher.clear();
}

From source file:interfaz.pdf.java

public static void addImagen(Document document) throws DocumentException, BadElementException, IOException {
    Image imagen = Image.getInstance("src/imagenes/cwm2.jpg");
    imagen.setAlignment(Element.ALIGN_CENTER);
    document.add(imagen);/* w ww  .  j  a  v  a 2 s .  c  o  m*/
}

From source file:io.github.nick11roberts.pdf_drive.PreviewActivity.java

License:Open Source License

public void addImagesToPDF() throws Exception {
    Document document = new Document();
    ByteArrayOutputStream stream;
    Bitmap bmpImage;/*w  w w.  j a v a  2s.c  o m*/
    byte[] imagebytes;
    Image image;
    float scaler;
    PdfWriter.getInstance(document, new FileOutputStream(tmpPdfFile));
    document.open();
    for (int i = camIndex - 1; i >= 0; i--) {
        stream = new ByteArrayOutputStream();
        bmpImage = Bitmap.createBitmap(imagesFromCamera.get(i));
        //bmpImage = rotateImage(bmpImage, -90);         
        bmpImage.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        imagebytes = stream.toByteArray();
        image = Image.getInstance(imagebytes);
        scaler = ((document.getPageSize().getWidth()) / image.getWidth()) * 100;
        image.scalePercent(scaler);
        image.setAlignment(Image.MIDDLE | Image.ALIGN_MIDDLE);
        document.add(image);
        document.newPage();
        stream.close();
        stream = null;
    }

    document.close();
}

From source file:itextpdf.GeneratePdf.java

License:Minecraft Mod Public

public void addPhoto(String photoName) {
    try {//w  w  w  .  j  av  a  2 s.c om
        Image image = Image.getInstance(photoName);
        image.scaleToFit(400, 400);
        image.setAlignment(Chunk.ALIGN_MIDDLE);
        document.add(image);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Login.ventas.fproyectos.java

public void fondos(Document documento, PdfContentByte canvas) {
    try {/*from  w ww  . j a  v a2s .  co m*/
        Image imghead = Image.getInstance(usuario.getDireccion() + "/plantilla.jpg");
        imghead.setAbsolutePosition(0, 0);
        imghead.setAlignment(Image.ALIGN_CENTER);
        float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin())
                / imghead.getWidth()) * 100;
        imghead.scalePercent(scaler);
        PdfTemplate tp = canvas.createTemplate(PageSize.A4.getWidth(), PageSize.A4.getHeight()); //el rea destinada para el encabezado
        tp.addImage(imghead);
        x = (int) imghead.getWidth();
        y = (int) imghead.getHeight();
        canvas.addTemplate(tp, 0, 0);//posicin del tmplate derecha y abajo
    } catch (IOException | DocumentException io) {

    }
}

From source file:model.PDFModel.java

License:Open Source License

public void createDailyPDF(String fileName, String date)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {
    Document pdf = new Document();
    PdfWriter.getInstance(pdf, new FileOutputStream(fileName));

    Paragraph tittle = new Paragraph("RESTAURACJA LITERA");
    tittle.setAlignment(Element.ALIGN_CENTER);

    Image logo = Image.getInstance("logo.png");
    logo.setAlignment(Element.ALIGN_RIGHT);

    Paragraph headerParagraph = new Paragraph("Raport Dzienny " + date);
    headerParagraph.setAlignment(Element.ALIGN_CENTER);

    pdf.open();/*from   w w w .  jav a  2s .  c o  m*/
    pdf.add(logo);
    pdf.add(tittle);
    pdf.add(new Paragraph(" "));
    pdf.add(headerParagraph);
    for (int i = 0; i < 10; i++) {
        pdf.add(createTablePDFTable(i + 1, date));
    }
    pdf.add(createDailyTable(date));
    pdf.close();
    System.out.println("closed");
}

From source file:modelo.DTO.PDF_Registro2.java

public static void generar() throws DocumentException, FileNotFoundException, BadElementException, IOException {
    Rectangle pageSize = new Rectangle(816f, 1056f); //ancho y alto
    miPDF = new Document(pageSize, 0, 0, 0, 0);

    PdfWriter.getInstance(miPDF, new FileOutputStream(PDF_Registro2.rutaDestino + ".pdf"));
    miPDF.open();//  w  w w .  j  a  v  a2  s. co m
    miPDF.addTitle("Registro");
    miPDF.addAuthor("Universidad Tecnolgica de Len");
    miPDF.addSubject("Constancia de Registro");
    miPDF.addKeywords("1");

    //Inicio
    //Image foto = Image.getInstance("src/imagens/Registro.png");
    String thisIp = InetAddress.getLocalHost().getHostAddress();
    Image foto = Image.getInstance("http://" + thisIp + ":8084/ExamenParcial2Web/imagenes/Registro.png");
    foto.setAlignment(Chunk.ALIGN_MIDDLE);
    foto.scaleToFit(816, 754);

    miPDF.add(foto);
    PdfPTable ta = new PdfPTable(2);
    PdfPCell celda;

    celda = new PdfPCell(new Paragraph("\nClave:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + clave + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nNombre:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + nombre + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nE-mail:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + email + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    celda = new PdfPCell(new Paragraph("\nUT:\n\n", FontFactory.getFont("arial", 12, Font.BOLD)));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);
    celda = new PdfPCell(new Paragraph("\n" + procedencia + "\n\n"));
    celda.setBorderColor(BaseColor.WHITE);
    ta.addCell(celda);

    miPDF.add(ta);
    miPDF.close();

    //Fin 
    miPDF.close();
}