Example usage for com.itextpdf.text.pdf PdfPCell setColspan

List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setColspan.

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:beans.SolicitudDeMantenimientoPDF.java

public void createPdf(String dest) throws IOException, DocumentException {
    Parametrizacion p = new Parametrizacion();
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/* w w w  . j av a2 s.c  o  m*/
    PdfPTable table = new PdfPTable(12);
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell celda;
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CODIGO: " + sm.getCodigo() + "\nREVISION: " + sm.getRevision()
            + "\nSOLICITUD DE SERVICIO: " + sm.getSolicitudDeServicio() + "\nFECHA: " + sm.getFecha() + "",
            font));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SECCION", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MAQUINA", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("NOMBRE DEL OPERARIO", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getUbicacion(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getNombre(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getOperario(), font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    String reparacion = " ";
    String mtoMecanico = " ";
    String mtoPreventivo = " ";
    String mtoElectrico = " ";
    String mtoCorrectivo = " ";
    String otros = " ";
    if (sm.isReparacion()) {
        reparacion += " X";
    }
    if (sm.isMtoMecanico()) {
        mtoMecanico += " X";
    }
    if (sm.isMtoPreventivo()) {
        mtoPreventivo += " X";
    }
    if (sm.isMtoElectrico()) {
        mtoElectrico += " X";
    }
    if (sm.isMtoCorrectivo()) {
        mtoCorrectivo += " X";
    }
    if (sm.isOtros()) {
        otros += " X";
    }

    celda = new PdfPCell(new Phrase("REPARACION", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(reparacion, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. MECANICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoMecanico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. PREVENTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoPreventivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. ELECTRICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoElectrico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. CORRECTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoCorrectivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("OTROS", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(otros, font));
    celda.setColspan(1);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DEL SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionServicio(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE ACCIONES A REALIZAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionAcciones(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("MATERIAL A EMPLEAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getMaterial(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("GENERALIDADES", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + sm.getHorasParada() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA SOLICITUD: " + sm.getHoraSolicitud() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + sm.getHorasMTO() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA ENTREGA: " + sm.getHoraEntrega() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO POR: " + sm.getSolicitadoPor() + "\n"
            + "SERVICIO REALIZADO POR: " + sm.getRealizadoPor() + "\n" + "RECIBO A CONFORMIDAD: "
            + sm.getRecibidoPor() + "\n\n\n FIRMA", font));
    celda.setColspan(12);
    table.addCell(celda);
    document.add(table);
    document.close();
}

From source file:bemyguest.controller.ValidationResevation.java

@FXML
private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException {
    Resrevation e = tab_reservation.getSelectionModel().getSelectedItem();
    if (e == null) {

        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle("Warning Dialog");
        alert.setHeaderText(null);//  w w  w .  j  a va  2s. c o  m
        alert.setContentText("selectionner un demande de  reservation a traiter svp!");

        alert.showAndWait();
        LoadData();
        setCellTable();
    }

    else {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("Confiramtion");
        alert.setHeaderText(null);
        alert.setContentText("vous etes sur d'accepter cette demande de reservation");
        Optional<ButtonType> answer = alert.showAndWait();

        if (answer.get() == ButtonType.OK) {
            ResevationDAO dao = new ResevationDAO();
            if (dao.ajouter_Reservation(e)) {

                LoadData();
                setCellTable();

                alert.setTitle("Success Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Demandes accepter avec success");

                alert.showAndWait();

                try {

                    Document d = new Document(PageSize.A4.rotate());
                    PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf"));
                    d.open();

                    d.add(new Paragraph("BeMyGuest Facture :",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
                    d.add(new Paragraph(new Date().toString()));
                    d.add(new Paragraph(
                            "-------------------------------------------------------------------------------------------------------------"));
                    d.add(new Paragraph("             "));
                    d.add(new Paragraph("             "));
                    PdfPTable pdt = new PdfPTable(7);
                    PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture"));
                    cell.setColspan(7);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.RED);
                    pdt.addCell(cell);

                    pdt.addCell(new Paragraph("Nom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prenom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Debut:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Fin:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre chambre:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre personne:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prix:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getNom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateDebut().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateFin().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(e.getDateDebut().toString());

                    int nb = e.getPropriete().getNbrChambre();

                    float pr = e.getPropriete().getPrix();
                    int nbp = e.getPropriete().getNbrVoyageur();
                    pdt.addCell(new Paragraph(Integer.toString(nb),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Integer.toString(nbp),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Float.toString(pr),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));

                    pdt.addCell(Float.toString(pr));

                    d.add(pdt);
                    d.close();
                } catch (Exception b) {

                    JOptionPane.showMessageDialog(null, b);
                }
            } else {
                alert.setTitle("Error Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Cette Propriete Reserver pendant cette date ");

                alert.showAndWait();

                LoadData();
                setCellTable();
            }
        }

        else {
            LoadData();
            setCellTable();
        }
    }

}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Alunos
public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/*from ww  w. ja  va  2 s.c  o  m*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaA.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF 
        PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos"));
        header.setColspan(5);
        tabelaA.addCell(header);
        tabelaA.addCell("ID");
        tabelaA.addCell("Matrcula");
        tabelaA.addCell("Nome");
        tabelaA.addCell("C.P.F");
        tabelaA.addCell("Telefone");
        Statement stA = conn.conectar1().createStatement();
        ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;");
        while (rsa.next()) {
            Aluno a = new Aluno(0, 0, "", "", "");
            a.setIdaluno(rsa.getInt("idAluno"));
            a.setMatricula(rsa.getInt("matriculaAluno"));
            a.setNoAluno(rsa.getString("nomeAluno"));
            a.setCpf(rsa.getString("nCPF"));
            a.setTelefone(rsa.getString("Telefone"));

            tabelaA.addCell(String.valueOf(a.getIdaluno()));
            tabelaA.addCell(String.valueOf(a.getMatricula()));
            tabelaA.addCell(a.getNoAluno());
            tabelaA.addCell(a.getCpf());
            tabelaA.addCell(a.getTelefone());

        }
        doc.add(tabelaA);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Livros
public void pdfL() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/*from w w w. j a  v a2 s  .c  om*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaL.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF
        PdfPTable tabelaL = new PdfPTable(new float[] { 0.1f, 0.7f, 0.7f, 0.1f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Livros"));
        header.setColspan(4);
        tabelaL.addCell(header);
        tabelaL.addCell("ID");
        tabelaL.addCell("Ttulo");
        tabelaL.addCell("Autor");
        tabelaL.addCell("Qtde.");

        Statement st = conn.conectar1().createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM `Livro`;");
        while (rs.next()) {
            Livro l = new Livro(0, "", "", 0, 0);
            l.setIdlivro(rs.getInt("idlivro"));
            l.setTiLivro(rs.getString("nomeLivro"));
            l.setNoAutor(rs.getString("nomeAutor"));
            l.setQtdeLivro(rs.getInt("qtdelivro"));

            tabelaL.addCell(String.valueOf(l.getIdlivro()));
            tabelaL.addCell(l.getTiLivro());
            tabelaL.addCell(l.getNoAutor());
            tabelaL.addCell(String.valueOf(l.getQtdeLivro()));
        }
        doc.add(tabelaL);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Reservas
public void pdfR() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;//from   w  w  w .  j a  v a2  s .  co m
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("Tabela de Reservas.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF
        PdfPTable tabelaR = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.7f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Reservas"));
        header.setColspan(5);
        tabelaR.addCell(header);
        tabelaR.addCell("ID");
        tabelaR.addCell("Ttulo do Livro");
        tabelaR.addCell("Aluno");
        tabelaR.addCell("Data de Saida");
        tabelaR.addCell("Data de Entrega");

        Statement stR = conn.conectar1().createStatement();
        ResultSet rsr = stR.executeQuery(
                "SELECT Itens.id_Itens as \"Item\", Itens.id_reserva AS \"Reserva\", Aluno.nomeAluno "
                        + "as \"Aluno\", Itens.id_Livro as \"idLivro\", Livro.nomeLivro AS \"NomeLivro\", Reserva.dataRetirada AS \"DataSaida\", Reserva.dataEntrega as \"DataEntrega\""
                        + "FROM Itens JOIN Reserva ON id_reserva = Reserva.idReserva\n"
                        + "JOIN Aluno ON Reserva.idAluno = Aluno.idAluno\n"
                        + "JOIN Livro ON Livro.idLivro = Itens.id_Livro;");
        while (rsr.next()) {
            Reserva r = new Reserva(0, 0, "", 0, "", "", "");

            r.setIdItem(rsr.getInt("Item"));
            r.setIdReserva(rsr.getInt("Reserva"));
            r.setNoAluno(rsr.getString("Aluno"));
            r.setIdLivro(rsr.getInt("idLivro"));
            r.setNoLivro(rsr.getString("NomeLivro"));
            r.setDaSaida(rsr.getString("DataSaida"));
            r.setDaEntrada(rsr.getString("DataEntrega"));

            tabelaR.addCell(String.valueOf(r.getIdReserva()));
            tabelaR.addCell(r.getNoLivro());
            tabelaR.addCell(r.getNoAluno());
            tabelaR.addCell(r.getDaSaida());
            tabelaR.addCell(r.getDaEntrada());

        }
        doc.add(tabelaR);
    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}

From source file:bl.pdf.PDFFile.java

private PdfPTable getTable(EntityTableModel tModel) {
    String[] headers = tModel.getColumnNames();

    PdfPTable table = new PdfPTable(headers.length);
    table.setHeaderRows(1);//w ww .java  2s . c om
    table.setWidthPercentage(100);
    for (String header : headers) {
        PdfPCell c1 = new PdfPCell(new Phrase(header));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    ArrayList<DBEntity> entries = tModel.getEntries();
    if (entries.isEmpty()) {
        PdfPCell c = new PdfPCell(new Phrase("Keine Eintrge vorhanden"));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setColspan(headers.length);
        table.addCell(c);
        return table;
    }
    for (DBEntity entry : entries) {
        for (String header : headers) {
            Method method;

            Object a;
            try {
                method = entry.getClass().getMethod("get" + header, new Class<?>[0]);
                a = method.invoke(entry, new Object[0]);
                table.addCell(String.valueOf(a));
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (SecurityException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            }
        }
    }
    return table;
}

From source file:bl.pdf.PDFFile.java

private PdfPTable getRechnungszeileTable(Rechnung r) throws DALException {
    String[] headers;//  ww w  .  j  a  va2  s  . com
    if (r instanceof Eingangsrechnung) {
        String[] h = { "Rechnungszeile", "Kommentar", "Steuersatz", "Betrag", "ohne Steuer" };
        headers = h;
    } else {
        String[] h = { "Rechnungszeile", "Kommentar", "AngebotID", "Steuersatz", "Betrag", "ohne Steuer" };
        headers = h;
    }
    PdfPTable table = new PdfPTable(headers.length);
    table.setHeaderRows(1);
    table.setWidthPercentage(100);
    for (String header : headers) {
        PdfPCell c1 = new PdfPCell(new Phrase(header));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    ArrayList<Rechnungszeile> rechnungszeilen = BL.getRechnungszeileListe(r.getRechnungID());
    if (rechnungszeilen.isEmpty()) {
        PdfPCell c = new PdfPCell(new Phrase("Keine Rechnungszeilen vorhanden"));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (r instanceof Ausgangsrechnung) {
            c.setColspan(6);
        } else {
            c.setColspan(5);
        }
        table.addCell(c);
        return table;
    }
    double summe = 0;
    double summeOhne = 0;
    for (Rechnungszeile rz : rechnungszeilen) {
        table.addCell(String.valueOf(rz.getRechnungszeileID()));
        table.addCell(String.valueOf(rz.getKommentar()));
        if (r instanceof Ausgangsrechnung) {
            table.addCell(String.valueOf(rz.getAngebotID()));
        }
        table.addCell(String.valueOf(rz.getSteuersatz()));
        table.addCell(String.valueOf(rz.getBetrag()));
        double betrag = rz.getBetrag();
        double steuersatz = rz.getSteuersatz();
        double betragOhne = betrag - (betrag / 100 * steuersatz);
        table.addCell(String.valueOf(betragOhne));
        summe += rz.getBetrag();
        summeOhne += betragOhne;
    }

    PdfPCell c = new PdfPCell(new Phrase("Summe"));
    c.setHorizontalAlignment(Element.ALIGN_RIGHT);
    if (r instanceof Ausgangsrechnung) {
        c.setColspan(4);
    } else {
        c.setColspan(3);
    }
    table.addCell(c);
    table.addCell(String.valueOf(summe));
    table.addCell(String.valueOf(summeOhne));

    return table;

}

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

License:Open Source License

/**
 * Generate an award report./*  w ww.  j  a  va2s. co  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.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.
 *//*from www  . j a va  2 s. 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: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  ww w. j a va  2s.co  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);
    }
}