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:PDF.Reporte_Final.java

private void addEncabezado(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 4);//  w  w  w  .  j  a  v a2  s  .c o m
    preface.setAlignment(Element.ALIGN_CENTER);
    preface.add(new Paragraph("E-SIBE", catFont));

    preface.add(new Paragraph("Reporte de resultados finales de la" + " beca SIBE de COFAA", smallBold));
    addEmptyLine(preface, 2);
    document.add(preface);
}

From source file:PdfCreation.PdfTableWriter.java

public Paragraph newParagraph(String text, boolean alignCenter, boolean alignLeft, boolean alignRight) {
    Paragraph ourParagraph = new Paragraph();
    if (alignCenter && !alignLeft && !alignRight) {
        ourParagraph.setAlignment(Element.ALIGN_CENTER);
    } else if ((!alignCenter && !alignLeft && !alignRight) && (!alignCenter && alignLeft && !alignRight)) {
        ourParagraph.setAlignment(Element.ALIGN_LEFT);
    } else if (!alignCenter && !alignLeft && alignRight) {
        ourParagraph.setAlignment(Element.ALIGN_RIGHT);
    }//w ww  .j a v  a  2s. c  o  m
    //    ourParagraph.setFont(new Font(Font.FontFamily.COURIER, 11));
    ourParagraph.add(text);
    return ourParagraph;
}

From source file:pipe.PdfMaker.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//ww w.ja  v  a  2s.  c  om
    // Lets write a big header
    Paragraph para = new Paragraph("Meine Pfeifensammlung", catFont);
    para.setAlignment(Element.ALIGN_CENTER);
    preface.add(para);

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Erstellt von: " + System.getProperty("user.name"), arialSmall));
    addEmptyLine(preface, 7);
    Image image = null;
    String frontpic = "db" + File.separator + "pipe-frontpage.jpg";

    try {
        ImageIcon icon = new ImageIcon(frontpic.toString());
        java.awt.Image img = icon.getImage();
        java.awt.Image newimg = img.getScaledInstance(500, -1, java.awt.Image.SCALE_SMOOTH);
        image = Image.getInstance(newimg, null);
    } catch (BadElementException e) {
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    Paragraph picture = new Paragraph("");
    picture.setAlignment(Element.ALIGN_CENTER);
    picture.add(image);
    preface.add(picture);
    addEmptyLine(preface, 10);

    preface.add(new Paragraph(
            "Dieser Katalog wurde mit Mat's pipe-manager erstellt.\nDie Software ist frei verfgbar und herunterladbar ber das Forum von www.komm-zur-pfeife.de.",
            arialSmall));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:pipe.PdfMaker.java

private Element FinalElement() {
    String legal = "Dieses Dokument wurde mit Mat's pipe-manager erstellt.";
    Paragraph element = new Paragraph(legal, this.arialMini);
    element.setAlignment(Element.ALIGN_JUSTIFIED);
    return element;
}

From source file:pkg412project.ReportPDF.java

public static void main(String args[])
        throws ClassNotFoundException, SQLException, DocumentException, FileNotFoundException {
    try {//  w w  w .  j  a va 2s  .  c o  m
        //Class.forName("oracle.jdbc.OracleDriver");
        int rowno = 0;
        String url = "jdbc:oracle:thin:@acaddb2.asu.edu:1521:orcl";
        String username = "sbmohan1";
        String password = "sbmohan1";

        Connection conn = DriverManager.getConnection(url, username, password);
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

        ResultSet rs = stmt.executeQuery("SELECT * FROM SBMOHAN1.ORDERTABLE");
        ResultSetMetaData rsmd = rs.getMetaData();
        int colno = rsmd.getColumnCount();
        while (rs.next()) {
            rowno++;
        }
        rs.first();
        Document d = new Document();
        PdfWriter.getInstance(d, new FileOutputStream("report.pdf"));
        Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 27);
        Font font3 = new Font(Font.FontFamily.COURIER, 12, Font.BOLD);
        float[] columnWidths = { 4f, 4f, 16f, 16f, 4f, 4f, 4f, 4f };
        PdfPTable ptable = new PdfPTable(colno);
        ptable.setWidths(columnWidths);
        d.open();
        Paragraph title = new Paragraph("Order Report", font1);
        title.setAlignment(Element.ALIGN_CENTER);
        d.add(title);
        Paragraph date = new Paragraph("December 10th, 2015", font2);
        date.setAlignment(Element.ALIGN_CENTER);
        d.add(date);
        //d.add(new Paragraph("Order Report"));

        //d.add(new Paragraph("Date: December 10th, 2015"));
        d.add(Chunk.NEWLINE);
        //d.add(Chunk.NEWLINE);
        ptable.addCell(new Paragraph("OrderID", font3));
        ptable.addCell(new Paragraph("NumItems", font3));
        ptable.addCell(new Paragraph("ItemsOrdered", font3));
        ptable.addCell(new Paragraph("OrderStatus", font3));
        ptable.addCell(new Paragraph("TotalPrice", font3));
        ptable.addCell(new Paragraph("PaymentID", font3));
        ptable.addCell(new Paragraph("TableID", font3));
        ptable.addCell(new Paragraph("ChefID", font3));

        //insertCell(ptable, "OrderID", Element.ALIGN_LEFT, 1, bfBold12);
        for (int i = 0; i < rowno; i++) {
            ptable.addCell("" + rs.getString(1));
            ptable.addCell("" + rs.getString(2));
            ptable.addCell("" + rs.getString(3));
            ptable.addCell("" + rs.getString(4));
            ptable.addCell("" + rs.getString(5));
            ptable.addCell("" + rs.getString(6));
            ptable.addCell("" + rs.getString(7));
            ptable.addCell("" + rs.getString(8));
            rs.next();
        }

        d.add(ptable);
        d.close();

    } catch (SQLException ex) {
        System.out.println(ex.toString());
    }
}

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFpersonales() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;// w w w.  j  av a  2s .  c o m

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Personales de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Titulo");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblHoy.addCell("Lugar");
        tblAntes.addCell("Titulo");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblAntes.addCell("Lugar");
        tblDespues.addCell("Titulo");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");
        tblDespues.addCell("Lugar");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 2");
        while (rs.next()) {
            String fecharecibida = rs.getString(2).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(3).substring(0, 5));
                tblHoy.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(3).substring(0, 5));
                tblAntes.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(3).substring(0, 5));
                tblDespues.addCell(H.desencriptar(rs.getString(4)));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFdeestudio() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*from  w  ww  .j  a  va  2 s .c om*/

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Estudio de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Asignatura");
        tblHoy.addCell("Tarea");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblAntes.addCell("Asignatura");
        tblAntes.addCell("Tarea");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblDespues.addCell("Asignatura");
        tblDespues.addCell("Tarea");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 1");
        while (rs.next()) {
            String fecharecibida = rs.getString(3).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(H.desencriptar(rs.getString(2)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(H.desencriptar(rs.getString(2)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(H.desencriptar(rs.getString(2)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(4).substring(0, 5));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmAgenda.java

public void PDF() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*from  ww w .  j a  v  a  2 s. c  o  m*/

    try {
        FacturaPdf = new FileOutputStream("archives/Notas.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Notas de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        PdfPTable tabla = new PdfPTable(2);
        tabla.addCell("Titulo");
        tabla.addCell("Descripcion");

        //sdfhfjhsdfsd

        rs = H.Buscar(
                "SELECT nom_nota, des_nota FROM Notas WHERE cod_usu = " + H.Usuario + " ORDER BY nom_nota ASC");
        while (rs.next()) {
            tabla.addCell(rs.getString(1));
            tabla.addCell(rs.getString(2));
        }

        //askjdhskfjhdf
        documento.add(tabla);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmVerContactos.java

public void PDF() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;// w ww  . ja va 2  s  .c om

    try {
        FacturaPdf = new FileOutputStream("archives/Contactos.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Contactos de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        PdfPTable tabla = new PdfPTable(4);
        tabla.addCell("Apellidos");
        tabla.addCell("Nombres");
        tabla.addCell("Telefono");
        tabla.addCell("Correo");

        //sdfhfjhsdfsd
        rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
        while (rs.next()) {
            cantidad_contactos += 1;
        }
        contactosdesordenados = new String[cantidad_contactos];
        rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
        while (rs.next()) {
            contactosdesordenados[num_contacto] = H.desencriptar(rs.getString(1));
            num_contacto += 1;
        }
        contactosordenados = new String[cantidad_contactos];
        Arrays.sort(contactosdesordenados);
        contactosordenados = contactosdesordenados;
        for (int i = 0; i < contactosordenados.length; i++) {
            if (!"".equals(contactosordenados[i].toString())) {
                rs = H.Buscar(
                        "SELECT ape_contacto, nom_contacto, tel1_contacto, correo_contacto FROM Contactos WHERE ape_contacto = '"
                                + H.encriptar(contactosordenados[i].toString()) + "'");
                while (rs.next()) {
                    tabla.addCell(H.desencriptar(rs.getString(1)));
                    tabla.addCell(H.desencriptar(rs.getString(2)));
                    tabla.addCell(rs.getString(3));
                    tabla.addCell(H.desencriptar(rs.getString(4)));
                }
            }
        }

        //askjdhskfjhdf
        documento.add(tabla);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:presentation.frmReportForm.java

private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed
    Date dateNow = new Date();
    SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");

    System.out.println(dtcMonthChooser.getMonth());
    System.out.println(dtcYearChooser.getYear());

    if (radInMonth.isSelected()) {
        List<Transfer> transferList = new ArrayList<>();

        transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear());

        Document document = new Document();
        try {//from   w  w  w. j  ava  2 s . c  om
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph(
                    "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(),
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);

            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (radInDateRange.isSelected()) {
        try {
            List<Transfer> transferList = new ArrayList<>();

            java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate());
            java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate());
            transferList = empObj.searchRecordByDate(fromDateSql, toDateSql);

            Document document = new Document();
            try {
                Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

                String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
                PdfWriter.getInstance(document, new FileOutputStream(fileName));

                document.open();

                Image imageLogo = Image
                        .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
                imageLogo.setAbsolutePosition(20, 750f);
                document.add(imageLogo);

                Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
                titlePara.setAlignment(Element.ALIGN_CENTER);
                titlePara.setSpacingAfter(5);
                document.add(titlePara);

                Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                        FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
                creditPara.setAlignment(Element.ALIGN_CENTER);
                creditPara.setSpacingAfter(10);
                document.add(creditPara);

                SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
                String fromDate = df2.format(dtcFromDate.getDate());
                String toDate = df2.format(dtcToDate.getDate());

                Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate,
                        FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
                slashPara.setSpacingAfter(40);
                slashPara.setAlignment(Element.ALIGN_CENTER);
                document.add(slashPara);

                PdfPTable table = new PdfPTable(5);
                table.setWidthPercentage(100);

                Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
                Paragraph paragraphCellHeading = new Paragraph("Report", font);

                PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
                BaseColor myColor = WebColors.getRGBColor("#41a5c2");
                cellHeading.setColspan(5);
                cellHeading.setBackgroundColor(myColor);
                cellHeading.setFixedHeight(30.3f);
                cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellHeading);

                Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

                PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
                cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle1);
                PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
                cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle2);
                PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
                cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle3);
                PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
                cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitle4);
                PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
                cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cellTitleStatus);

                int cellColorCheck = 1;
                for (Transfer e : transferList) {
                    PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                    PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                    PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                    PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                    PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                    if (cellColorCheck % 2 == 1) {
                        cellBody1.setBackgroundColor(BaseColor.ORANGE);
                        cellBody2.setBackgroundColor(BaseColor.ORANGE);
                        cellBody3.setBackgroundColor(BaseColor.ORANGE);
                        cellBody4.setBackgroundColor(BaseColor.ORANGE);
                        cellBody5.setBackgroundColor(BaseColor.ORANGE);
                    }
                    table.addCell(cellBody1);
                    table.addCell(cellBody2);
                    table.addCell(cellBody3);
                    table.addCell(cellBody4);
                    table.addCell(cellBody5);
                    cellColorCheck++;
                }

                document.add(table);
                JOptionPane.showMessageDialog(this, "Report saved");

                if (Desktop.isDesktopSupported()) {
                    File reportFile = new File(fileName);
                    Desktop.getDesktop().open(reportFile);
                    ;
                }

                document.close();
            } catch (DocumentException | FileNotFoundException ex) {
                Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ParseException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (radInProject.isSelected()) {
        String fromProjectId = (String) cbxFromProject.getSelectedItem();
        String toProjectId = (String) cbxToProject.getSelectedItem();
        List<Transfer> transferList = new ArrayList<>();
        String andOr = "";
        if (cbxAndOr.getSelectedItem().equals("And")) {
            andOr = "and";
            transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr);
        } else {
            andOr = "or";
            transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr);
        }

        Document document = new Document();
        try {
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph(
                    "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId,
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);
            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (radAllRecord.isSelected()) {
        List<Transfer> transferList = new ArrayList<>();
        transferList = empObj.searchAllRecord();

        Document document = new Document();
        try {
            Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);

            String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf";
            PdfWriter.getInstance(document, new FileOutputStream(fileName));

            document.open();

            Image imageLogo = Image
                    .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png"));
            imageLogo.setAbsolutePosition(20, 750f);
            document.add(imageLogo);

            Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle);
            titlePara.setAlignment(Element.ALIGN_CENTER);
            titlePara.setSpacingAfter(5);
            document.add(titlePara);

            Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh",
                    FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC));
            creditPara.setAlignment(Element.ALIGN_CENTER);
            creditPara.setSpacingAfter(10);
            document.add(creditPara);

            Paragraph slashPara = new Paragraph("All transfer records",
                    FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD));
            slashPara.setSpacingAfter(40);
            slashPara.setAlignment(Element.ALIGN_CENTER);
            document.add(slashPara);

            PdfPTable table = new PdfPTable(5);
            table.setWidthPercentage(100);

            Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD);
            Paragraph paragraphCellHeading = new Paragraph("Report", font);

            PdfPCell cellHeading = new PdfPCell(paragraphCellHeading);
            BaseColor myColor = WebColors.getRGBColor("#41a5c2");
            cellHeading.setColspan(5);
            cellHeading.setBackgroundColor(myColor);
            cellHeading.setFixedHeight(30.3f);
            cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellHeading);

            Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK);

            PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody));
            cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle1);
            PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody));
            cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle2);
            PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody));
            cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle3);
            PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody));
            cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitle4);
            PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody));
            cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cellTitleStatus);

            int cellColorCheck = 1;
            for (Transfer e : transferList) {
                PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId()));
                PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId()));
                PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId()));
                PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId()));
                PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus()));
                if (cellColorCheck % 2 == 1) {
                    cellBody1.setBackgroundColor(BaseColor.ORANGE);
                    cellBody2.setBackgroundColor(BaseColor.ORANGE);
                    cellBody3.setBackgroundColor(BaseColor.ORANGE);
                    cellBody4.setBackgroundColor(BaseColor.ORANGE);
                    cellBody5.setBackgroundColor(BaseColor.ORANGE);
                }
                table.addCell(cellBody1);
                table.addCell(cellBody2);
                table.addCell(cellBody3);
                table.addCell(cellBody4);
                table.addCell(cellBody5);
                cellColorCheck++;
            }

            document.add(table);
            JOptionPane.showMessageDialog(this, "Report saved");

            if (Desktop.isDesktopSupported()) {
                File reportFile = new File(fileName);
                Desktop.getDesktop().open(reportFile);
                ;
            }

            document.close();
        } catch (DocumentException | FileNotFoundException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}