Example usage for com.lowagie.text Image scaleAbsolute

List of usage examples for com.lowagie.text Image scaleAbsolute

Introduction

In this page you can find the example usage for com.lowagie.text Image scaleAbsolute.

Prototype

public void scaleAbsolute(float newWidth, float newHeight) 

Source Link

Document

Scale the image to an absolute width and an absolute height.

Usage

From source file:jm.nom.clas.Carnet.java

public void onEndPage(PdfWriter writer, Document document) {
    try {// w ww.  j  a  v a  2s  . c om
        //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\";
        Image imagelogo = Image.getInstance(_dir + "fondocarnet.jpg");
        imagelogo.scaleAbsolute(860, 625);//ancho, alto
        imagelogo.setAbsolutePosition(0, 10);
        document.add(imagelogo);
    } catch (DocumentException ex) {
        Logger.getLogger(pdfEmpleadosCarnets.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(pdfEmpleadosCarnets.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setLogo(String logo, int ancho, int alto) {
    PdfPCell celdaImg = null;/*from   w  ww  .jav  a 2s.c  o m*/
    try {
        Image imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(ancho, alto);
        celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setPadding(0);
    } catch (Exception e) {
        celdaImg = null;
    }
    return celdaImg;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setLogo(String logo, int ancho, int alto, int alineacion) {
    PdfPCell celdaImg = null;//from w  w w .j  a v a2 s.  c om
    try {
        Image imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(ancho, alto);
        celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setHorizontalAlignment(alineacion);
        celdaImg.setPadding(0);
    } catch (Exception e) {
        celdaImg = null;
    }
    return celdaImg;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setLogoCarnet(String logo, int ancho, int alto) {
    PdfPCell celdaImg = null;//  ww w . j a  v a2  s.  c  o  m
    try {
        Image imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(ancho, alto);
        celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setPadding(0);
        celdaImg.setPaddingLeft(50);
    } catch (Exception e) {
        celdaImg = null;
    }
    return celdaImg;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static Image setMarcaAgua(String logo, int ancho, int alto) {
    try {//from   w  ww .  ja v  a  2s  . c o m
        Image imagelogo = Image.getInstance(logo);
        imagelogo.setTransparency(new int[] { 255, 255 });
        imagelogo.setRotationDegrees(57);
        imagelogo.scaleAbsolute(ancho, alto);
        imagelogo.setAbsolutePosition(0, 30);
        return imagelogo;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPTable setCabecera(String logo, String titulo, String ruc, String subtitulo, String direccion,
        String sucursal) {/*from   w ww  .j a va  2s .co  m*/
    PdfPTable encabezado = new PdfPTable(new float[] { 80f, 400f });
    PdfPTable tbl_encab = new PdfPTable(1);
    Image imagelogo = null;
    try {
        imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(150, 70);
        PdfPCell celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setPadding(0);
        encabezado.addCell(celdaImg);
    } catch (Exception e) {
        encabezado.addCell("");
    }
    tbl_encab.addCell(Addons.setCeldaPDF(titulo, Font.HELVETICA, 13, Font.BOLD, Element.ALIGN_CENTER, 0));
    tbl_encab.addCell(Addons.setCeldaPDF(direccion, Font.HELVETICA, 11, Font.NORMAL, Element.ALIGN_CENTER, 0));
    if (ruc.compareTo("") != 0) {
        tbl_encab.addCell(
                Addons.setCeldaPDF("RUC: " + ruc, Font.HELVETICA, 11, Font.NORMAL, Element.ALIGN_CENTER, 0));
    }
    tbl_encab.addCell(Addons.setCeldaPDF(subtitulo, Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_CENTER, 0));

    encabezado.addCell(Addons.setCeldaPDF(tbl_encab, Element.ALIGN_CENTER, 0));

    encabezado.addCell(Addons.setFilaBlanco(2, 6));

    if (sucursal.compareTo("") != 0) {
        encabezado.addCell(Addons.setCeldaPDF("Sucursal: " + sucursal, Font.HELVETICA, 10, Font.NORMAL,
                Element.ALIGN_LEFT, 0, 0, 2));
    }

    encabezado.addCell(Addons.setCeldaPDF("Fecha de impresin: " + Fecha.getFecha("SQL"), Font.HELVETICA, 10,
            Font.NORMAL, Element.ALIGN_LEFT, 0, 0, 2));

    encabezado.addCell(Addons.setFilaBlanco(2, 4));

    return encabezado;
}

From source file:mx.avanti.siract.ui.RACTBeanUI.java

public void postProcessPDF(Object document) throws IOException, DocumentException {
    final Document pdf = (Document) document;
    TreeNode[] selectedNodesPDF = selectedNodes;

    if (selectedNodes != null) {
        for (TreeNode nodo : selectedNodes) {
            System.out.println("*********************" + ((NodoMultiClass) nodo.getData()).getNombre());
        }//  w  w  w  .j  av  a  2 s . c  om
    }
    pdf.setPageSize(PageSize.A4.rotate());
    pdf.open();
    String nombrep = profesor.getPronombre() + " " + profesor.getProapellidoPaterno() + " "
            + profesor.getProapellidoMaterno();
    String numEmpPro = Integer.toString(profesor.getPronumeroEmpleado());
    String porAv = Float.toString(porcentajeAvance);
    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");

    //Obtener el nombre del programa educativo seleccionado
    String nombreProgEdu = "";
    int programaEducativoSeleccionado2 = Integer.parseInt(programaEducativoSeleccionado);
    for (int x = 0; x < programasEducativos.size(); x++) {
        if (programasEducativos.get(x).getPedid() == programaEducativoSeleccionado2) {
            nombreProgEdu = programasEducativos.get(x).getPednombre();
        }
    }
    //----------------------------------------------------------------------------------

    //Obtener el nombre de la unidad de aprendizaje y clave seleccionada
    String nombreUniApr = "";
    String nombreclave = "";
    int uniAprselec2 = Integer.parseInt(unidadAprendizajeSeleccionada);
    for (int x = 0; x < unidadesaprendisaje.size(); x++) {
        if (unidadesaprendisaje.get(x).getUapclave() == uniAprselec2) {
            nombreUniApr = unidadesaprendisaje.get(x).getUapnombre();
            nombreclave = Integer.toString(unidadesaprendisaje.get(x).getUapclave());
        }
    }
    //----------------------------------------------------------------------

    // rutaImagen es la ruta para acceder a la imagen guardada en el folder resources del proyecto
    try {
        //            Image imagenLogo = Image.getInstance("C:\\Users\\Y\\Desktop\\RACT 22-01-2015\\RACT\\build\\web\\resources\\imagenes\\logo.jpg");
        Image imagenLogo = Image.getInstance(RACTBeanUI.class.getResource("imagenes/logo.jpg"));

        //Posicion de imagen (Horizontal, Vertiacal)
        imagenLogo.setAbsolutePosition(120f, 460f);

        //Tamao de imagen (Ancho, largo)
        imagenLogo.scaleAbsolute(90, 120);
        //imagenLogo.scaleAbsoluteWidth(100f);
        //imagenLogo.scaleAbsoluteHeight(150f);
        //imagenLogo.scaleToFit(100f, 120f); Esta es la buena
        //Image imagenLogo = Image.getInstance("http://ed.uabc.mx/sed/images/logo.jpg");
        //imagenLogo.scaleAbsolute(70f, 90f);
        pdf.add(imagenLogo);
    } catch (Exception exception) {
        System.out.println("****NO SE ENCONTRO LA RUTA DE IMAGEN ESPECIFICADA");
    }
    //Tabla con UABC y Nombre del profesor(a)
    PdfPTable pdfTabletitulo = new PdfPTable(2);
    pdfTabletitulo.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    PdfPTable pdfTabletitulo2 = new PdfPTable(2);
    pdfTabletitulo2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    Paragraph UABC = new Paragraph("Universidad Autnoma de Baja California",
            FontFactory.getFont(FontFactory.TIMES, 22, Font.BOLD, new Color(0, 113, 65)));
    UABC.setAlignment(Element.ALIGN_CENTER);
    Paragraph esp = new Paragraph(" ");
    pdf.add(UABC);
    pdf.add(esp);
    pdf.add(esp);
    pdf.add(esp);
    pdf.add(esp);
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));
    pdfTabletitulo.addCell(new Paragraph(""));

    pdfTabletitulo.addCell(new Paragraph("Profesor(a): ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdfTabletitulo.addCell(new Paragraph(nombrep));

    pdfTabletitulo2.addCell(new Paragraph("Num. de Empleado: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdfTabletitulo2.addCell(new Paragraph(numEmpPro));

    pdfTabletitulo.setHorizontalAlignment(25);
    //pdfTabletitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
    //document.add(table);
    float[] columnWidthsss = new float[] { 4f, 28 };
    pdfTabletitulo.setWidths(columnWidthsss);
    pdf.add(pdfTabletitulo);

    float[] columnWidthss = new float[] { 10f, 38 };
    pdfTabletitulo2.setWidths(columnWidthss);
    pdf.add(pdfTabletitulo2);

    pdf.add(new Phrase(" "));

    //----------------------------------------------------------------------
    //Tabla Cabezera
    PdfPTable pdftablecabezera = new PdfPTable(4);
    pdftablecabezera.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    PdfPTable pdftablecabezera2 = new PdfPTable(5);
    pdftablecabezera2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    pdftablecabezera.addCell(new Paragraph("Programa educativo: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera.addCell(new Paragraph("Fecha: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera.addCell(new Paragraph("Ciclo Escolar: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera.addCell(new Paragraph("Avance Global: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera.addCell(new Paragraph(nombreProgEdu));
    pdftablecabezera.addCell(new Paragraph(formato.format(new Date())));
    pdftablecabezera.addCell(new Paragraph("        " + cicloEscolar));
    pdftablecabezera.addCell(new Paragraph("        " + porAv));

    pdftablecabezera.addCell(new Paragraph(" "));
    pdftablecabezera.addCell(new Paragraph(" "));
    pdftablecabezera.addCell(new Paragraph(" "));
    pdftablecabezera.addCell(new Paragraph(" "));

    pdftablecabezera2.addCell(new Paragraph("Unidad de Aprendizaje: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera2.addCell(new Paragraph("Clave: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera2.addCell(new Paragraph("Grupo: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera2.addCell(new Paragraph("Subgrupo: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera2.addCell(new Paragraph("Tipo Grupo: ",
            FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0))));
    pdftablecabezera2.addCell(new Paragraph(nombreUnidadSeleccionado));
    pdftablecabezera2.addCell(new Paragraph(claveUnidadAprendizajeSeleccionada));
    pdftablecabezera2.addCell(new Paragraph("   " + grupo));
    pdftablecabezera2.addCell(new Paragraph("       " + subGrupo));
    String tipoGrupo = "";
    switch (this.tipoUnidadAprendizaje) {
    case "C":
        tipoGrupo = "Clase";
        break;
    case "L":
        tipoGrupo = "Laboratorio";
        break;
    case "T":
        tipoGrupo = "Taller";
        break;
    case "P":
        tipoGrupo = "Practica";
        break;
    case "CL":
        tipoGrupo = "Practicas Clinica";
        break;
    }
    pdftablecabezera2.addCell(new Paragraph("       " + tipoGrupo));
    pdftablecabezera2.addCell(new Paragraph(" "));

    pdftablecabezera.setHorizontalAlignment(25);
    float[] columnWidths = new float[] { 38f, 10f, 14f, 18f };
    pdftablecabezera.setWidths(columnWidths);
    pdf.add(pdftablecabezera);

    pdftablecabezera2.setHorizontalAlignment(25);
    float[] columnWidthss2 = new float[] { 38f, 10f, 8f, 11f, 14f };
    pdftablecabezera2.setWidths(columnWidthss2);
    pdf.add(pdftablecabezera2);

    pdf.add(new Phrase(" "));

    //----------------------------------------------------------------------
    Paragraph numrep = new Paragraph("Reporte # " + numeroReporte,
            FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD, new Color(0, 0, 0)));
    numrep.setAlignment(Element.ALIGN_CENTER);
    pdf.add(numrep);
    pdf.add(new Paragraph(" "));
    //Tabla con Datos 
    PdfPTable pdfTable = new PdfPTable(3);
    pdfTable.addCell(new Phrase("Nombre",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0))));
    pdfTable.addCell(new Phrase("Porcentaje",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0))));
    pdfTable.addCell(new Phrase("Observaciones",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0))));

    //Evitar Null pointer exception por no tener nodoes en selectedNodes
    //Se utiliza un auxiliar de selectedNodes por que hay posibilidad de que selectedNodes se modifique durante el proceso de generacion del PDF
    if (selectedNodesPDF != null && selectedNodesPDF.length > 0) {

        //Regresar a lo basicoString
        int nns = selectedNodesPDF.length;
        String[] ns = new String[nns];
        for (int x = 0; x < selectedNodesPDF.length; x++) {
            ns[x] = ((NodoMultiClass) selectedNodesPDF[x].getData()).getNumero() + "--"
                    + ((NodoMultiClass) selectedNodes[x].getData()).getNombre() + "--"
                    + ((NodoMultiClass) selectedNodes[x].getData()).getPorcentajeAvance() + "--"
                    + ((NodoMultiClass) selectedNodes[x].getData()).getObservaciones() + " -- ";
        }
        String[] filas = new String[4];
        String[] nstr = new String[3];

        String[] filas2 = new String[4];
        String[] nstr2 = new String[3];

        for (int x = 1; x < ns.length; x++) {
            for (int y = 0; y < ns.length - x; y++) {
                //Obtengo los valores para hacer las comparaciones
                int[] n = new int[3];
                int[] n2 = new int[3];
                filas = ns[y].split("--");
                nstr = filas[0].split("\\.");
                for (int z = 0; z < nstr.length; z++) {
                    if (nstr == null) {
                        n[z] = 0;
                    } else {
                        n[z] = Integer.parseInt(nstr[z]);
                    }
                }
                filas2 = ns[y + 1].split("--");
                nstr2 = filas2[0].split("\\.");
                for (int z = 0; z < nstr2.length; z++) {
                    if (nstr2 == null) {
                        n2[z] = 0;
                    } else {
                        n2[z] = Integer.parseInt(nstr2[z]);
                    }
                }
                //-------------------------------------------------comparacion
                if (n[0] == n2[0]) {
                    if (n[1] == n2[1]) {
                        if (n[2] > n2[2]) {
                            String aux = ns[y];
                            ns[y] = ns[y + 1];
                            ns[y + 1] = aux;
                        }
                    } else {
                        if (n[1] > n2[1]) {
                            String aux = ns[y];
                            ns[y] = ns[y + 1];
                            ns[y + 1] = aux;
                        }
                    }
                } else {
                    if (n[0] > n2[0]) {
                        String aux = ns[y];
                        ns[y] = ns[y + 1];
                        ns[y + 1] = aux;
                    }
                }
                //-------------------------------------------------------------
            }
        }

        String[] auxNum = new String[4];
        for (int x = 0; x < ns.length; x++) {

            filas = ns[x].split("--");
            num = filas[0].split("\\.");

            //Auxiliar para agregar padre de tema/subtema
            int auxMargen = 1;
            //Agregar unidad a la que pertenece el tema/subtema

            String[] auxNum2 = auxNum;
            int tamanoArbol = root.getChildCount();
            //AGREGAR A TEMA
            if (Integer.parseInt(num[0]) > tamanoArbol) {
                auxMargen = Integer.parseInt(num[0]) - tamanoArbol;
            }
            if (num.length >= 2 && auxNum2[0] != null && !auxNum2[0].equals(num[0])) {
                if (!num[1].equals("0")) {
                    while (!num[0].equals(auxNum2[0]) && auxMargen > 0) {
                        System.out.println("XXXXXXIteracion  para encontrar padre XXXXXXX 0" + auxMargen);
                        auxNum2 = (((NodoMultiClass) root.getChildren()
                                .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\.");
                        //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){
                        if (num[0].equals(auxNum2[0])) {

                        } else {
                            auxMargen--;
                        }

                    }
                    System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre());
                    NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getData());
                    //UTIL PARA PONER TEXTO TACHADO
                    //                     Chunk strikethrough = new Chunk("Strikethrough.");
                    //                      strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location
                    //                     document.add(strikethrough);
                    pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(auxNodo.getObservaciones());

                }
            } else {
                if (auxNum2[0] == null && num.length >= 2) {
                    auxNum2 = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen)
                            .getData()).getNumero()).split("\\.");
                    while (!num[0].equals(auxNum2[0]) && auxMargen > 0) {
                        System.out.println("XXXXXXIteracion  para encontrar padre XXXXXXX 0" + auxMargen);
                        auxNum2 = (((NodoMultiClass) root.getChildren()
                                .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\.");
                        //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){
                        if (num[0].equals(auxNum2[0])) {

                        } else {
                            auxMargen--;
                        }
                    }
                    System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre());
                    NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getData());
                    //UTIL PARA PONER TEXTO TACHADO
                    //                     Chunk strikethrough = new Chunk("Strikethrough.");
                    //                      strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location
                    //                     document.add(strikethrough);
                    pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(auxNodo.getObservaciones());

                }
            }

            //AGREGAR A SUBTEMA
            String[] auxNumeroUnidad = new String[4];
            int auxMargen2 = 1;
            if (num.length == 3 && auxNum[1] != null && !auxNum[1].equals(num[1])) {
                if (!num[2].equals("0")) {
                    while (!num[0].equals(auxNum[0]) && auxMargen >= 0) {
                        NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren()
                                .get(Integer.parseInt(num[0]) - auxMargen).getData());
                        auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\.");
                        tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount();
                        if (Integer.parseInt(num[1]) > tamanoArbol) {
                            auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol;
                        }

                        while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1])
                                && auxMargen > 0) {
                            System.out.println("XXXXXXIteracion  para encontrar padre XXXXXXX 0" + auxMargen);
                            auxNum = (((NodoMultiClass) root.getChildren()
                                    .get(Integer.parseInt(num[0]) - auxMargen).getChildren()
                                    .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero())
                                            .split("\\.");
                            //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){
                            if (num[1].equals(auxNum[1])) {

                            } else {
                                auxMargen2--;
                            }

                        }
                        //                            auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\.");
                        if (num[0].equals(auxNum[0])) {
                        } else {
                            auxMargen--;
                        }
                    }

                    System.out.println("*****Unidad Padre(SUBTEMA)"
                            + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen)
                                    .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData())
                                            .getNombre());
                    NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getChildren()
                            .get(Integer.parseInt(num[1]) - auxMargen2).getData());
                    //UTIL PARA PONER TEXTO TACHADO
                    //                     Chunk strikethrough = new Chunk("Strikethrough.");
                    //                      strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location
                    //                     document.add(strikethrough);
                    pdfTable.addCell(
                            new Phrase("   " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory
                                    .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(auxNodo.getObservaciones());

                }
            } else {
                if (auxNum[0] == null && num.length == 3) {
                    auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen)
                            .getData()).getNumero()).split("\\.");
                    while (!num[0].equals(auxNum[0]) && auxMargen > 0) {
                        NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren()
                                .get(Integer.parseInt(num[0]) - auxMargen).getData());
                        auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\.");
                        tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount();
                        if (Integer.parseInt(num[1]) > tamanoArbol) {
                            auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol;
                        }
                        while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1])
                                && auxMargen > 0) {
                            System.out.println("Iteracion  para encontrar padre XXXXXXX 0" + auxMargen);
                            auxNum = (((NodoMultiClass) root.getChildren()
                                    .get(Integer.parseInt(num[0]) - auxMargen).getChildren()
                                    .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero())
                                            .split("\\.");
                            //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){
                            if (num[1].equals(auxNum[1])) {

                            } else {
                                auxMargen2--;
                            }
                        }
                        //                            auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\.");
                        if (num[0].equals(auxNum[0])) {
                        } else {
                            auxMargen--;
                        }
                    }

                    System.out.println("***Unidad Padre(SUBTEMA)"
                            + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen)
                                    .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData())
                                            .getNombre());
                    NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren()
                            .get(Integer.parseInt(num[0]) - auxMargen).getChildren()
                            .get(Integer.parseInt(num[1]) - auxMargen2).getData());
                    //UTIL PARA PONER TEXTO TACHADO
                    //                     Chunk strikethrough = new Chunk("Strikethrough.");
                    //                      strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location
                    //                     document.add(strikethrough);
                    pdfTable.addCell(
                            new Phrase("   " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory
                                    .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory
                            .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151))));
                    pdfTable.addCell(auxNodo.getObservaciones());

                }
            }

            auxNum = num;
            //FIN AGREGAR PADRE DE TEMA/SUBTEMA 
            boolean banpor = true;
            if (num.length == 1) {
                pdfTable.addCell(new Phrase(filas[0] + ".- " + filas[1],
                        FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0))));
                pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))),
                        FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0))));
                banpor = false;
            }
            if (num.length == 2) {
                pdfTable.addCell(new Phrase("   " + filas[0] + ".- " + filas[1]));
            }
            if (num.length == 3) {
                pdfTable.addCell(new Phrase("       " + filas[0] + ".- " + filas[1],
                        FontFactory.getFont(FontFactory.TIMES_ITALIC, 12)));
                pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))),
                        FontFactory.getFont(FontFactory.TIMES_ITALIC, 12)));
                banpor = false;
            }
            if (banpor) {
                pdfTable.addCell(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))));
                pdfTable.addCell(filas[3]);
            } else {
                pdfTable.addCell(filas[3]);
            }
        }

    } else {
        pdfTable.addCell("No hay nada seleccionado");
        pdfTable.addCell("");
        pdfTable.addCell("");
    }

    pdfTable.setHorizontalAlignment(15);
    float[] columnWidths2 = new float[] { 32f, 8f, 14f };
    pdfTable.setWidths(columnWidths2);
    pdf.add(pdfTable);
    //----------------------------------------------------------------------
}

From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java

License:Apache License

private Image getParagraphImage(String resourceFileName) throws DocumentException, IOException {
    Image image = paragraphImagesByResourceName.get(resourceFileName);
    if (image == null) {
        image = getImage(resourceFileName);
        image.scaleAbsolute(16, 16);
        paragraphImagesByResourceName.put(resourceFileName, image);
    }/*  www  .j  av  a 2  s  .  co m*/
    return image;
}

From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java

License:Apache License

Image getSmallImage(String resourceFileName) throws DocumentException, IOException {
    Image image = smallImagesByResourceName.get(resourceFileName);
    if (image == null) {
        image = getImage(resourceFileName);
        image.scaleAbsolute(8, 8);
        smallImagesByResourceName.put(resourceFileName, image);
    }/*  ww w.  j  av  a 2  s . c  o  m*/
    return image;
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *//*from w w  w  .  java2  s .  com*/
protected void exportImage(JRPrintImage printImage) throws DocumentException, IOException, JRException {
    if (printImage.getMode() == JRElement.MODE_OPAQUE) {
        pdfContentByte.setRGBColorFill(printImage.getBackcolor().getRed(), printImage.getBackcolor().getGreen(),
                printImage.getBackcolor().getBlue());
        pdfContentByte.rectangle(printImage.getX() + getOffsetX(),
                jasperPrint.getPageHeight() - printImage.getY() - getOffsetY(), printImage.getWidth(),
                -printImage.getHeight());
        pdfContentByte.fill();
    }

    int topPadding = printImage.getLineBox().getTopPadding().intValue();
    int leftPadding = printImage.getLineBox().getLeftPadding().intValue();
    int bottomPadding = printImage.getLineBox().getBottomPadding().intValue();
    int rightPadding = printImage.getLineBox().getRightPadding().intValue();

    int availableImageWidth = printImage.getWidth() - leftPadding - rightPadding;
    availableImageWidth = (availableImageWidth < 0) ? 0 : availableImageWidth;

    int availableImageHeight = printImage.getHeight() - topPadding - bottomPadding;
    availableImageHeight = (availableImageHeight < 0) ? 0 : availableImageHeight;

    JRRenderable renderer = printImage.getRenderer();

    if (renderer != null && availableImageWidth > 0 && availableImageHeight > 0) {
        if (renderer.getType() == JRRenderable.TYPE_IMAGE) {
            // Image renderers are all asked for their image data at some point. 
            // Better to test and replace the renderer now, in case of lazy load error.
            renderer = JRImageRenderer.getOnErrorRendererForImageData(renderer, printImage.getOnErrorType());
        }
    } else {
        renderer = null;
    }

    if (renderer != null) {
        int xoffset = 0;
        int yoffset = 0;

        Chunk chunk = null;

        float scaledWidth = availableImageWidth;
        float scaledHeight = availableImageHeight;

        if (renderer.getType() == JRRenderable.TYPE_IMAGE) {
            com.lowagie.text.Image image = null;

            float xalignFactor = getXAlignFactor(printImage);
            float yalignFactor = getYAlignFactor(printImage);

            switch (printImage.getScaleImage()) {
            case JRImage.SCALE_IMAGE_CLIP: {
                // Image load might fail, from given image data. 
                // Better to test and replace the renderer now, in case of lazy load error.
                renderer = JRImageRenderer.getOnErrorRendererForDimension(renderer,
                        printImage.getOnErrorType());
                if (renderer == null) {
                    break;
                }

                int normalWidth = availableImageWidth;
                int normalHeight = availableImageHeight;

                Dimension2D dimension = renderer.getDimension();
                if (dimension != null) {
                    normalWidth = (int) dimension.getWidth();
                    normalHeight = (int) dimension.getHeight();
                }

                xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
                yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));

                int minWidth = Math.min(normalWidth, availableImageWidth);
                int minHeight = Math.min(normalHeight, availableImageHeight);

                BufferedImage bi = new BufferedImage(minWidth, minHeight, BufferedImage.TYPE_INT_ARGB);

                Graphics2D g = bi.createGraphics();
                if (printImage.getMode() == JRElement.MODE_OPAQUE) {
                    g.setColor(printImage.getBackcolor());
                    g.fillRect(0, 0, minWidth, minHeight);
                }
                renderer.render(g, new java.awt.Rectangle((xoffset > 0 ? 0 : xoffset),
                        (yoffset > 0 ? 0 : yoffset), normalWidth, normalHeight));
                g.dispose();

                xoffset = (xoffset < 0 ? 0 : xoffset);
                yoffset = (yoffset < 0 ? 0 : yoffset);

                //awtImage = bi.getSubimage(0, 0, minWidth, minHeight);

                //image = com.lowagie.text.Image.getInstance(awtImage, printImage.getBackcolor());
                image = com.lowagie.text.Image.getInstance(bi, null);

                break;
            }
            case JRImage.SCALE_IMAGE_FILL_FRAME: {
                if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) {
                    image = (com.lowagie.text.Image) loadedImagesMap.get(renderer);
                } else {
                    try {
                        image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                        imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
                    } catch (Exception e) {
                        JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage(
                                JRImageRenderer.getInstance(renderer.getImageData()),
                                printImage.getOnErrorType());
                        if (tmpRenderer == null) {
                            break;
                        }
                        java.awt.Image awtImage = tmpRenderer.getImage();
                        image = com.lowagie.text.Image.getInstance(awtImage, null);
                    }

                    if (printImage.isUsingCache()) {
                        loadedImagesMap.put(renderer, image);
                    }
                }

                image.scaleAbsolute(availableImageWidth, availableImageHeight);
                break;
            }
            case JRImage.SCALE_IMAGE_RETAIN_SHAPE:
            default: {
                if (printImage.isUsingCache() && loadedImagesMap.containsKey(renderer)) {
                    image = (com.lowagie.text.Image) loadedImagesMap.get(renderer);
                } else {
                    try {
                        image = com.lowagie.text.Image.getInstance(renderer.getImageData());
                        imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
                    } catch (Exception e) {
                        JRImageRenderer tmpRenderer = JRImageRenderer.getOnErrorRendererForImage(
                                JRImageRenderer.getInstance(renderer.getImageData()),
                                printImage.getOnErrorType());
                        if (tmpRenderer == null) {
                            break;
                        }
                        java.awt.Image awtImage = tmpRenderer.getImage();
                        image = com.lowagie.text.Image.getInstance(awtImage, null);
                    }

                    if (printImage.isUsingCache()) {
                        loadedImagesMap.put(renderer, image);
                    }
                }

                image.scaleToFit(availableImageWidth, availableImageHeight);

                xoffset = (int) (xalignFactor * (availableImageWidth - image.plainWidth()));
                yoffset = (int) (yalignFactor * (availableImageHeight - image.plainHeight()));

                xoffset = (xoffset < 0 ? 0 : xoffset);
                yoffset = (yoffset < 0 ? 0 : yoffset);

                break;
            }
            }

            if (image != null) {
                chunk = new Chunk(image, 0, 0);

                scaledWidth = image.scaledWidth();
                scaledHeight = image.scaledHeight();
            }
        } else {
            double normalWidth = availableImageWidth;
            double normalHeight = availableImageHeight;

            double displayWidth = availableImageWidth;
            double displayHeight = availableImageHeight;

            double ratioX = 1f;
            double ratioY = 1f;

            Rectangle2D clip = null;

            Dimension2D dimension = renderer.getDimension();
            if (dimension != null) {
                normalWidth = dimension.getWidth();
                normalHeight = dimension.getHeight();
                displayWidth = normalWidth;
                displayHeight = normalHeight;

                float xalignFactor = getXAlignFactor(printImage);
                float yalignFactor = getYAlignFactor(printImage);

                switch (printImage.getScaleImage()) {
                case JRImage.SCALE_IMAGE_CLIP: {
                    xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
                    yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
                    clip = new Rectangle2D.Double(-xoffset, -yoffset, availableImageWidth,
                            availableImageHeight);
                    break;
                }
                case JRImage.SCALE_IMAGE_FILL_FRAME: {
                    ratioX = availableImageWidth / normalWidth;
                    ratioY = availableImageHeight / normalHeight;
                    normalWidth *= ratioX;
                    normalHeight *= ratioY;
                    xoffset = 0;
                    yoffset = 0;
                    break;
                }
                case JRImage.SCALE_IMAGE_RETAIN_SHAPE:
                default: {
                    ratioX = availableImageWidth / normalWidth;
                    ratioY = availableImageHeight / normalHeight;
                    ratioX = ratioX < ratioY ? ratioX : ratioY;
                    ratioY = ratioX;
                    normalWidth *= ratioX;
                    normalHeight *= ratioY;
                    xoffset = (int) (xalignFactor * (availableImageWidth - normalWidth));
                    yoffset = (int) (yalignFactor * (availableImageHeight - normalHeight));
                    break;
                }
                }
            }

            PdfTemplate template = pdfContentByte.createTemplate((float) displayWidth, (float) displayHeight);

            Graphics2D g = forceSvgShapes
                    ? template.createGraphicsShapes((float) displayWidth, (float) displayHeight)
                    : template.createGraphics(availableImageWidth, availableImageHeight, new LocalFontMapper());

            if (clip != null) {
                g.setClip(clip);
            }

            if (printImage.getMode() == JRElement.MODE_OPAQUE) {
                g.setColor(printImage.getBackcolor());
                g.fillRect(0, 0, (int) displayWidth, (int) displayHeight);
            }

            Rectangle2D rectangle = new Rectangle2D.Double(0, 0, displayWidth, displayHeight);

            renderer.render(g, rectangle);
            g.dispose();

            pdfContentByte.saveState();
            pdfContentByte.addTemplate(template, (float) ratioX, 0f, 0f, (float) ratioY,
                    printImage.getX() + getOffsetX() + xoffset, jasperPrint.getPageHeight() - printImage.getY()
                            - getOffsetY() - (int) normalHeight - yoffset);
            pdfContentByte.restoreState();

            Image image = getPxImage();
            image.scaleAbsolute(availableImageWidth, availableImageHeight);
            chunk = new Chunk(image, 0, 0);
        }

        /*
        image.setAbsolutePosition(
           printImage.getX() + offsetX + borderOffset,
           jasperPrint.getPageHeight() - printImage.getY() - offsetY - image.scaledHeight() - borderOffset
           );
                
        pdfContentByte.addImage(image);
        */

        if (chunk != null) {
            setAnchor(chunk, printImage, printImage);
            setHyperlinkInfo(chunk, printImage);

            ColumnText colText = new ColumnText(pdfContentByte);
            int upperY = jasperPrint.getPageHeight() - printImage.getY() - topPadding - getOffsetY() - yoffset;
            int lowerX = printImage.getX() + leftPadding + getOffsetX() + xoffset;
            colText.setSimpleColumn(new Phrase(chunk), lowerX, upperY - scaledHeight, lowerX + scaledWidth,
                    upperY, scaledHeight, Element.ALIGN_LEFT);

            colText.go();
        }
    }

    if (printImage.getLineBox().getTopPen().getLineWidth().floatValue() <= 0f
            && printImage.getLineBox().getLeftPen().getLineWidth().floatValue() <= 0f
            && printImage.getLineBox().getBottomPen().getLineWidth().floatValue() <= 0f
            && printImage.getLineBox().getRightPen().getLineWidth().floatValue() <= 0f) {
        if (printImage.getLinePen().getLineWidth().floatValue() > 0f) {
            exportPen(printImage.getLinePen(), printImage);
        }
    } else {
        /*   */
        exportBox(printImage.getLineBox(), printImage);
    }
}