Example usage for com.itextpdf.text Image scaleAbsolute

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

Introduction

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

Prototype

public void scaleAbsolute(final float newWidth, final float newHeight) 

Source Link

Document

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

Usage

From source file:NPRImpl.java

@Override
public boolean saveRegistrationToPdf(RegistrationImpl registrationImpl, ResidentImpl residentImpl)
        throws RemoteException {
    try {//from www  .j  ava2s  .c o m
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }
        String gend = "";
        Document doc = new Document();
        FileOutputStream fos = new FileOutputStream(path + "\\registration\\" + residentImpl.getLName().trim()
                + ", " + residentImpl.getFName().trim() + "RegistrationResidentForm.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("RegistrationResidentForm.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);
            if (residentImpl.getPicture() != null) {
                Image image1 = Image.getInstance(residentImpl.getPicture());
                image1.scaleAbsolute(95, 105);
                image1.setAbsolutePosition(465f, 635f);
                content.addImage(image1);
            }

            //Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            //last name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getLName().trim(), 175, 610, 0);
            //first name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getFName().trim(), 325, 610, 0);
            //middle name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getMName().trim(), 470, 610, 0);
            //college
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getCollege().trim(), 180, 582,
                    0);
            //Course and year
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    registrationImpl.getCourse().trim() + " - " + registrationImpl.getYear().trim(), 180, 568,
                    0);
            //department
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getDepartment().trim(), 400,
                    582, 0);
            //Sex
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentImpl.getGender().trim(), 400, 568, 0);
            //Home address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getAddress().trim(), 110, 540,
                    0);
            //resident mobile no1
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMobile_number().trim(), 187,
                    485, 0);
            //resident mobile no2
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMobile_number2().trim(), 187,
                    470, 0);
            //student email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getEmail().trim(), 397, 485, 0);
            //fathers name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherName().trim(), 110,
                    443, 0);
            //fathers area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherAreaCode().trim(), 300,
                    443, 0);
            //father landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherPhone().trim(), 355,
                    443, 0);
            //father mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherMobile().trim(), 490,
                    443, 0);
            //father email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getFatherEmail().trim(), 110,
                    430, 0);
            //mother name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherName().trim(), 110,
                    402, 0);
            //mother area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherAreaCode().trim(), 300,
                    402, 0);
            //mother landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherPhone().trim(), 355,
                    402, 0);
            //mother mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherMobile().trim(), 490,
                    402, 0);
            //mother email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getMotherEmail().trim(), 110,
                    387, 0);
            //guardian name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianName().trim(), 170,
                    335, 0);
            //guardian contact number
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianMobile().trim(), 470,
                    335, 0);
            //guardian address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianAddress().trim(),
                    125, 322, 0);
            //guardian relation
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, registrationImpl.getGuardianRelation().trim(),
                    170, 307, 0);
            content.setFontAndSize(bf, 12);
            //room details
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Room No.: "
                    + registrationImpl.getRoom_number().trim() + " - " + registrationImpl.getRoom_type().trim(),
                    355, 235, 0);
            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
        fos.close();
        pdfWriter.close();
    } catch (DocumentException | FileNotFoundException ex) {
        //            Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex);
        label.setText(ex.getMessage());
        return false;
    } catch (IOException ex) {
        //            Logger.getLogger(NPRImpl.class.getName()).log(Level.SEVERE, null, ex);
        label.setText(ex.getMessage());
        return false;
    }
    return true;
}

From source file:pdfservlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*w w  w .j  ava 2  s .  c o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ResultSet resultSet = null;
    Statement statement = null;
    try {
        Connection connection = ConnectionManager.createConnectionToDB();

        String query = "SELECT * FROM employees";
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    response.setContentType("application/pdf");
    Document document = new Document();
    Font font3 = new Font(Font.FontFamily.TIMES_ROMAN, 8);
    Font font4 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
    Font font2 = new Font(Font.FontFamily.COURIER, 10, Font.UNDERLINE);

    try {

        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();
        document.add(new Phrase(new Date().toString() + "\n", font3));
        String imageUrl = "http://www.technolinks.in/images/bhel_logo.jpg";

        Image image2 = Image.getInstance(new URL(imageUrl));
        image2.scaleAbsolute(100f, 100f);
        image2.setAbsolutePosition(25f, 725f);
        document.add(image2);

        document.add(new Phrase(
                "                                                                                                               BHEL Recruitment for Medical Professionals \n                                                              ",
                font3));
        document.add(new Phrase("Admit Card for Interview of Medical Professional in BHEL\n", font2));
        document.add(
                new Phrase("                                                 Acknowledgement No :", font3));

        document.addCreator("Shivin");
        document.addTitle("BHEL");

        resultSet.next();
        String trade_id = "100003";
        do {
            if (trade_id.matches(resultSet.getString("TRADE")))
                break;

        } while (resultSet.next());

        document.add(new Phrase("Post Applied:           " + resultSet.getString("TRADE") + "\n"));
        document.add(new Phrase("Name:                   " + resultSet.getString("FIRSTNAME") + "\n"));
        document.add(new Phrase("Father's/Husband's Name:" + resultSet.getString("FATHERNAME")));
        document.add(new Phrase("Address:                " + resultSet.getString("ADDRESS1") + "\n"
                + resultSet.getString("ADDRESS2") + "\n" + resultSet.getString("DISTRICT")
                + resultSet.getString("CITY") + "\n"));
        document.add(new Phrase("State:                  " + resultSet.getString("STATE") + "\n"));
        document.add(new Phrase("Pin:                    " + resultSet.getString("PIN") + "\n"));
        document.add(new Phrase("Caste:                  " + resultSet.getString("CASTE") + "\n"));
        document.add(new Phrase("Interview Date:         " + resultSet.getString("INTERVIEW_DATE") + "\n"));
        document.add(
                new Phrase("Interview Time:                  " + resultSet.getString("INTERVIEW_TIME") + "\n"));
        document.add(
                new Phrase("Reporting Time:                  " + resultSet.getString("REPORTING_TIME") + "\n"));
        document.add(new Phrase("Interview Venue:          " + resultSet.getString("INTERVIEW_VENUE") + "\n"));

        document.add(new Phrase("Important Instructions: \n", font4));
        document.add(
                new Paragraph("1.You must bring along with you the original documents and 01 selfattested\n"
                        + "photocopy of the following :\n"
                        + "Xth Certificate/ Birth Certificate mentioning Date of Birth\n"
                        + "MBBS Degree Certificate / Marksheets of all year\n"
                        + "PG Diploma / PG Degree / DNB Certificate in relevant discipline\n"
                        + "Medical Council Registration Certificate\n"
                        + "Post Qualification Experience Certificate in support of the experience being claimed\n"
                        + "Certificate for SC/ST in the prescribed format, if applicable\n"
                        + "Certificate for OBC indicating Non Creamy Layer status in the prescribed format, if applicable\n"
                        + "Self Undertaking for Non Creamy Layer status of OBC in the prescribed format, if applicable\n"
                        + "Medical Certificate for Physically Handicapped candidates for their disability from Government Hospital or Medical Board, if applicable.\n"
                        + "Discharge Certificate for ExServicemen\n"
                        + "NOC from the present employer, if applicable\n"
                        + "2. The shortlisted candidates after attending the interviews will be reimbursed train fare to the extent of single AC 2nd class return train fare\n"
                        + "from the address mentioned in the Application form to Interview Centre, by the shortest route subject to submission of rail/bus Ticket\n"
                        + "3. Please ensure that you fulfill all the prescribed job specifications as advertised and produce all the relevant documents thereof as aforesaid (as\n"
                        + "applicable to you), failing which we will not be able to interview you nor reimburse the Travelling Allowance. In case it is found that a\n"
                        + "candidate does not possess the qualification and /or other specification as prescribed in our advertisement, their candidature will be cancelled abinitio\n"
                        + "and no Travelling Allowance will be paid.\n"
                        + "4. You have the option to answer either in English or in Hindi during the Interview. Please note that no change of Interview place and/or date of\n"
                        + "interview will be possible. Also, we will not be able to respond to any individual queries regarding the results of personal Interview."));
        document.add(new Phrase("Declaration by the candidate: \n", font4));
        document.add(new Paragraph(
                "I understand that my permission to this test interview is provisional and if it is found at the later date that I do not fulfill the essential eligibility\n"
                        + "criteria regarding qualification, marks, age, caste, Experience etc. as per requirement of the Company, I will be debarred abinitio\n"
                        + "and I will not\n" + "be able to make any claim to the post."));
        document.add(new Phrase("DATE:", font2));
        document.add(new Phrase("\n"));
        document.add(new Phrase("PLACE:", font2));
        document.add(new Phrase("\n"));

        /* PdfPTable table2 = new PdfPTable(1);
                 
         table2.addCell("1.");
         table2.addCell("2.");
         table2.addCell("3.");
                
                 
                
          document.add(new Paragraph("                                                 \n\n\n\n            \n\n\n\n\n\n"));
                
          document.add(new Paragraph("             *Terms and Conditions      \n                               "));
                  
          document.add(table2); 
          document.close();
                  
                  
                  
        */
    } catch (Exception e) {
        e.printStackTrace();

    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */

}

From source file:Registration_Tenant.java

private void saveToPdf() {
    try {//from  w w w .ja  va2s.  c  o m
        String gend = "";
        Document doc = new Document();
        BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt"));
        String path = "";
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            path = sb.toString().trim();
        } finally {
            br.close();
        }
        FileOutputStream fos = new FileOutputStream(
                path + "\\registration\\" + lastNameTextField.getText().trim() + ", "
                        + firstNameTextField.getText().trim() + "RegistrationResidentForm.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos);

        PdfReader pdfReader = new PdfReader("RegistrationResidentForm.pdf");

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
            PdfContentByte content = pdfStamper.getOverContent(i);

            byte[] cc = null;
            if (file != null) {
                File thisFile = new File(file);
                cc = Files.readAllBytes(thisFile.toPath());
            }
            if (cc != null) {
                Image image1 = Image.getInstance(cc);
                image1.scaleAbsolute(95, 105);
                image1.setAbsolutePosition(465f, 635f);
                content.addImage(image1);
            }

            //Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 10);
            //last name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, lastNameTextField.getText().trim(), 175, 610, 0);
            //first name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, firstNameTextField.getText().trim(), 325, 610,
                    0);
            //middle name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, middleNameTextField.getText().trim(), 470, 610,
                    0);
            //college
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, collegeTextField.getText().trim(), 180, 582, 0);
            //Course and year
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    courseTextField.getText().trim() + " - " + yearTextField.getText().trim(), 180, 568, 0);
            //department
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, departmentTextField.getText().trim(), 400, 582,
                    0);
            String g;
            if (male.isSelected()) {
                g = "Male";//6
            } else {
                g = "Female";//6
            }
            //Sex
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, g, 400, 568, 0);
            //Home address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, homeAddressTextArea.getText(), 110, 540, 0);
            //resident mobile no1
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, MobileNumber1.getText().trim(), 187, 485, 0);
            //resident mobile no2
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, MobileNumber2.getText().trim(), 187, 470, 0);
            //student email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, email.getText().trim(), 397, 485, 0);
            //fathers name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fatherNameTextField.getText().trim(), 110, 443,
                    0);
            //fathers area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fACodeTextField.getText().trim(), 300, 443, 0);
            //father landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fphoneNumberTextField.getText().trim(), 355, 443,
                    0);
            //father mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fMobileNumberTextField.getText().trim(), 490,
                    443, 0);
            //father email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fEmailTextField.getText().trim(), 110, 430, 0);
            //mother name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, motherNameTextField.getText().trim(), 110, 402,
                    0);
            //mother area code
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mACodeTextField.getText().trim(), 300, 402, 0);
            //mother landline
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mphoneNumberTextField.getText().trim(), 355, 402,
                    0);
            //mother mobile
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mMobileNumberTextField.getText().trim(), 490,
                    402, 0);
            //mother email
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, mEmailTextField.getText().trim(), 110, 387, 0);
            //guardian name
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guardianNameTextField.getText().trim(), 170, 335,
                    0);
            //guardian contact number
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, gContactNumber1.getText().trim(), 470, 335, 0);
            //guardian address
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, guardianAddress.getText().trim(), 125, 322, 0);
            //guardian relation
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, relationToGuardian.getText().trim(), 170, 307,
                    0);
            content.setFontAndSize(bf, 12);
            //room details
            content.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Room No.: " + roomNumberTextField.getSelectedItem().toString().trim() + " - "
                            + roomTypeTextField.getText().trim(),
                    355, 235, 0);
            content.endText();

        }
        pdfStamper.close();
        pdfReader.close();
        fos.close();
        pdfWriter.close();
    } catch (DocumentException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (IOException ex) {
        //            Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:imprimer.java

public void imagee(Document document) throws Exception {
    URL imageUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
    System.out.println(imageUrl);
    Image image = Image.getInstance(imageUrl + "logo.png");
    image.scaleAbsolute(224, 70);
    image.setAlignment(Image.MIDDLE);
    document.add(image);/*  w  w  w.  j  a v a2 s  .c om*/

}

From source file:biblioteca.database2.controladores.ControladorEstadisticas.java

License:Open Source License

public ArrayList<Element> estadisticasDocumentosDescargados(String dow, String dom, String month, String year,
        String tipo_usuario, String[] franja, String[] desde, String[] hasta, String area, String autor,
        String doc_tipo, String usuario, boolean todos, int salida)
        throws BadElementException, MalformedURLException, IOException {

    ArrayList<Element> Salida = new ArrayList<Element>(6);
    BufferedImage bufferedImage;/*from  ww  w . ja v  a 2 s .  c om*/
    Image image;
    ResultSet rs = new DaoEstadisticas().documentosMasDescargados(dow, dom, month, year, tipo_usuario, franja,
            desde, hasta, area, autor, doc_tipo, usuario, todos);
    int total = 0;
    ArrayList<ArrayList<String>> resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
    ArrayList<String> Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla,
            1, 2);
    for (int i = 1; i < resultadosTabla.size(); i++) {
        total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
    }
    PdfPTable tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);

    Salida.add(tabla);
    Salida.add(new Paragraph("\r\n"));
    Salida.add(new Paragraph("* Diagrama de Pastel y Diagrama de Barras: Documentos Descargados"));
    JFreeChart chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
            "Documentos Descargados");
    bufferedImage = chart.createBufferedImage(500, 600);
    image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
    image.scaleAbsolute(250, 300);
    image.setAlignment(Image.MIDDLE);
    Salida.add(image);
    Salida.add(new Paragraph("\r\n"));
    chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
            "Documentos Descargados", "Identificador Documento", "Numero de Descargados");
    bufferedImage = chart.createBufferedImage(1000, 500);
    image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
    image.scaleAbsolute(500, 250);
    image.setAlignment(Image.MIDDLE);
    Salida.add(image);
    return Salida;
}

From source file:biblioteca.database2.controladores.ControladorEstadisticas.java

License:Open Source License

public ArrayList<Element> estadisticasDocumentosConsultados(String dow, String dom, String month, String year,
        String tipo_usuario, String[] franja, String[] desde, String[] hasta, String area, String autor,
        String doc_tipo, String usuario, boolean todos, int salida)
        throws BadElementException, MalformedURLException, IOException {

    ArrayList<Element> Salida = new ArrayList<Element>(6);
    BufferedImage bufferedImage;/*from  w ww .  j a v  a  2  s  .com*/
    Image image;
    ResultSet rs = new DaoEstadisticas().documentosMasConsultados(dow, dom, month, year, tipo_usuario, franja,
            desde, hasta, area, autor, doc_tipo, usuario, todos);
    int total = 0;
    ArrayList<ArrayList<String>> resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
    ArrayList<String> Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla,
            0, 2);
    for (int i = 1; i < resultadosTabla.size(); i++) {
        total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
    }
    PdfPTable tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);

    Salida.add(tabla);
    Salida.add(new Paragraph("\r\n"));
    Salida.add(new Paragraph("* Diagrama de Pastel y Diagrama de Barras: Documentos Consultados"));
    JFreeChart chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
            "Documentos Consultados");
    bufferedImage = chart.createBufferedImage(500, 600);
    image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
    image.scaleAbsolute(250, 300);
    image.setAlignment(Image.MIDDLE);
    Salida.add(image);
    Salida.add(new Paragraph("\r\n"));
    chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
            "Documentos Consultados", "Identificador Documento", "Numero de Consultas");
    bufferedImage = chart.createBufferedImage(1000, 500);
    image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
    image.scaleAbsolute(500, 250);
    image.setAlignment(Image.MIDDLE);
    Salida.add(image);
    return Salida;
}

From source file:biblioteca.database2.controladores.ControladorEstadisticas.java

License:Open Source License

public ArrayList<Element> estadisticasUsuariosRegistradosMultiplesTablas(boolean dow, boolean dom, boolean mes,
        String Year, String[] franja, String desde[], String[] hasta, boolean genero, boolean vinculo,
        boolean tipo, boolean estado, boolean area, int salida)
        throws BadElementException, MalformedURLException, IOException {
    BufferedImage bufferedImage;/* w  w w. j a v  a2  s  .c om*/
    Image image;
    ResultSet rs;
    ArrayList<Element> Salida = new ArrayList<Element>(100);
    ArrayList<Element> images = new ArrayList<Element>(100);
    DaoEstadisticas controlador = new DaoEstadisticas();
    JFreeChart chart;
    ArrayList<ArrayList<String>> resultadosTabla;
    ArrayList<String> Array2DtoArrayPlane;
    PdfPTable tabla = null;
    int total = 0;
    if (dow) {
        ArrayList<String> tmp = controlador.consultarUsuariosRegistradosPorDoW();
        float promedio = promedio(tmp, 2);
        Salida.add(new Paragraph("Resultados para los das de la semana"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(
                biblioteca.reportes.PdfCreator.plainArrayListToPdfPTable(agregarPorcentajesALista(tmp, 2), 3));
        Salida.add(new Paragraph("Promedio " + promedio));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Pastel: Usuarios Registrados para los dias de la Semana"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(tmp),
                "Usuarios Registrados para los das de la semana");
        bufferedImage = chart.createBufferedImage(400, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Usuarios Registrados para los dias de la Semana"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(tmp),
                "Usuarios Registrados para los das de la semana", "Das de la Semana",
                "Cantidad de usuarios");
        bufferedImage = chart.createBufferedImage(700, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(400, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (dom) {
        rs = controlador.consultarUsuariosRegistradosPorDoM();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Resultados para los das del mes"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(
                new Paragraph("* Ver Anexo: Diagrama de Pastel: Usuarios Registrados para los dias del mes"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Usuarios Registrados para los das del mes");
        bufferedImage = chart.createBufferedImage(500, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 300);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Usuarios Registrados para los das del Mes", "Das del mes", "Cantidad de usuarios");
        bufferedImage = chart.createBufferedImage(1000, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(500, 250);
        image.setAlignment(Image.MIDDLE);
        Salida.add(
                new Paragraph("* Ver Anexo: Diagrama de Barras: Usuarios Registrados para los dias del mes"));
        Salida.add(new Paragraph("\r\n"));
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (mes) {
        ArrayList<String> tmp = controlador.consultarUsuariosRegistradosPorMes();
        Salida.add(new Paragraph("Resultados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        float promedio = promedio(tmp, 2);
        Salida.add(
                biblioteca.reportes.PdfCreator.plainArrayListToPdfPTable(agregarPorcentajesALista(tmp, 2), 3));
        Salida.add(new Paragraph("Promedio " + promedio));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("* Ver Anexo: Diagrama de Pastel: Usuarios Registrados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(tmp),
                "Usuarios Registrados para los meses");
        bufferedImage = chart.createBufferedImage(500, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(350, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("* Ver Anexo: Diagrama de Barras: Usuarios Registrados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(tmp),
                "Usuarios Registrados para los Meses", "Meses", "Cantidad de usuarios");
        bufferedImage = chart.createBufferedImage(1000, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(500, 300);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (Year != null) {
        ArrayList<String> tmp = controlador.consultarUsuariosRegistradosPorYear(Year);
        Salida.add(new Paragraph("Resultados para el ao seleccionado"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Ao:" + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (franja != null) {
        ArrayList<String> tmp = controlador.consultarUsuariosRegistradosPorFranja(franja[0], franja[1]);
        Salida.add(new Paragraph("Resultados para la franja seleccionada"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Franja:" + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (desde != null && hasta != null) {
        ArrayList<String> tmp = controlador.consultarUsuariosRegistradosPorIntervalo(
                desde[0] + "-" + desde[1] + "-" + desde[2], hasta[0] + "-" + hasta[1] + "-" + hasta[2]);
        Salida.add(new Paragraph("Resultados para el intervalo de tiempo seleccionado"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Intervalo de Tiempo: " + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (genero) {
        rs = controlador.consultarUsuariosRegistradosPorGenero();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        for (int i = 0; i < resultadosTabla.size(); i++) {
            if (resultadosTabla.get(i).get(0).equals("F") || resultadosTabla.get(i).get(0).equals("f"))
                resultadosTabla.get(i).set(0, "Femenino");
            if (resultadosTabla.get(i).get(0).equals("M") || resultadosTabla.get(i).get(0).equals("m"))
                resultadosTabla.get(i).set(0, "Masculino");
            if (resultadosTabla.get(i).get(0).equals("N") || resultadosTabla.get(i).get(0).equals("n")) {
                resultadosTabla.remove(i);
            }
        }
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Estadisticas de Usuarios Registrados por Genero"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Pastel: Estadisticas de Usuarios Registrados por Genero"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Genero");
        bufferedImage = chart.createBufferedImage(450, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Genero", "Genero", "Cantidad de Usuarios");
        bufferedImage = chart.createBufferedImage(400, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(200, 200);
        image.setAlignment(Image.MIDDLE);
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Estadisticas de Usuarios Registrados por Genero"));
        Salida.add(new Paragraph("\r\n"));
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (vinculo) {
        rs = controlador.consultarUsuariosRegistradosPorVinculo();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Estadisticas de Usuarios Registrados por Vinculo"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Pastel: Estadisticas de Usuarios Registrados por Vinculo"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Vinculo");
        bufferedImage = chart.createBufferedImage(500, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Vinculo", "Vinculo", "Cantidad de Usuarios");
        bufferedImage = chart.createBufferedImage(500, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(200, 200);
        image.setAlignment(Image.MIDDLE);
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Estadisticas de Usuarios Registrados por Vinculo"));
        Salida.add(new Paragraph("\r\n"));
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (tipo) {
        rs = controlador.consultarUsuariosRegistradosPorTipoUsuario();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        for (int i = 0; i < resultadosTabla.size(); i++) {
            if (resultadosTabla.get(i).get(0).equals("3"))
                resultadosTabla.get(i).set(0, "Normal");
            else if (resultadosTabla.get(i).get(0).equals("2"))
                resultadosTabla.get(i).set(0, "Catalogador");
            else if (resultadosTabla.get(i).get(0).equals("1"))
                resultadosTabla.get(i).set(0, "Administrador");
            else if (resultadosTabla.get(i).get(0).equals("0"))
                resultadosTabla.remove(i);
        }
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Estadisticas de Usuarios Registrados por Tipo de Usuario"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("* Ver Anexo: Diagrama de Pastel: Estadisticas de Usuarios Tipo de Usuario"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Tipo de Usuario");
        bufferedImage = chart.createBufferedImage(450, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Tipo de Usuario", "Tipo de Usuario",
                "Cantidad de Usuarios");
        bufferedImage = chart.createBufferedImage(600, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 200);
        image.setAlignment(Image.MIDDLE);
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Estadisticas de Usuarios Registrados por Genero"));
        Salida.add(new Paragraph("\r\n"));
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (estado) {
        rs = controlador.consultarUsuariosRegistradosPorEstado();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        for (int i = 0; i < resultadosTabla.size(); i++) {
            if (resultadosTabla.get(i).get(0).equals("t") || resultadosTabla.get(i).get(0).equals("T"))
                resultadosTabla.get(i).set(0, "Activo");
            if (resultadosTabla.get(i).get(0).equals("f") || resultadosTabla.get(i).get(0).equals("F"))
                resultadosTabla.get(i).set(0, "Inactivo");
        }
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Estadisticas de Usuarios Registrados por Estado de Cuenta"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Pastel: Estadisticas de Usuarios por Estado de Cuenta"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios por Estado de Cuenta");
        bufferedImage = chart.createBufferedImage(450, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 200);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Estadisticas de Usuarios Registrados por Estado de Cuenta", "Estado de Cuenta",
                "Cantidad de Usuarios");
        bufferedImage = chart.createBufferedImage(600, 400);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 200);
        image.setAlignment(Image.MIDDLE);
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Estadisticas de Usuarios Registrados por Estado de Cuenta"));
        Salida.add(new Paragraph("\r\n"));
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (area) {
        total = 0;
        rs = controlador.consultarUsuariosRegistradosPorArea();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 2);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Areas con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Areas con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Areas con ms Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(600, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 300);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Areas con ms Documentos Catalogados", "Area_ID", "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(900, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(450, 250);
        image.setAlignment(Image.MIDDLE);
        images.add(image);
        images.add(new Paragraph("\r\n"));
    }
    if (!images.isEmpty()) {
        Salida.add(new Paragraph("Anexos:"));
        Salida.add(new Paragraph("\r\n"));
    }
    for (int i = 0; i < images.size(); i++) {
        Salida.add(images.get(i));
    }
    return Salida;
}

From source file:biblioteca.database2.controladores.ControladorEstadisticas.java

License:Open Source License

public ArrayList<Element> ConsultarDocumentosCatalogados(boolean dow, boolean dom, boolean month, String year,
        String[] franja, String[] desde, String[] Hasta, boolean area, boolean autor, boolean doc_tipo,
        boolean pc, boolean usuario, int salida)
        throws BadElementException, MalformedURLException, IOException {

    ArrayList<Element> Salida = new ArrayList<Element>(100);
    ArrayList<Element> Images = new ArrayList<Element>(100);
    DaoEstadisticas controlador = new DaoEstadisticas();
    ResultSet rs;/*from   ww w  .  ja  v  a  2  s.  co m*/
    JFreeChart chart;
    BufferedImage bufferedImage;
    Image image;
    ArrayList<ArrayList<String>> resultadosTabla;
    ArrayList<String> Array2DtoArrayPlane;
    PdfPTable tabla = null;
    int total = 0;
    if (dow) {
        ArrayList<String> tmp = controlador.consultarDocumentosCatalogadosPorDoW();
        float promedio = promedio(tmp, 2);
        Salida.add(new Paragraph("Resultados de Documentos Catalogados para los das de la semana"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(
                biblioteca.reportes.PdfCreator.plainArrayListToPdfPTable(agregarPorcentajesALista(tmp, 2), 3));
        Salida.add(new Paragraph("Promedio " + promedio));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Pastel: Documentos Catalogados para los dias de la Semana"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(tmp),
                "Documentos Catalogados para los Das de la Semana");
        bufferedImage = chart.createBufferedImage(400, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 200);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo: Diagrama de Barras: Documentos Catalogados para los Das de la Semana"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(tmp),
                "Documentos Catalogados para los Das de la Semana", "Das de la Semana",
                "Cantidad de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(700, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(400, 200);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (dom) {
        rs = controlador.consultarDocumentosCatalogadosPorDoM();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Resultados de Documentos Catalogados para los das del mes"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(
                new Paragraph("* Ver Anexo: Diagrama de Pastel: Documentos Catalogados para los dias del mes"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Documentos Catalogados para los das del mes");
        bufferedImage = chart.createBufferedImage(500, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 300);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Documentos Catalogados para los das del Mes", "Das del mes", "Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(1000, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(500, 250);
        image.setAlignment(Image.MIDDLE);
        Salida.add(
                new Paragraph("* Ver Anexo: Diagrama de Barras: Documentos Catalogados para los dias del mes"));
        Salida.add(new Paragraph("\r\n"));
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (month) {
        ArrayList<String> tmp = controlador.consultarDocumentosCatalogadosPorMes();
        Salida.add(new Paragraph("Resultados de Documentos Catalogados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        float promedio = promedio(tmp, 2);
        Salida.add(
                biblioteca.reportes.PdfCreator.plainArrayListToPdfPTable(agregarPorcentajesALista(tmp, 2), 3));
        Salida.add(new Paragraph("Promedio " + promedio));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("* Ver Anexo: Diagrama de Pastel: Documentos Catalogados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(tmp),
                "Documentos Catalogados para los meses");
        bufferedImage = chart.createBufferedImage(500, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(350, 200);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("* Ver Anexo: Diagrama de Barras: Documentos Catalogados para los meses"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(tmp),
                "Documentos Catalogados para los Meses", "Meses", "Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(1000, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(500, 300);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (year != null) {
        ArrayList<String> tmp = controlador.consultarDocumentosCatalogadosPorYear(year);
        Salida.add(new Paragraph("Resultados para el ao seleccionado"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Ao: " + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (franja != null) {
        ArrayList<String> tmp = controlador.consultarDocumentosCatalogadosPorFranja(franja[0], franja[1]);
        Salida.add(new Paragraph("Resultados para la franja seleccionada"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Franja:" + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (desde != null && Hasta != null) {
        ArrayList<String> tmp = controlador.consultarDocumentosCatalogadosPorIntervalo(
                desde[0] + "-" + desde[1] + "-" + desde[2], Hasta[0] + "-" + Hasta[1] + "-" + Hasta[2]);
        Salida.add(new Paragraph("Resultados para el intervalo de tiempo seleccionado"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph("Intervalo de Tiempo: " + tmp.get(0) + ", Resultados:" + tmp.get(1)));
        Salida.add(new Paragraph("\r\n"));
    }
    if (area) {
        total = 0;
        rs = controlador.consultarDocumentosCatalogadosPorArea();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 2);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Areas con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Areas con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Areas con ms Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(600, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 300);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Areas con ms Documentos Catalogados", "Area_ID", "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(900, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(450, 250);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }

    if (autor) {
        total = 0;
        rs = controlador.consultarDocumentosCatalogadosPorAutor();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 1, 3);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Autores con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Autores con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Autores con ms Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(600, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(300, 300);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Autores con ms Documentos Catalogados", "Nombre Autor", "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(1000, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(400, 300);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (doc_tipo) {
        total = 0;
        rs = controlador.consultarDocumentosCatalogadosPorTipoMaterial();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Tipos de Material con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Tipos de Material con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Tipos de Material con ms Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(600, 600);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        bufferedImage = chart.createBufferedImage(300, 300);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Tipos de Material con ms Documentos Catalogados", "Tipo de Material",
                "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(900, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(450, 250);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (pc) {
        total = 0;
        rs = controlador.consultarDocumentosCatalogadosPorPalabraClave();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 1);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Palabras Clave con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Palabras Clave con ms Documentos Catalogados"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Palabras Clave con ms Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(500, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 250);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Palabras Clave con ms Documentos Catalogados", "Palabras Clave",
                "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(900, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(450, 250);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (usuario) {
        total = 0;
        rs = controlador.consultarDocumentosCatalogadosPorUsuarios();
        resultadosTabla = biblioteca.reportes.PdfCreator.resultSetToArrayList(rs);
        Array2DtoArrayPlane = biblioteca.reportes.PdfCreator.Array2DtoArrayPlane(resultadosTabla, 0, 2);
        for (int i = 1; i < resultadosTabla.size(); i++)
            total += Integer.parseInt(resultadosTabla.get(i).get(resultadosTabla.get(i).size() - 1));
        tabla = biblioteca.reportes.PdfCreator.arrayListToStatisticTable(resultadosTabla, total, salida);
        Salida.add(new Paragraph("Usuarios que mas Catalogan Documentos"));
        Salida.add(new Paragraph("\r\n"));
        Salida.add(tabla);
        Salida.add(new Paragraph("\r\n"));
        Salida.add(new Paragraph(
                "* Ver Anexo Diagrama de Pastel y Diagrama de Barras para Usuarios que mas Catalogan"));
        Salida.add(new Paragraph("\r\n"));
        chart = ChartCreator.generatePieChart(ChartCreator.asignarPieDataset(Array2DtoArrayPlane),
                "Usuarios que mas Catalogan");
        bufferedImage = chart.createBufferedImage(500, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(250, 250);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
        chart = ChartCreator.generateBarChart(ChartCreator.asignarBarDataset(Array2DtoArrayPlane),
                "Usuarios que mas Catalogan", "Username", "Numero de Documentos Catalogados");
        bufferedImage = chart.createBufferedImage(900, 500);
        image = Image.getInstance(EncoderUtil.encode(bufferedImage, "png"));
        image.scaleAbsolute(450, 250);
        image.setAlignment(Image.MIDDLE);
        Images.add(image);
        Images.add(new Paragraph("\r\n"));
    }
    if (!Images.isEmpty()) {
        Salida.add(new Paragraph("Anexos:"));
        Salida.add(new Paragraph("\r\n"));
    }
    for (int i = 0; i < Images.size(); i++) {
        Salida.add(Images.get(i));
    }
    return Salida;
}

From source file:br.com.bikefood.model.PdfGenerator.java

public File menuGenerator(File a, Bikefood bike) throws BadElementException, IOException {
    try {/*ww w  .j av a 2s . c  o m*/
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream(a.getAbsolutePath()));

        doc.open();

        doc.add(new Paragraph("Cardpio do Bike Food: " + bike.getName()));
        doc.add(new Paragraph("Especialidade em: " + bike.getType().getType()));
        doc.add(new Paragraph("\n"));
        doc.add(new Paragraph("\n"));

        Dal dal = new Dal();

        List<Product> cardapio = dal.getProducts((int) bike.getId());

        for (int x = 0; x < cardapio.size(); x++) {

            String image;

            if (cardapio.get(x).getImg().contains("br/com/bikefood")) {
                image = "C:\\Users\\Aluno\\Documents\\NetBeansProjects\\Bikefood\\src\\br\\com\\bikefood\\image\\product.png";

            } else {
                image = cardapio.get(x).getImg();

            }

            Image img = Image.getInstance(image);
            img.scaleAbsolute(125, 125);
            doc.add(img);

            doc.add(new Paragraph("Nome do Prato: " + cardapio.get(x).getName()));
            doc.add(new Paragraph("Preo do Prato: " + cardapio.get(x).getPrice()));
            doc.add(new Paragraph("Ingredientes: " + cardapio.get(x).getIngredients()));
            doc.add(new Paragraph("\n"));
            System.out.println(cardapio.get(x).getImg());
        }

        doc.close();

        return a;

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

    return a;
}

From source file:com.asae.controllers.BeanGestionRutinas.java

public void generarPdf() {
    Document document = new Document();
    try {//from   w w  w. j a v  a  2s.c  o m
        File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf"));
        pdfFileName = file.getName();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD);
        URL url = FacesContext.getCurrentInstance().getExternalContext()
                .getResource("/resources/img/logo-unicauca-negro.png");
        Image imgLogoUnicauca = Image.getInstance(url);
        imgLogoUnicauca.scaleAbsolute(118f, 131f);

        PdfPTable tableEncabezado = new PdfPTable(2);
        tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableEncabezado.setWidthPercentage(100);
        tableEncabezado.setSpacingAfter(5);
        PdfPCell cell1 = new PdfPCell(imgLogoUnicauca);
        cell1.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa"));
        cell2.setBorder(Rectangle.NO_BORDER);
        cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold));
        cell3.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold));
        cell4.setBorder(Rectangle.NO_BORDER);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableEncabezado.addCell(cell1);
        tableEncabezado.addCell(cell2);
        tableEncabezado.addCell(cell3);
        tableEncabezado.addCell(cell4);

        PdfPTable tableDatosUsuario = new PdfPTable(3);
        tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDatosUsuario.setWidthPercentage(100);
        tableDatosUsuario.setSpacingBefore(20);
        PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname()
                + " " + rutinaVisualizar.getIdusuario().getSecondname() + " "
                + rutinaVisualizar.getIdusuario().getFirstlastname() + " "
                + rutinaVisualizar.getIdusuario().getSecondlastname()));
        cell5.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell6 = new PdfPCell();
        cell6.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell7 = new PdfPCell();
        cell7.setBorder(Rectangle.NO_BORDER);

        tableDatosUsuario.addCell(cell5);
        tableDatosUsuario.addCell(cell6);
        tableDatosUsuario.addCell(cell7);

        PdfPTable tableFechas = new PdfPTable(3);
        tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableFechas.setWidthPercentage(100);
        tableFechas.setSpacingBefore(10);
        PdfPCell cell8 = new PdfPCell(
                new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio())));
        cell8.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell9 = new PdfPCell(
                new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin())));
        cell9.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell10 = new PdfPCell();
        cell10.setBorder(Rectangle.NO_BORDER);

        tableFechas.addCell(cell8);
        tableFechas.addCell(cell9);
        tableFechas.addCell(cell10);

        PdfPTable tableMedidas = new PdfPTable(4);
        tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableMedidas.setWidthPercentage(100);
        tableMedidas.setSpacingBefore(10);

        Usuario usuAux = rutinaVisualizar.getIdusuario();
        List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList();
        Evaluacion evalAux;
        double peso = 0;
        if (lstEvalAux.size() > 0) {
            evalAux = lstEvalAux.get(lstEvalAux.size() - 1);
            peso = evalAux.getPeso().doubleValue();
        }

        double estatura = 0;
        MedidasGenerales medGenAux = usuAux.getMedidasGenerales();
        if (medGenAux != null) {
            estatura = medGenAux.getEstatura().doubleValue();
        }

        PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso));
        cell11.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura));
        cell12.setBorder(Rectangle.NO_BORDER);

        double imc = 0;
        if (peso != 0 && estatura != 0) {
            imc = peso / Math.pow(estatura, 2);
        }

        PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc));
        cell13.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina()));
        cell14.setBorder(Rectangle.NO_BORDER);

        tableMedidas.addCell(cell11);
        tableMedidas.addCell(cell12);
        tableMedidas.addCell(cell13);
        tableMedidas.addCell(cell14);

        PdfPTable tableDias = new PdfPTable(2);
        tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDias.setWidthPercentage(100);
        tableDias.setSpacingBefore(20);
        tableDias.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableDias.setWidths(new int[] { 1, 9 });

        List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList();

        PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold));
        PdfPCell cellCabezeraDia2 = new PdfPCell();
        cellCabezeraDia2.setBorder(Rectangle.NO_BORDER);

        tableDias.addCell(cellCabezeraDia);
        tableDias.addCell(cellCabezeraDia2);

        for (Dia dia : lstDiasPDF) {
            PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString()));
            PdfPCell cellDia2 = new PdfPCell();
            cellDia2.setBorder(Rectangle.NO_BORDER);

            List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList();

            if (lstGMuscularPDF.size() > 0) {
                PdfPTable tableGMuscular = new PdfPTable(2);
                tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                tableGMuscular.setWidthPercentage(100);
                tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT);
                tableGMuscular.setWidths(new int[] { 1, 6 });

                PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold));
                cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                PdfPCell cellCabezeraGMuscular2 = new PdfPCell();
                cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER);
                tableGMuscular.addCell(cellCabezeraGMuscular);
                tableGMuscular.addCell(cellCabezeraGMuscular2);

                int aux = 1;
                for (GrupoMuscular gMuscularFor : lstGMuscularPDF) {
                    PdfPCell cellGMuscular = new PdfPCell(
                            new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre()));
                    cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                    PdfPCell cellGMuscular2 = new PdfPCell();
                    cellGMuscular2.setBorder(Rectangle.NO_BORDER);

                    List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList();
                    BaseColor myColor = WebColors.getRGBColor("#CCEEFF");
                    if (lstEjerciciosGMuscularPDF.size() > 0) {
                        PdfPTable tableEjercicioGMsucular = new PdfPTable(5);
                        tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                        tableEjercicioGMsucular.setWidthPercentage(100);
                        tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT);

                        PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold));
                        cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM);

                        PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold));
                        cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM2.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM2.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2);

                        PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold));
                        cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM3.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM3.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3);

                        PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold));
                        cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM4.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM4.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4);

                        PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold));
                        cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM5.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM5.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5);

                        int aux2 = 1;
                        for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) {
                            PdfPCell cellEjercicioGM = new PdfPCell(
                                    new Paragraph(ejercicioGm.getEjercicio().getNombre()));
                            cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM2 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getNumeroSeries().toString()));
                            cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM2.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM3 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getRepeticiones().toString()));
                            cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM3.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM4 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getReceso().toString()));
                            cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM4.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM5 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getPeso().toString()));
                            cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM5.setLeading(20f, 0f);

                            if (aux2 % 2 == 0) {
                                cellEjercicioGM.setBackgroundColor(myColor);
                                cellEjercicioGM2.setBackgroundColor(myColor);
                                cellEjercicioGM3.setBackgroundColor(myColor);
                                cellEjercicioGM4.setBackgroundColor(myColor);
                                cellEjercicioGM5.setBackgroundColor(myColor);
                            }

                            tableEjercicioGMsucular.addCell(cellEjercicioGM);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM2);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM3);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM4);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM5);
                            aux2++;
                        }
                        cellGMuscular2.addElement(tableEjercicioGMsucular);
                    }
                    tableGMuscular.addCell(cellGMuscular);
                    tableGMuscular.addCell(cellGMuscular2);
                    aux++;
                }
                cellDia2.addElement(tableGMuscular);
            }
            tableDias.addCell(cellDia);
            tableDias.addCell(cellDia2);
        }

        LineSeparator ls = new LineSeparator();
        document.add(tableEncabezado);
        document.add(ls);
        document.add(tableDatosUsuario);
        document.add(tableFechas);
        document.add(tableMedidas);
        document.add(tableDias);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex);
    }
}