Example usage for com.itextpdf.text Paragraph setAlignment

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

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:bladwin.web.reg.regPDF.java

public void genPed(String loc, regMgr regMgr, dbMgrInterface db) {
    Document document = null;/*from  ww  w .j a  v a2 s  .  c  o  m*/
    //String loc = "C:/_bisc/_javaApps/jlData/jvp/CellWidths.pdf";

    //regMgr.getCustomerRegBean().setPdf(loc);
    try {

        document = new Document(PageSize.A4, 30, 30, 30, 30);
        PdfWriter.getInstance(document, new FileOutputStream(loc));
        document.open();
        customerRegBean r = regMgr.getCustomerRegBean();
        customerBean c = regMgr.getCustomerBean();
        customerBean a = new custObj().getcustomerBean(r.getRegCustId(), db);
        mgnLookupBean bean = new mgnLookupObj().getLookupBean(-947, db);
        Paragraph pg;
        pg = new Paragraph(r.getLookupDesc());
        pg.setAlignment(Paragraph.ALIGN_CENTER);
        pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
        document.add(getHeader(r.getLookupDesc()));
        document.add(getHeader("BALDWIN BLAZERS TRACK CLUB"));
        document.add(getHeader("REGISTRATION"));
        pg = new Paragraph("\n\r");
        document.add(pg);
        // -------------------------------------------------------
        document.add(genAthleteInfo(r, a));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genParentInfo(c));
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(genSport(r));
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("PARENTS SIGNATURE");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        pg = new Paragraph("_____________________________________________________________________");
        document.add(pg);
        pg = new Paragraph("\n\r");
        document.add(pg);
        document.add(getHeader(r.getFeeDesc() + "\n\r" + bean.getSubjectBody()));
        // ----------------------------------------------------------------------------

    } catch (DocumentException ex) {
        logger.error("DocumentException", ex);
    } catch (FileNotFoundException ex) {
        logger.error("FileNotFoundException", ex);
    } finally {
        try {
            if (document != null)
                document.close();

            //pdfFileOpen(loc);

        } catch (Exception e) {
            logger.error("FileNotFoundException", e);
        }
    }
}

From source file:bladwin.web.reg.regPDF.java

private Paragraph getHeader(String text) {
    Paragraph pg = new Paragraph(text);
    pg.setAlignment(Paragraph.ALIGN_CENTER);
    pg.setFont(FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
    return pg;//  w ww.j av a 2 s  . c o m
}

From source file:Boss.BOss.java

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
    if (evt.getClickCount() == 2) {
        try {//w  w  w.  j  av  a 2  s .  c  o m
            connect = new Connection();
            Statement st = connect.con.createStatement();
            String SQL = "SELECT * FROM request where idrequest =" + getSelectedrequest1();
            ResultSet rq = st.executeQuery(SQL);
            rq.next();
            /*****************************/
            String type = "";
            if (parseInt(rq.getString("id_type")) == 1) {
                type = "Instalation";
            }
            if (parseInt(rq.getString("id_type")) == 2) {
                type = "Transfer";
            }
            if (parseInt(rq.getString("id_type")) == 3) {
                type = "Maintenamce";
            }
            /**************************/
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream("report.pdf"));
            document.open();

            Paragraph paragraph = new Paragraph();
            paragraph.add(new Paragraph("Request : \n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
            paragraph.add("ID Request :");
            paragraph.add(rq.getString("idRequest") + "");
            paragraph.add("\nRequest type :");
            paragraph.add(type);
            paragraph.add("\nClient name :");
            paragraph.add(rq.getString("clientName"));
            paragraph.add("\nPhone number :");
            paragraph.add(rq.getString("TELCLIENT"));
            paragraph.add("\nAddress 1 :");
            paragraph.add(rq.getString("address1"));
            paragraph.add("\nAddress 2 :");
            paragraph.add(rq.getString("address2"));
            paragraph.add("\nTeam :");
            paragraph.add(rq.getString("IDTEAM") + "\n");
            /***********************/
            String sql = "Select * from report where IDREQUEST = '" + getSelectedrequest1() + "' ";
            ResultSet rs = st.executeQuery(sql);
            rs.next();
            /**********************/

            paragraph.add(new Paragraph("Report : \n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.DARK_GRAY)));
            paragraph.add(rs.getString("REPORT") + "\n");
            Paragraph date = new Paragraph(rs.getString("REPORTDATE").toString().substring(0, 10));
            date.setAlignment(Element.ALIGN_RIGHT);
            Paragraph title = new Paragraph("Report\n",
                    FontFactory.getFont(FontFactory.COURIER_BOLD, 20, Font.BOLD, BaseColor.BLACK));
            title.setAlignment(Element.ALIGN_CENTER);
            document.add(date);
            document.add(title);
            document.add(paragraph);
            document.close();
            /* Open Pdf */
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("report.pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (SQLException | ClassNotFoundException | DocumentException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(BOss.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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

License:Open Source License

/**
 * Generate an award report.//from   www. j a  v  a 2s . 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.
 */
public static boolean doReport(Dao dao) {
    if (!dao.isOpen()) {
        logger.warn("DAO is not open");
        return false;
    }

    if (dao.getMaxAward() == null) {
        logger.warn("Max Award value is NULL");
        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 Inventory Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        PdfPTable datatable;
        int[] awardCounts = getAwardCountsForClassDivWeight(dao);
        if (awardCounts != null) {
            Paragraph p3 = new Paragraph(new Paragraph("\nFor class/age division/weight class",
                    FontFactory.getFont(FontFactory.HELVETICA, 11)));
            p3.setAlignment(Paragraph.ALIGN_LEFT);
            document.add(p3);
            datatable = getDataTable(awardCounts, dao.getMaxAward());
            document.add(datatable);
        }

        awardCounts = getAwardCountsForExistingGroups(dao);
        if (awardCounts != null) {
            Paragraph p3 = new Paragraph(
                    new Paragraph("\nFor existing groups", FontFactory.getFont(FontFactory.HELVETICA, 11)));
            p3.setAlignment(Paragraph.ALIGN_LEFT);
            document.add(p3);
            datatable = getDataTable(awardCounts, dao.getMaxAward());
            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.award.AwardReport.java

License:Open Source License

/**
 * Generate an award report.// w w w  .  j  av  a2  s.  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.matkey.MatKeyReport.java

License:Open Source License

/**
 * Generate the Mat Key report.//from w ww .  j av a  2  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.
 *///ww  w .ja v  a  2s  . c  o  m
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 .jav  a 2 s .  c  o  m
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:br.com.tcc.relat.BalancoAnual.java

public static void main(String[] args) throws Exception {
    /* Create Connection objects */
    Connection con = new ConnectionFactory().getConnection();
    Statement stmt = con.createStatement();
    /* Define the SQL query */
    ResultSet query = stmt.executeQuery(
            "SELECT produto.ID, produto.descricao, produto.numEstoque, produto.numEstoqueCritico, unidade.descricao, fornecedor.nome FROM produto as produto INNER JOIN unidade as unidade ON (produto.idUnidade = unidade.id) INNER JOIN fornecedor as fornecedor ON (produto.idFornecedor = fornecedor.id)");
    /* Step-2: Initialize PDF documents - logical objects */
    Document PDFLogReport = new Document();
    //PdfWriter.getInstance(PDFLogReport, new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Balanco.pdf"));
    PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../RelatBalanco.pdf"));
    PDFLogReport.open();//from  www. j a va2 s.  c  o  m

    Paragraph cabecalho = new Paragraph(
            "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n"
                    + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n");
    cabecalho.setAlignment(Element.ALIGN_CENTER);
    PDFLogReport.add(cabecalho);
    //we have two columns in our table  
    PdfPTable LogTable = new PdfPTable(6);

    // Ttulo para a tabela
    Paragraph tableHeader = new Paragraph("Balano Anual");

    PdfPCell header = new PdfPCell(tableHeader);

    // Definindo que o header vai ocupar as 2 colunas
    header.setColspan(6);
    // Definindo alinhamento do header
    header.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    // Adicionando o header  tabela

    Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK);
    Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);
    LogTable.addCell(header);
    LogTable.addCell(new Paragraph("Produto ", fonte));
    LogTable.addCell(new Paragraph("Fornecedor", fonte));
    LogTable.addCell(new Paragraph("Unidade", fonte));
    LogTable.addCell(new Paragraph("Estoque", fonte));
    LogTable.addCell(new Paragraph("Estoque Crtico", fonte));
    LogTable.addCell(new Paragraph("Quantidade", fonte));
    //create a cell object  
    //         PdfPCell table_cell;  
    while (query.next()) {
        String produto = query.getString("descricao");
        LogTable.addCell(new Paragraph(produto, fonteDados));
        String fornecedor = query.getString("nome");
        LogTable.addCell(new Paragraph(fornecedor, fonteDados));
        String unidade = query.getString("unidade.descricao");
        LogTable.addCell(new Paragraph(unidade, fonteDados));
        String estoque = query.getString("numEstoque");
        LogTable.addCell(new Paragraph(estoque, fonteDados));
        String critico = query.getString("numEstoqueCritico");
        LogTable.addCell(new Paragraph(critico, fonteDados));
        LogTable.addCell(new Paragraph("       ", fonteDados));
    }
    /* Attach report table to PDF */
    PDFLogReport.add(LogTable);
    PDFLogReport.close();
    /* Close all DB related objects */
    query.close();
    stmt.close();
    con.close();
    String file;
    file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Balanco.pdf";
    //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file);

    File pdf = new File("../../RelatBalanco.pdf");
    try {
        Desktop.getDesktop().open(pdf);
    } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex);
    }
}

From source file:br.com.tcc.relat.ConsultarVendas.java

public void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException {
    /* Create Connection objects */
    Connection con = new ConnectionFactory().getConnection();
    Statement stmt = con.createStatement();
    /* Define the SQL query */
    //         sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" +
    //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE  dataVenda = CURRENT_DATE";
    ResultSet query = stmt.executeQuery(sql);
    /* Step-2: Initialize PDF documents - logical objects */
    Document PDFLogReport = new Document();
    PdfWriter.getInstance(PDFLogReport, new FileOutputStream("../../VendaDoDia.pdf"));
    PDFLogReport.open();//from   ww  w . ja  va 2s .  c om

    Paragraph cabecalho = new Paragraph(
            "AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n" + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n"
                    + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n" + "CNPJ: 12.345.678/1011-12\n\n\n");
    cabecalho.setAlignment(Element.ALIGN_CENTER);
    PDFLogReport.add(cabecalho);
    //we have two columns in our table  
    PdfPTable LogTable = new PdfPTable(9);

    // Ttulo para a tabela
    Paragraph tableHeader = new Paragraph("Relatrio Venda do Dia");

    PdfPCell header = new PdfPCell(tableHeader);

    // Definindo que o header vai ocupar as 2 colunas
    header.setColspan(9);
    // Definindo alinhamento do header
    header.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    // Adicionando o header  tabela

    Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK);
    Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);

    LogTable.addCell(header);
    LogTable.addCell(new Paragraph("Cliente ", fonte));
    LogTable.addCell(new Paragraph("Funcionario", fonte));
    LogTable.addCell(new Paragraph("Tipo Pagamento", fonte));
    LogTable.addCell(new Paragraph("Data Compra", fonte));
    LogTable.addCell(new Paragraph("Valor Sugerido", fonte));
    LogTable.addCell(new Paragraph("Valor da Venda", fonte));
    LogTable.addCell(new Paragraph("Parcelas", fonte));
    LogTable.addCell(new Paragraph("1 Vencimento", fonte));
    LogTable.addCell(new Paragraph("Status da Compra", fonte));
    //create a cell object  
    //         PdfPCell table_cell;  
    while (query.next()) {
        String cliente = query.getString("cliente.nome");
        LogTable.addCell(new Paragraph(cliente, fonteDados));
        String funcionario = query.getString("funcionario.nome");
        LogTable.addCell(new Paragraph(funcionario, fonteDados));
        String tipoPagamento = query.getString("tipopagamento.descricao");
        LogTable.addCell(new Paragraph(tipoPagamento, fonteDados));
        String dataVenda = query.getString("dataVenda");
        LogTable.addCell(new Paragraph(dataVenda, fonteDados));
        String vlrSugerido = query.getString("vlrSugerido");
        LogTable.addCell(new Paragraph(vlrSugerido, fonteDados));
        String totalVenda = query.getString("totalVenda");
        LogTable.addCell(new Paragraph(totalVenda, fonteDados));
        String parcela = query.getString("parcela");
        LogTable.addCell(new Paragraph(parcela, fonteDados));
        String vencimento = query.getString("1vencimento");
        LogTable.addCell(new Paragraph(vencimento, fonteDados));
        String ativo = query.getString("ativo");
        LogTable.addCell(new Paragraph(ativo, fonteDados));
    }
    /* Attach report table to PDF */
    PDFLogReport.add(LogTable);
    PDFLogReport.close();
    /* Close all DB related objects */
    query.close();
    stmt.close();
    con.close();
    String file;
    file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\VendaDoDia.pdf";
    //Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file);
    File pdf = new File("../../VendaDoDia.pdf");
    try {
        Desktop.getDesktop().open(pdf);
    } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Erro ao abrir relatrio: " + ex);
    }
}