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

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

Introduction

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

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:bouttime.report.award.AwardInventoryReport.java

License:Open Source License

private static PdfPTable getDataTable(int[] awardCounts, int maxAward) throws DocumentException {
    Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

    // create and add the table
    PdfPTable datatable = new PdfPTable(2);
    int colWidths[] = { 90, 10 }; // percentage
    datatable.setWidths(colWidths);//from  ww  w.  j a v  a  2 s .  co m
    datatable.setWidthPercentage(100);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    for (int i = 0; i < maxAward; i++) {
        if ((i % 2) == 0) {
            datatable.getDefaultCell().setGrayFill(0.9f);
        } else {
            datatable.getDefaultCell().setGrayFill(1);
        }

        String place = null;
        switch (i) {
        case 0:
            place = "1st Place";
            break;
        case 1:
            place = "2nd Place";
            break;
        case 2:
            place = "3rd Place";
            break;
        case 3:
            place = "4th Place";
            break;
        case 4:
            place = "5th Place";
            break;
        case 5:
            place = "6th Place";
            break;
        case 6:
            place = "7th Place";
            break;
        default:
            logger.warn("unexpected place value : " + i);
            place = "???";
            break;
        }

        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(new Phrase(place, detailFont));

        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(Integer.toString(awardCounts[i]), detailFont));
    }

    datatable.setSpacingBefore(5f);
    datatable.setSpacingAfter(15f);

    return datatable;
}

From source file:bouttime.report.award.AwardReport.java

License:Open Source License

/**
 * Generate an award report./*from w  ww  .  j  av  a2s  .  c o m*/
 * @param dao Dao object to use to retrieve data.
 * @param session Session to generate the report for.
 * @param group Group to generate report for.  This takes precedence, so
 * if not null, then the report will be generated for this group.
 * @return True if the report was generated.
 */
private static boolean doReport(Dao dao, String session, Group group) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<Group> groups;
        if (group != null) {
            groups = new ArrayList<Group>();
            groups.add(group);
        } else if (session != null) {
            groups = dao.getGroupsBySession(session);
        } else {
            groups = dao.getAllGroups();
        }

        for (Group g : groups) {

            // create and add the table
            PdfPTable datatable = new PdfPTable(4);
            int colWidths[] = { 30, 30, 30, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the group name
            headerCell.setPhrase(new Phrase(g.toString(), headerFont));
            headerCell.setColspan(4);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            List<Wrestler> wList = getSortedAwardList(g);

            int i = 0;
            for (Wrestler w : wList) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                Integer place = w.getPlace();
                String placeStr = (place == null) ? "" : place.toString();
                datatable.addCell(new Phrase(placeStr, detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.boutsequence.BoutSequenceReport.java

License:Open Source License

private static PdfPTable addBoutSequences(List<Wrestler> wList, String session) throws DocumentException {
    // create and add the table
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
    Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell headerCell = new PdfPCell();
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setPadding(3);// ww w .j  a v a  2s  .  co  m
    headerCell.setBorderWidth(2);
    PdfPTable datatable = new PdfPTable(3);
    int colWidths[] = { 5, 25, 70 }; // percentage
    datatable.setWidths(colWidths);
    datatable.setWidthPercentage(100);
    datatable.getDefaultCell().setPadding(3);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    headerCell.setPhrase(new Phrase("Mat", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Name", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Bout Sequence", headerFont));
    datatable.addCell(headerCell);

    datatable.setHeaderRows(1); // this is the end of the table header

    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    Collections.sort(wList, new WrestlerMatNameSort());

    int i = 0;
    for (Wrestler w : wList) {
        if (w.getGroup() == null) {
            logger.debug(String.format("Wrestler [%s] is not in a group, skipping.", w.getShortName()));
            continue;
        }

        if ((session != null) && !session.equalsIgnoreCase(w.getGroup().getSession())) {
            logger.debug(String.format("Wrestler [%s] is in a group but not in session %s, skipping.",
                    w.getShortName(), session));
            continue;
        }

        if ((i++ % 2) == 0) {
            datatable.getDefaultCell().setGrayFill(0.9f);
        } else {
            datatable.getDefaultCell().setGrayFill(1);
        }

        List<Bout> bList = BoutSequence.calculate(w);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(w.getGroup().getMat(), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(new Phrase(String.format("%s %s", w.getFirstName(), w.getLastName()), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        String boutSequenceString = getBoutSequenceString(bList);
        datatable.addCell(new Phrase(boutSequenceString, detailFont));
    }

    datatable.setSpacingBefore(5f);
    datatable.setSpacingAfter(15f);
    return (i > 0 ? datatable : null);
}

From source file:bouttime.report.matkey.MatKeyReport.java

License:Open Source License

/**
 * Generate the Mat Key report.//from   ww  w  . ja v  a2  s  .  c o  m
 * This is a color-coded report that maps the groups to a mat.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 */
public static boolean doReport(Dao dao) {
    if (!dao.isOpen()) {
        logger.warn("Cannot create report : DAO not open");
        return false;
    }

    String matValues = dao.getMatValues();
    if ((matValues == null) || matValues.isEmpty()) {
        JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame();
        JOptionPane.showMessageDialog(mainFrame,
                "Mat values are not configured." + "\nSet the mat values in 'Edit -> Configuration'",
                "Mat Key Report error", JOptionPane.WARNING_MESSAGE);
        logger.warn("Cannot create report : mat values not configured");
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Mat Key Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        int cols = 4; // Class, Div, Weight, Mat

        // create and add the table
        PdfPTable datatable = new PdfPTable(cols);
        //int colWidths[] = { 55, 15, 15, 15 };   // percentage
        //datatable.setWidths(colWidths);
        datatable.getDefaultCell().setPadding(3);
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        datatable.addCell("Class");
        datatable.addCell("Div");
        datatable.addCell("Weight");
        datatable.addCell("Mat");
        datatable.setHeaderRows(1); // this is the end of the table header

        datatable.getDefaultCell().setBorderWidth(1);

        // Prepare the list of groups
        List<Group> groups = dao.getAllGroups();
        Collections.sort(groups, new GroupClassDivWtSort());

        // Prepare the list of mat values
        String[] mats = matValues.split(",");
        List<String> matList = new ArrayList<String>();
        for (String m : mats) {
            matList.add(m.trim());
        }

        for (Group g : groups) {
            String mat = g.getMat();
            int idx = matList.indexOf(mat);
            datatable.getDefaultCell().setBackgroundColor(colorMap.get(idx));

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell(g.getClassification());
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            datatable.addCell(g.getAgeDivision());
            datatable.addCell(g.getWeightClass());
            datatable.addCell(g.getMat());
        }

        datatable.setSpacingBefore(15f); // space between title and table
        document.add(datatable);

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a summary report of the teams in the tournament.
 * This report lists the teams and the number of wresters on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 *///from  ww w.j a v  a2  s.com
public static boolean doSummary(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Summary Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        int cols = 2; // Team name and Total
        String classVals = dao.getClassificationValues();
        String[] classes = null;
        if (classVals != null) {
            if (classVals.length() > 0) {
                classes = classVals.split(",");
                cols += classes.length;
            }
        }

        // create and add the table
        PdfPTable datatable = new PdfPTable(cols);
        //int colWidths[] = { 55, 15, 15, 15 };   // percentage
        //datatable.setWidths(colWidths);
        datatable.getDefaultCell().setPadding(3);
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        datatable.addCell("Team Name");

        // Make a column for each classification value
        int[] classesTotals = null;
        if (classes != null) {
            for (String c : classes) {
                datatable.addCell(c.trim());
            }
            classesTotals = new int[classes.length];
            for (int i = 0; i < classesTotals.length; i++) {
                classesTotals[i] = 0;
            }
        }
        datatable.addCell("Total");
        datatable.setHeaderRows(1); // this is the end of the table header

        datatable.getDefaultCell().setBorderWidth(1);

        List<String> teams = dao.getTeams();

        int total = 0; // total count of all wrestlers in this method
        int i = 0;
        for (String t : teams) {
            if ((i++ % 2) == 0) {
                datatable.getDefaultCell().setGrayFill(0.9f);
            } else {
                datatable.getDefaultCell().setGrayFill(1);
            }

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();
            int rowTotal = 0;
            total += count;

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell(t);
            if (classes != null) {
                //for (String c : classes) {
                for (int idx = 0; idx < classes.length; idx++) {
                    String c = classes[idx].trim();
                    List<Wrestler> wrestlers2 = dao.getWrestlersByTeamClass(t, c);
                    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                    int count2 = wrestlers2.size();
                    datatable.addCell(Integer.toString(count2));
                    classesTotals[idx] += count2;
                    rowTotal += count2;
                }
            }

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            datatable.addCell(Integer.toString(count));

            // Check if there is an error in the counts.
            if ((classes != null) && (rowTotal != count)) {
                JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame();
                JOptionPane.showMessageDialog(mainFrame,
                        "There is an error" + " with the total count for team '" + t + "'.\n" + "This is "
                                + "most likely due to an incorrect classification value\nfor "
                                + "one or more wrestlers.",
                        "Team count error", JOptionPane.WARNING_MESSAGE);
            }
        }

        // Add totals row
        datatable.getDefaultCell().setGrayFill(0.7f);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell("Total");
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (classes != null) {
            for (int idx = 0; idx < classesTotals.length; idx++) {
                datatable.addCell(Integer.toString(classesTotals[idx]));
            }
        }

        datatable.addCell(Integer.toString(total));

        datatable.setSpacingBefore(15f);
        document.add(datatable);

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a detail report of the teams in the tournament.
 * This report includes the teams and all of the wrestlers on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 */// ww  w. ja  va 2s.  c  om
public static boolean doDetail(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<String> teams = dao.getTeams();

        for (String t : teams) {

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();

            // create and add the table
            PdfPTable datatable = new PdfPTable(5);
            int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the team name and the number of entries
            headerCell.setPhrase(new Phrase(t, headerFont));
            headerCell.setColspan(3);
            datatable.addCell(headerCell);

            headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont));
            headerCell.setColspan(2);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.weighin.WeighInReport.java

License:Open Source License

/**
 * Generate a report of the entries in the tournament for weigh-in.
 * @param sections List of sections for the report.  Each section will start
 *     on a new page./* ww  w  .  j a  v a 2  s  .  c o m*/
 * @param headerString String to be used for the header of each page of the report.
 * @return True if the report was generated.
 */
public static boolean doReport(List<List<Wrestler>> sections, String headerString) {
    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        if (headerString != null) {
            Paragraph p1 = new Paragraph(
                    new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10)));
            document.add(p1);
        }

        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

        for (List<Wrestler> wrestlers : sections) {
            // create and add the table
            PdfPTable datatable = new PdfPTable(7);
            int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            //datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
                datatable.addCell(new Phrase()); // actual weight
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
            document.newPage();
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bussiness.ReportHandler.java

public void BuildSaleReport(double totalCost) {
    try {/*from  w  w  w  . j a v  a2s  .  c o m*/
        // Se crea el documento
        Document documento = new Document();
        // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
        FileOutputStream ficheroPdf = new FileOutputStream("fichero.pdf");

        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        Image imagen = Image.getInstance("logo.jpeg");

        documento.open();
        PdfPTable table = new PdfPTable(2);
        table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table.getDefaultCell().setPaddingLeft(60);
        BuildHeaderSaleReport(documento);

        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));
        documento.add(new Chunk("\n"));

        imagen.setAbsolutePosition(110f, 150f);

        BuildBodySaleReport(table, totalCost, documento);

        BuildFooterSaleReport(documento);
        documento.add(imagen);
        documento.close();

    } catch (Exception e) {
        System.err.println("Ocurrio un error: " + e);
        System.exit(-1);
    }
}

From source file:bussiness.ReportHandler.java

public void BuildVeterinaryPrescription(String clientName, String petName, List<Medicine> medicines,
        String comments, Double totalCost) {
    try {/*  w w  w  .j  ava  2 s .c om*/
        Document veterinaryPrescription = new Document(PageSize.A3.rotate());
        //Tal vez agregar la fecha al nombre de la receta
        FileOutputStream fileOutputStream = new FileOutputStream("prescription.pdf");
        PdfWriter.getInstance(veterinaryPrescription, fileOutputStream).setInitialLeading(20);
        Image logo = Image.getInstance("logo2.png");
        Image division = Image.getInstance("linea.png");
        veterinaryPrescription.open();
        division.setAbsolutePosition(20f, 600f);
        veterinaryPrescription.add(division);
        logo.setAbsolutePosition(400, 50f);
        veterinaryPrescription.add(logo);

        //Encabezado
        BuildHeaderPrescription(veterinaryPrescription, clientName, petName);

        //Cuerpo
        veterinaryPrescription.add(new Chunk("\n"));
        veterinaryPrescription.add(new Chunk("\n"));
        veterinaryPrescription.add(new Chunk("\n"));

        PdfPTable table = new PdfPTable(3);
        table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table.getDefaultCell().setPaddingLeft(60);

        BuildBodyPrescription(medicines, veterinaryPrescription, totalCost, table);

        BuildFooterPrescription(veterinaryPrescription, comments);

        veterinaryPrescription.close();
    } catch (Exception e) {
        System.err.println("Ocurrio un error: " + e);
        System.exit(-1);
    }
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteInventario() {
    Connection con;/*  w w  w .  j  a  v  a2 s  .c o  m*/
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Cantidad, Cantidadmin,  Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.Composicion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento ");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_inventario " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Elaboracion");
            table.addCell("Fecha de Vencimiento");
            table.addCell("Cantidad minima");
            table.addCell("Cantidad actual");
            table.addCell("Cantidad maxima");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("FechaElaboracion"));
            table.addCell(res.getString("FechaVencimiento"));
            table.addCell(res.getString("Cantidadmin"));
            table.addCell(res.getString("Cantidad"));
            table.addCell(res.getString("Cantidadmax"));
        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Inventario generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }

}