Example usage for com.itextpdf.text Font ITALIC

List of usage examples for com.itextpdf.text Font ITALIC

Introduction

In this page you can find the example usage for com.itextpdf.text Font ITALIC.

Prototype

int ITALIC

To view the source code for com.itextpdf.text Font ITALIC.

Click Source Link

Document

this is a possible style.

Usage

From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java

@Override
public void enregistrerBulletin() {
    if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("user")) {

        if (eleveAnneeClasse.getId() != null) {
            classematieres.clear();/*w  ww.  j a  va 2 s  .  c  om*/
            matieres.clear();
            notesPropres.clear();
            matiereCompses.clear();
            eleveAnneeClasse = eleveAnneeClasseFacade.find(eleveAnneeClasse.getId());
            if (sequence != null) {
                Annee an = anneeFacade.findByEtatSingle(true);
                Eleveanneeclasse eleveClasse = eleveAnneeClasseFacade.getEleveAnneeClaseByAnneClasse(
                        eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee());
                if (eleveClasse != null) {
                    List<Naturematiere> nature = natureMatiereFacade.findAll();
                    if (!nature.isEmpty()) {
                        List<Evaluation> notes = evaluationFacadeLocal.getByEleveAnneeSequence(
                                eleveAnneeClasse.getEleve().getIdeleve(), an.getIdannee(),
                                sequence.getIdsequencean());

                        /*if (!notes.isEmpty()) {*/
                        try {

                            String bulletinName = "" + eleveAnneeClasse.getEleve().getNom() + "_"
                                    + eleveAnneeClasse.getEleve().getPrenom() + "_"
                                    + sequence.getIdsequence().getNom() + ".pdf";
                            Document bulletin = new Document();

                            PdfWriter.getInstance(bulletin, new FileOutputStream(Utilitaires.path + "/"
                                    + Utilitaires.repertoireParDefautBulletin + "/" + bulletinName));

                            bulletin.setMargins(5, 5, 5, 5);
                            bulletin.addCreator("School Manager");
                            bulletin.setPageSize(PageSize.A4);

                            bulletin.open();

                            //tableau qui va contenir les notes
                            PdfPTable table = new PdfPTable(5);
                            table.setComplete(true);

                            //entete de bulletin
                            table.addCell(
                                    PrintUtils.createPdfPCell("COLLEGE POZAM Anne Scolaire " + an.getCode()
                                            + " - " + (an.getCode() + 1) + " " + an.getTheme(), 5, detail));
                            table.addCell(PrintUtils.createPdfPCell(
                                    "BULLETIN DE NOTES DE : " + sequence.getIdsequence().getNom(), 5, true));
                            table.addCell(PrintUtils
                                    .createPdfPCell("Nom : " + eleveAnneeClasse.getEleve().getNom(), 2, false));

                            PdfPCell cellLogo = new PdfPCell(new Paragraph("  "));
                            cellLogo.setRowspan(2);
                            table.addCell(cellLogo);

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Matricule : " + eleveAnneeClasse.getEleve().getMatricule(), 2, false));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Prnom : " + eleveAnneeClasse.getEleve().getPrenom(), 2, false));

                            //table.addCell("kenne");
                            PdfPCell cellClasse = new PdfPCell(
                                    new Paragraph("Classe : " + eleveClasse.getIdclasse().getNom()));
                            cellClasse.setColspan(2);
                            table.addCell(cellClasse);

                            //debut de saisis de notes
                            PdfPTable entete = new PdfPTable(5);
                            table.addCell(new Paragraph("Dicipline"));
                            table.addCell(PrintUtils.createPdfPCell("Note ", true));
                            table.addCell(PrintUtils.createPdfPCell("Cofficient ", true));
                            table.addCell(PrintUtils.createPdfPCell("Total", true));
                            table.addCell(PrintUtils.createPdfPCell("Apprciation", true));

                            //partie qui contient es totaux
                            PdfPTable total = new PdfPTable(5);

                            int totalCoef = 0;
                            float totalPoint = 0;

                            classematieres = classeMatiereFacade
                                    .get(eleveAnneeClasse.getIdclasse().getIdclasse());
                            if (!classematieres.isEmpty()) {
                                for (Classematiere m : classematieres) {
                                    matieres.add(m.getIdmatiere());
                                }

                                /*for (Evaluation e : notes) {
                                 if (matieres.contains(e.getIdmatiere())) {
                                 notesPropres.add(e);
                                 matiereCompses.add(e.getIdmatiere());
                                 }
                                 }*/
                                for (int i = 0; i < nature.size(); i++) {
                                    table.addCell(
                                            PrintUtils.createPdfPCell("Matires " + nature.get(i).getLibelle(),
                                                    5, false, PrintUtils.blueFont));

                                    int totalCoefBloc = 0;
                                    int totalPointBloc = 0;

                                    for (int a = 0; a < matieres.size(); a++) {

                                        if (matiereCompses.contains(matieres.get(a))) {
                                            //if (Objects.equals(notesPropres.get(a).getIdmatiere(), nature.get(i).getIdnaturematiere())) {;
                                            //decompte des coefficient et nombre point globaux
                                            //totalCoef += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            // totalPoint += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();

                                            //decompte des coef et point par groupe                                          
                                            //totalCoefBloc += notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //totalPointBloc += notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient();
                                            //                                                    table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getNote(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getIdmatiere().getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + (notesPropres.get(a).getNote() * notesPropres.get(a).getIdmatiere().getCoeficient()), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                            //table.addCell(PrintUtils.createPdfPCell("" + notesPropres.get(a).getObservation(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC)));
                                            // }
                                        } else {
                                            if (Objects.equals(
                                                    matieres.get(a).getIdnaturematiere().getIdnaturematiere(),
                                                    nature.get(i).getIdnaturematiere())) {
                                                //decompte des coefficient et nombre point globaux
                                                //                                                    totalCoef += matieres.get(a).get
                                                totalPoint += 0;
                                                //decompte des coef et point par groupe                                          
                                                //                                                    totalCoefBloc += matieres.get(a).getCoeficient();
                                                totalPointBloc += 0;

                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getIdtypematiere().getLibelle(), false, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("O", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                //                                                    table.addCell(PrintUtils.createPdfPCell("" + matieres.get(a).getCoeficient(), true, new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("0", true, new Font(
                                                        Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL)));
                                                table.addCell(PrintUtils.createPdfPCell("Pas encore valu",
                                                        true, new Font(Font.FontFamily.TIMES_ROMAN, 10,
                                                                Font.ITALIC)));
                                            }
                                        }
                                    }

                                    //le texte Total pour chaque bloc
                                    PdfPCell cellTotalBlocText = new PdfPCell(
                                            new Paragraph("Total Matires " + nature.get(i).getLibelle() + " ",
                                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL)));
                                    cellTotalBlocText.setColspan(2);
                                    table.addCell(cellTotalBlocText);

                                    table.addCell(PrintUtils.createPdfPCell("" + totalCoefBloc, true, new Font(
                                            Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell("" + totalPointBloc, 2, true,
                                            new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL,
                                                    BaseColor.RED)));

                                    table.addCell(PrintUtils.createPdfPCell(
                                            "Moyenne Matires  " + nature.get(i).getLibelle(), 3, false,
                                            PrintUtils.blueFont));
                                    if (totalCoefBloc != 0) {
                                        table.addCell(PrintUtils.createPdfPCell(
                                                "" + (totalPointBloc / totalCoefBloc) + "/20", 2, true,
                                                PrintUtils.redFont));
                                    } else {
                                        table.addCell(PrintUtils.createPdfPCell("......", 2, true,
                                                PrintUtils.redFont));
                                    }
                                    table.addCell(PrintUtils.createPdfPCell("  ", 5, false));
                                }
                            } else {

                            }
                            //on ecrit totaux
                            table.addCell(PrintUtils.createPdfPCell("Totaux  ", 2, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));

                            //on met le total de coefficient
                            table.addCell(PrintUtils.createPdfPCell("" + totalCoef, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            //on met le total de point
                            table.addCell(PrintUtils.createPdfPCell("" + totalPoint, 2, true,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.RED)));

                            table.addCell(PrintUtils.createPdfPCell(
                                    "Moyenne de la " + sequence.getIdsequence().getNom(), 3, false,
                                    new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLUE)));
                            if (totalCoef != 0) {
                                table.addCell(PrintUtils.createPdfPCell((totalPoint / totalCoef) + "/20", 2,
                                        true,
                                        new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED)));
                            }

                            bulletin.add(table);
                            bulletin.close();
                            JsfUtil.addSuccessMessage(
                                    "Opration russie,redirigez-vous dans le repertoire bulletin");
                        } catch (DocumentException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        /*} else {
                         JsfUtil.addErrorMessage("L'lve selectionn n a aucune note  la squence slectionne");
                         }*/
                    } else {
                        JsfUtil.addErrorMessage("Aucune nature de matiere parametre");
                    }
                } else {
                    JsfUtil.addErrorMessage("l'eleve n a pas de classe");
                }
            } else {
                JsfUtil.addErrorMessage("veuillez selectionner une squence !");
            }
        } else {
            JsfUtil.addErrorMessage("Veuillez selectionner un lve");
        }
    } else {
        String sc = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect(sc + "/login.html");
        } catch (IOException ex) {
            Logger.getLogger(BulletinCtrl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:helpers.PDFHeaderFooter.java

@Override
public void onStartPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(),
            rect.getTop(), 0);//from ww  w .  ja v a 2  s  .co  m
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase("Page " + document.getPageNumber(),
                    FontFactory.getFont(FontFactory.TIMES_ITALIC, 5, Font.ITALIC, BaseColor.BLACK)),
            rect.getRight(), rect.getTop(), 0);
}

From source file:helpers.PDFHeaderFooter.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(""), rect.getLeft(),
            rect.getBottom(), 0);//from w  w w . j  a v a2s  .co  m
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
            new Phrase("Copyright @" + new SetDateCreated().getYear() + " (Wellington Mapiku)",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.ITALIC, BaseColor.DARK_GRAY)),
            rect.getRight(), rect.getBottom(), 0);
}

From source file:itextpdf.GeneratePdf.java

License:Minecraft Mod Public

public void addElements() throws DocumentException {
    document.add(new Paragraph("Ejemplo primer prrafo, Ejemplos del mundo"));
    document.add(new Paragraph("Segundo titulo del mundo",
            FontFactory.getFont("arial", 22, Font.ITALIC, BaseColor.CYAN)));
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteClientes(ArrayList<Cliente> Datos) throws IOException {
    // Se crea el documento Document documento = new Document();
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;/*  w ww  .  ja  v  a2 s  . co m*/
    try {
        FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteClientes.pdf");
        documento = new Document(); // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento.
        documento.open();
        documento.add(new Paragraph("REPORTE CLIENTES", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(9);
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("algo", font));
        documento.add(new Paragraph("\n"));

        Image img = Image.getInstance("C:\\Users\\panle\\Documents\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));
        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("NOMBRE COMLETO");
        tabla.addCell("USUARIO");
        tabla.addCell("NIT");
        tabla.addCell("NO DOCUMENTO");
        tabla.addCell("PROFESION");
        tabla.addCell("TELFONO CELULAR");
        tabla.addCell("TELFONO RESIDENCIA");
        tabla.addCell("DIRECCIN");
        tabla.addCell("CIUDAD");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getNOMBRE() + " " + Datos.get(conta).getAPELLIDO());
            tabla.addCell(Datos.get(conta).getUSUARIO());
            tabla.addCell(Datos.get(conta).getNIT());
            tabla.addCell(Datos.get(conta).getNUMERO_DOC());
            tabla.addCell(Datos.get(conta).getPROFESION());
            tabla.addCell(Datos.get(conta).getTEL_CEL());
            tabla.addCell(Datos.get(conta).getTEL_RESIDENCIA());
            tabla.addCell(Datos.get(conta).getDIRECCION());
            tabla.addCell(Datos.get(conta).getCIUDAD());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Clientes, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteProductos(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;//from www .  ja va2 s.  co m
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream("C:\\Users\\panle\\Documents\\ReporteProductos.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE PRODUCTOS", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

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

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteVentasFecha(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;/*www. ja v a  2 s  .co m*/
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream(
                "C:\\Users\\panle\\Documents\\ReporteVentasFecha.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE VENTAS POR FECHA", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

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

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteVentasCiudad(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;//from  www. java 2s .c om
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream(
                "C:\\Users\\panle\\Documents\\ReporteVentasCiudad.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE VENTAS POR CIUDAD", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

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

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}

From source file:modelo.GenerarPDF.java

public void nuevoReporteVentasMueble(ArrayList<Producto> Datos) throws IOException {
    // Se crea el documento Document
    // Se crea el OutputStream para el fichero donde queremos dejar el pdf.
    Document documento = null;//ww  w  .ja  v a2 s  .co  m
    try {
        //Direccion root
        FileOutputStream ficheroPdf = new FileOutputStream(
                "C:\\Users\\panle\\Documents\\ReporteVentasMueble.pdf");
        //FileOutputStream ficheroPdf = new FileOutputStream("user.dir/tmp", "ReporteProductos.pdf");
        //File tempfile = new File("user.dir/tmp", "tempfile.txt");    
        documento = new Document();
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);

        // Se abre el documento
        documento.open();
        documento.add(new Paragraph("REPORTE VENTAS POR MUEBLE", FontFactory.getFont("ARIAL", // fuente
                16, // tamao
                Font.ITALIC, // estilo
                BaseColor.BLACK))); // color

        PdfPTable tabla = new PdfPTable(3);//#campos(columnas) para la tabla
        Font font = new Font(FontFamily.COURIER, 6, Font.BOLD, BaseColor.BLACK);
        PdfPCell cell = new PdfPCell(new Phrase("Celdas", font));

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

        Image img = Image.getInstance("C:\\Users\\logo.png");
        documento.add(img);
        documento.add(new Paragraph("\n"));

        int conta = 0;

        cell.setBorder(Rectangle.TITLE);
        tabla.addCell("DESCRIPCION");
        tabla.addCell("REFERENCIA");
        tabla.addCell("TIPO");

        while (conta < Datos.size()) {
            cell.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(Datos.get(conta).getDESCRIPCION());
            tabla.addCell(Datos.get(conta).getREFERENCIA());
            tabla.addCell(Datos.get(conta).getTIPO());
            conta++;
        }

        documento.add(tabla);
        documento.close();

    } catch (FileNotFoundException | DocumentException e) {
        System.out.println("Error al generar Reporte Productos, por:");
        e.printStackTrace();
    }
}

From source file:net.sf.texprinter.generators.PDFGenerator.java

License:Open Source License

/**
 * Generates a PDF file from a Question object.
 * //from  w  ww  .j a  v a  2  s  . c  o  m
 * @param question The question.
 * @param filename The filename.
 */
public static void generate(Question question, String filename) {

    // wait window
    ProgressMessage pm = new ProgressMessage("TeXPrinter is printing your PDF file.");

    // start wait window
    //pm.start();

    // log message
    log.log(Level.INFO, "Starting PDF generation of {0}.", filename);

    // define a new PDF document
    Document document = null;

    // define a new PDF writer
    PdfWriter writer = null;

    // lets try
    try {

        // create a new PDF document
        document = new Document();

        // define a new PDF Writer
        writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

        // set the PDF version
        writer.setPdfVersion(PdfWriter.VERSION_1_6);

        // open the document
        document.open();

        // set the title font
        Font titleFont = new Font(FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);

        // set the chunk for the question title
        Chunk questionTitle = new Chunk(question.getQuestion().getTitle(), titleFont);

        // create a paragraph from that chunk
        Paragraph paragraphQuestionTitle = new Paragraph(questionTitle);

        // log message
        log.log(Level.INFO, "Adding the question title.");

        // add the question title to the document
        document.add(paragraphQuestionTitle);

        // set the asker font
        Font askerFont = new Font(FontFamily.HELVETICA, 10, Font.ITALIC, BaseColor.DARK_GRAY);

        // set the chunk for the asker
        Chunk questionAsker = new Chunk("Asked by " + question.getQuestion().getUser().getName() + " ("
                + question.getQuestion().getUser().getReputation() + ") on " + question.getQuestion().getDate()
                + " (" + String.valueOf(question.getQuestion().getVotes())
                + (question.getQuestion().getVotes() == 1 ? " vote" : " votes") + ")", askerFont);

        // create a paragraph from that chunk
        Paragraph paragraphQuestionAsker = new Paragraph(questionAsker);

        // log message
        log.log(Level.INFO, "Adding both asker and reputation.");

        // add the asker to the document
        document.add(paragraphQuestionAsker);

        // create a line separator
        LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -5);

        // add the line to the document
        document.add(line);

        // add a new line
        document.add(Chunk.NEWLINE);

        // create a list of elements from the question objects
        List<Element> questionTextObjects = getPostText(question.getQuestion().getText());

        // log message
        log.log(Level.INFO, "Adding the question text.");

        // for each element
        for (Element questionTextObject : questionTextObjects) {

            // add it to the document
            document.add(questionTextObject);
        }

        // add a new line
        document.add(Chunk.NEWLINE);

        // create a new font for the comments title
        Font commentsTitleFont = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLACK);

        // create a new chunk based on that font
        Chunk commentsTitle = new Chunk(
                "This question has " + question.getQuestion().getComments().size()
                        + ((question.getQuestion().getComments().size() == 1) ? " comment:" : " comments:"),
                commentsTitleFont);

        // create a paragraph from that chunk
        Paragraph paragraphCommentsTitle = new Paragraph(commentsTitle);

        // if there are comments to this question
        if (!question.getQuestion().getComments().isEmpty()) {

            // log message
            log.log(Level.INFO, "Adding the question comments.");

            // add that paragraph to the document
            document.add(paragraphCommentsTitle);

            // add a new line
            document.add(Chunk.NEWLINE);

            // get all the comments
            List<Comment> questionComments = question.getQuestion().getComments();

            // for each comment
            for (Comment questionComment : questionComments) {

                // get the elements of the comment text
                List<Element> questionCommentObjects = getPostText(questionComment.getText());

                // for each element
                for (Element questionCommentObject : questionCommentObjects) {

                    // add it to the document
                    document.add(questionCommentObject);
                }

                // create a new paragraph about the comment author
                Paragraph paragraphCommentAuthor = new Paragraph(questionComment.getAuthor() + " on "
                        + questionComment.getDate() + " (" + String.valueOf(questionComment.getVotes())
                        + (questionComment.getVotes() == 1 ? " vote" : " votes") + ")", askerFont);

                // set the alignment to the right
                paragraphCommentAuthor.setAlignment(Element.ALIGN_RIGHT);

                // add the paragraph to the document
                document.add(paragraphCommentAuthor);

                // add a new line
                document.add(Chunk.NEWLINE);
            }
        }

        // add a line separator
        document.add(line);

        // add two new lines
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        // get the list of answers
        List<Post> answersList = question.getAnswers();

        // if there are no answers
        if (answersList.isEmpty()) {

            // log message
            log.log(Level.INFO, "This question has no answers.");

            // create a new chunk
            Chunk noAnswersTitle = new Chunk("Sorry, this question has no answers yet.", titleFont);

            // create a paragraph from that chunk
            Paragraph paragraphNoAnswersTitle = new Paragraph(noAnswersTitle);

            // add the paragraph to the document
            document.add(paragraphNoAnswersTitle);

        } else {

            // log message
            log.log(Level.INFO, "Adding answers.");

            // there are answers, so create a counter for answers
            int answerCount = 1;

            // for each answer
            for (Post answer : answersList) {

                // log message
                log.log(Level.INFO, "Adding answer {0}.", answerCount);

                // set the message text as empty
                String answerAccepted = "";

                // if the answer is accepted
                if (answer.isAccepted()) {

                    // add that to the message
                    answerAccepted = " - Marked as accepted.";
                }

                // create a new chunk
                Chunk answerTitle = new Chunk("Answer #" + answerCount, titleFont);

                // create a paragraph from that chunk
                Paragraph paragraphAnswerTitle = new Paragraph(answerTitle);

                // add the paragraph to the document
                document.add(paragraphAnswerTitle);

                // increase the counter
                answerCount++;

                // create a new chunk
                Chunk questionAnswerer = new Chunk("Answered by " + answer.getUser().getName() + " ("
                        + answer.getUser().getReputation() + ") on " + answer.getDate() + answerAccepted + " ("
                        + String.valueOf(answer.getVotes()) + (answer.getVotes() == 1 ? " vote" : " votes")
                        + ")", askerFont);

                // create a paragraph from that chunk
                Paragraph paragraphQuestionAnswerer = new Paragraph(questionAnswerer);

                // add that paragraph to the document
                document.add(paragraphQuestionAnswerer);

                // add a line separator
                document.add(line);

                // add a new line
                document.add(Chunk.NEWLINE);

                // create a list of elements from the answer text
                List<Element> answerTextObjects = getPostText(answer.getText());

                // for each element
                for (Element answerTextObject : answerTextObjects) {

                    // add it to the document
                    document.add(answerTextObject);
                }

                // add a new line
                document.add(Chunk.NEWLINE);

                // create a new font style
                Font answerCommentsTitleFont = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLACK);

                // create a new chunk
                Chunk answerCommentsTitle = new Chunk(
                        "This answer has " + answer.getComments().size()
                                + ((answer.getComments().size() == 1) ? " comment:" : " comments:"),
                        answerCommentsTitleFont);

                // create a paragraph from that chunk
                Paragraph paragraphAnswerCommentsTitle = new Paragraph(answerCommentsTitle);

                // if there are comments for that answer
                if (!answer.getComments().isEmpty()) {

                    // log message
                    log.log(Level.INFO, "Adding comments for answer {0}.", (answerCount - 1));

                    // add that paragraph to the document
                    document.add(paragraphAnswerCommentsTitle);

                    // add a new line
                    document.add(Chunk.NEWLINE);

                    // get all the comments
                    List<Comment> answerComments = answer.getComments();

                    // for each comment
                    for (Comment answerComment : answerComments) {

                        // create a list of elements from the comment text
                        List<Element> answerCommentObjects = getPostText(answerComment.getText());

                        // for each element
                        for (Element answerCommentObject : answerCommentObjects) {

                            // add it to the document
                            document.add(answerCommentObject);
                        }

                        // create a new paragraph for the comment author
                        Paragraph paragraphAnswerCommentAuthor = new Paragraph(
                                answerComment.getAuthor() + " on " + answerComment.getDate() + " ("
                                        + String.valueOf(answerComment.getVotes())
                                        + (answerComment.getVotes() == 1 ? " vote" : " votes") + ")",
                                askerFont);

                        // set the aligment to the right
                        paragraphAnswerCommentAuthor.setAlignment(Element.ALIGN_RIGHT);

                        // add the paragraph to the document
                        document.add(paragraphAnswerCommentAuthor);

                        // add a new line
                        document.add(Chunk.NEWLINE);
                    }
                }

                // add a line separator
                document.add(line);

                // add two new lines
                document.add(Chunk.NEWLINE);
                document.add(Chunk.NEWLINE);
            }
        }

        // log message
        log.log(Level.INFO, "PDF generation complete, closing {0}.", filename);

        // close the document
        document.close();

        // stop wait window
        pm.interrupt();

    } catch (IOException ioexception) {

        // stop wait window
        pm.interrupt();

        // log message
        log.log(Level.SEVERE, "An IO error occurred while trying to create the PDF file. MESSAGE: {0}",
                StringUtils.printStackTrace(ioexception));

        // critical error, exit
        Dialogs.showExceptionWindow();

    } catch (Exception exception) {

        // log message
        log.log(Level.SEVERE, "A generic error occurred while trying to create the PDF file. MESSAGE: {0}",
                StringUtils.printStackTrace(exception));

        // log message
        log.log(Level.INFO, "I will try to remove the remaining PDF file.");

        try {

            // log message
            log.log(Level.INFO, "Closing both document and writer.");

            // close the document
            document.close();

            // close the writer
            writer.close();

        } catch (Exception ex) {

            // log message
            log.log(Level.WARNING, "I could not close either document or writer. MESSAGE: {0}",
                    StringUtils.printStackTrace(ex));
        }

        try {

            // reference problematic file
            File target = new File(filename);

            // log message
            log.log(Level.INFO, "Opening problematic file {0}.", filename);

            // check if file exists
            if (target.exists()) {

                // log message
                log.log(Level.INFO, "File exists, trying to delete it.");

                // trying to remove it
                if (target.delete()) {

                    // log message
                    log.log(Level.INFO, "File {0} was successfully removed.", filename);

                } else {

                    // log message
                    log.log(Level.SEVERE, "File {0} could not be removed.", filename);

                }
            }
        } catch (SecurityException se) {

            // log message
            log.log(Level.SEVERE, "A security exception was raised. MESSAGE: {0}",
                    StringUtils.printStackTrace(se));

        }

        // stop wait window
        pm.interrupt();

        // critical error, exit
        Dialogs.showExceptionWindow();

    }
}