Example usage for com.itextpdf.text BaseColor RED

List of usage examples for com.itextpdf.text BaseColor RED

Introduction

In this page you can find the example usage for com.itextpdf.text BaseColor RED.

Prototype

BaseColor RED

To view the source code for com.itextpdf.text BaseColor RED.

Click Source Link

Usage

From source file:engine.Pdf.java

public static void drawLines(PdfWriter writer) {
    PdfContentByte canvas = writer.getDirectContent();
    canvas.setColorStroke(BaseColor.RED);
    canvas.setLineWidth(3);/*  www . j  a  va 2  s .com*/
    canvas.moveTo(20, 30);
    canvas.lineTo(900, 900);
    canvas.lineTo(220, 330);
    canvas.closePathStroke();
    canvas.setColorFill(BaseColor.RED);
    canvas.fill();
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

private void insertPinnedComment(float xCoord, float yCoord, String id, String comment, int pageNum,
        int masterHeight, int masterWidth) throws DocumentException, IOException {

    int standardHeight = 38;
    int standardWidth = 130;
    int lineHeight = 7;

    if (fontSize == 8) {
        standardHeight = 48;/*  ww w.j  a v a2 s . c o m*/
        standardWidth = 180;
        lineHeight = 10;
    } else if (fontSize == 10) {
        standardHeight = 70;
        standardWidth = 210;
        lineHeight = 12;
    }

    // comment box position defines lower-left corner
    xCoord += 41; // x-coordinate of comment text box
    yCoord -= 7; // lower offset moves box up

    float f = (float) 0.4;
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(f);

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.setGState(gs1);
    fg.setLineWidth(.5f * getRatio(masterHeight, masterWidth, pageNum));

    // Calculate additional needed height for the comment, based on length of comment.
    List<String> lines = createComment(cleanupComment(comment));
    int numLines = lines.size();
    int commentHeight = (numLines - 1) * lineHeight;

    // Draw the comment box
    String color = "0xF2F3E4";
    Color c = Color.decode(color);
    color = "0xFAFAF4";
    Color c2 = Color.decode(color);
    fg.setLineWidth(1f);
    fg.setColorStroke(new BaseColor(c.getRGB()));
    fg.setColorFill(new BaseColor(c2.getRGB()));
    float newCoords[] = pinnedCoords(xCoord, yCoord, standardWidth, standardHeight + commentHeight);
    fg.roundRectangle(xCoord, newCoords[1], standardWidth, standardHeight + commentHeight, 2f);
    fg.fillStroke();

    //BaseFont bf = BaseFont.createFont();
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, true);
    BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, true);
    fg.setColorFill(BaseColor.RED);
    gs1.setFillOpacity(0.8f);
    fg.setGState(gs1);

    // Adding comment title text
    Phrase phrase = new Phrase("Comment", new Font(bfb, fontSize));
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 7, 0);

    // Adding comment number
    phrase = new Phrase(id, new Font(bf, fontSize));
    float offset = xCoord + 35;
    if (fontSize == 8)
        offset = xCoord + 45;
    else if (fontSize == 10)
        offset = xCoord + 55;
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, offset, yCoord - 7, 0);

    /*  Remove 10/27/2015 Jon Changkachith
    // Adding 'comment' label text
    phrase = new Phrase("Comment", new Font(bfb, fontSize));
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 20f, 0);
    */

    // Adding comment text
    int commentYOffset = 32;
    for (int i = 0; i < lines.size(); i++) {
        //phrase = new Phrase(lines.get(i), new Font(bf, fontSize));
        phrase = composePhrase(lines.get(i), bf, bfb);
        ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - commentYOffset, 0);
        commentYOffset += lineHeight;
    }

}

From source file:fc.extensions.itext.Writer.java

License:MIT License

public void setDebug() {
    this.baseColor = BaseColor.RED;
}

From source file:forensics_app.SharedModel.java

public static void writePDF(List<List<List>> final_result) {
    List<List> al = new ArrayList<List>();
    Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
    Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);
    Font blueFont = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL, BaseColor.BLUE);
    Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);
    Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    String fileName = System.getProperty("user.home") + "\\Desktop\\" + System.currentTimeMillis() + ".pdf";
    Document document = null;/*from   w w w. ja v  a  2  s.co  m*/
    document = new Document();
    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        document.add(new Phrase("\n"));
        document.add(new Paragraph("ForEye Smart Report", redFont));
        document.add(new Phrase("\n\n"));
        for (int z = 0; z < 3; z++) {
            al = final_result.get(z);
            switch (z) {
            case 0:
                if (al != null) {
                    document.add(new Phrase("\n-> History\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            case 1:
                if (al != null) {
                    document.add(new Phrase("\n-> Download\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            case 2:
                if (al != null) {
                    document.add(new Phrase("\n-> Bookmarks\n", blueFont));
                    document.add(new Paragraph("This user interseted in  " + al.get(0).get(0) + "  by "
                            + String.valueOf(al.get(1).get(0)) + "%", catFont));
                    document.add(new Phrase("\nthe rest of report\n", subFont));
                    for (int j = 0; j < al.get(0).size(); j++) {
                        document.add(new Phrase(
                                al.get(0).get(j) + "  by " + String.valueOf(al.get(1).get(j)) + "%"));
                        document.add(new Phrase("\n"));
                    }
                    document.add(new Phrase("\n\n"));
                }
                break;
            }
        }
        document.close();
        writer.close();
        if (Desktop.isDesktopSupported()) {
            try {
                File myFile = new File(fileName);
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:gestionEtat.imprimerBulletin.BulletinCtrl.java

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

        if (eleveAnneeClasse.getId() != null) {
            classematieres.clear();//from w  w w.ja v  a2  s  .co m
            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:Gui.admin.NouveauConsulterinfoAdherent.java

private void RapportBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RapportBouttonActionPerformed

        String value1 = idadherenttxt.getText();
        String value2 = nomadherentTxt.getText();
        String value3 = prenomAdhrentTxt.getText();
        String value4 = adresseAdherentTxt.getText();
        String value5 = mdpAdherentTXT.getText();
        String value6 = telAdherentTXT.getText();
        String value7 = nbrReclamationsTxt.getText();

        try {/*from  w  w w. ja va2 s  .c  om*/
            // pagesize.A4.rotate() pour voir le rapport dans IDE 
            com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

            if ((new File("rapport.pdf")).exists()) {

                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler rapport.pdf");
                p.waitFor();

            } else {

                System.out.println("File is not exists");

            }

            document.open();
            // Date
            document.add(new Paragraph(new Date().toString()));
            document.add(new Paragraph("Rapport Statistiques",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
            document.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------------------------------------------------------------------------------"));

            // ajoute un tableau dans le rapport 

            //                  PdfPTable table = new PdfPTable(4);
            //                  
            //                   PdfPCell cell = new PdfPCell(new Paragraph("Informations Adhrents"));
            //                     // le titre du tableau 
            //                  cell.setColspan(10);
            //                  cell.setBackgroundColor(BaseColor.GREEN);
            //                  table.addCell(cell);

            //                  table.addCell("Id Adhrent");
            //                  table.addCell("Nom de l'adhrent");
            //                  table.addCell("Prnom de l'adhrent");
            //                  table.addCell("Numro de l'adhrent");
            //                  document.add(table);
            // le titre du tableau 

            // ajouter l'image dans le fichier pdf 
            Image image = Image.getInstance("statistiques.png");
            document.add(new Paragraph("statistiques.png"));
            document.add(image);

            // document.add(new Paragraph("Salut sindoud", FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD, BaseColor.BLUE)));

            //document.add(new Paragraph (new Date().toString()));

            PdfPTable table = new PdfPTable(6);
            PdfPCell cell = new PdfPCell(new Paragraph("Titre"));
            cell.setColspan(4);
            //  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.GREEN);
            table.addCell("id de l'adherent");
            table.addCell(value1);
            table.addCell("Nom de l'adhrent");
            table.addCell(value2);
            table.addCell("Prnom de l'adhrent");
            table.addCell(value3);
            table.addCell("adresse de l'adhrent");
            table.addCell(value4);
            table.addCell("mot de passe de l'adherent");
            table.addCell(value5);
            table.addCell("tel de l'adherent ");
            table.addCell(value6);
            table.addCell("nombre de reclamations");
            table.addCell(value7);

            document.add(table);

            document.close();
            //com.itextpdf.text.Image image1= com.itextpdf.text.Image.getInstance("statistiques.png");
            // image1.scaleAbsolute(400,300);
            //document.add(image1);
            //PdfContentByte cb= writer.getDirectContent();
            JOptionPane.showMessageDialog(null, "rapport enregistr");
        }

        catch (DocumentException | IOException | InterruptedException | HeadlessException e) {

            JOptionPane.showMessageDialog(null, e);

        }
        //
    }

From source file:GUI.GestionProjects.java

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
    String IMAGE1 = lblPathImage.getText();
    Font red = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.RED);
    Chunk redText = new Chunk("Les information relatif au Projet : ", red);
    Font blue = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLUE);

    Document document = new Document();
    java.util.Date utilStartDate = jdateDeadLine.getDate();
    java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
    try {//from  w w w.  j  a va 2  s. c o m
        PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
        document.open();

        Paragraph p1 = new Paragraph();
        p1.add(redText);
        p1.add(txtTitreProjet.getText());

        Chunk txtdesc = new Chunk("Decription du Projet: ", red);
        Paragraph p2 = new Paragraph();
        p2.add(txtdesc);
        p2.add(txtDescriptionProjet.getText());

        Chunk txtcat = new Chunk("Catgorie du Projet: ", red);
        Paragraph p3 = new Paragraph();
        p3.add(txtcat);
        p3.add(combo_Cat.getSelectedItem().toString());

        Chunk txtfin = new Chunk("Mode de finnancement du Projet: ", red);
        Paragraph p4 = new Paragraph();
        p4.add(txtfin);
        p4.add(ComboFinnancementProjet.getSelectedItem().toString());

        Chunk txtdate = new Chunk("Date DeadLine Projet: ", red);
        Paragraph p5 = new Paragraph();
        p5.add(txtdate);
        p5.add(sqlStartDate.toString());

        p1.setSpacingAfter(25);
        p1.setSpacingBefore(25);
        p1.setAlignment(Element.ALIGN_CENTER);
        p1.setIndentationLeft(50);
        p1.setIndentationRight(50);

        document.add(p1);
        document.add(p2);
        document.add(p3);
        document.add(p4);
        document.add(p5);

        if (Desktop.isDesktopSupported()) {
            try {
                File myFile = new File("Report.pdf");
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    document.close();
    // TODO add your handling code here:
}

From source file:ihm.panneaux.GenererPdf.java

private void initComponement() throws FileNotFoundException, DocumentException, IOException {
    String DEST = "devis/devis-" + devis.getNumero() + ".pdf";
    OutputStream file = new FileOutputStream(new File(DEST));

    com.itextpdf.text.Document document = new com.itextpdf.text.Document();
    PdfWriter.getInstance((com.itextpdf.text.Document) document, file);
    // PAS TOUCHE
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));

    Rectangle rect = new Rectangle(30, 30, 550, 800);
    writer.setBoxSize("art", rect);
    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    writer.setPageEvent(event);// w ww . ja v a  2  s  .  c om
    document.open();
    PdfContentByte canvas = writer.getDirectContent();

    Image logo = Image.getInstance("images/logo.png");
    logo.scaleAbsolute(200, 57);

    // INFO DEVIS
    Image devisImg = Image.getInstance("images/imgDevis.png");
    devisImg.scaleAbsolute(110, 34);
    devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150),
            (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2);
    Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Phrase numeroInfo = new Phrase("Numro  " + devis.getNumero(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413,
            devisImg.getScaledHeight() + 710, 0);
    Phrase dateInfo = new Phrase("Le  " + devis.getDate(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420,
            devisImg.getScaledHeight() + 695, 0);
    Image devisImgBordure = Image.getInstance("images/bordureDevis.png");
    devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660);
    devisImgBordure.scaleAbsolute(120, 122);

    // INFO ENTREPRISE
    Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD);
    Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210,
            devisImg.getScaledHeight() + 660, 0);
    Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149,
            devisImg.getScaledHeight() + 640, 0);
    Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113,
            devisImg.getScaledHeight() + 625, 0);
    Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png");
    bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610);

    // INFO CLIENT
    Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL);
    Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient);
    Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient);
    Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(),
            fontClient);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 595, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 580, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 565, 0);

    document.add(logo);
    document.add(devisImg);
    document.add(devisImgBordure);
    document.add(bordureEntreprise);

    // AJOUT DES DONNEES DU TABLEAUX 

    float[] columnWidths = { 14, 3, 4, 3, 4 };
    Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    fontCategorie.setColor(BaseColor.GREEN);

    PdfPTable table = new PdfPTable(columnWidths);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    table.setTotalWidth(PageSize.A4.getWidth() - 15);

    table.setSpacingBefore(150);

    table.setLockedWidth(true);

    Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD);
    Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE);

    PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier));
    cellChantier.setColspan(3);
    cellChantier.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellChantier);
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(new Phrase("Dsignation", Categorie));
    PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie));
    PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie));
    PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie));
    PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie));

    unite.setHorizontalAlignment(Element.ALIGN_CENTER);
    quantite.setHorizontalAlignment(Element.ALIGN_CENTER);
    prixht.setHorizontalAlignment(Element.ALIGN_CENTER);
    pvtht.setHorizontalAlignment(Element.ALIGN_CENTER);

    unite.setBorder(Rectangle.NO_BORDER);
    quantite.setBorder(Rectangle.NO_BORDER);
    prixht.setBorder(Rectangle.NO_BORDER);
    pvtht.setBorder(Rectangle.NO_BORDER);

    table.addCell(unite);
    table.addCell(quantite);
    table.addCell(prixht);
    table.addCell(pvtht);

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    double htTotalParcour = 0;
    double ttcTotalParcour = 0;

    if (this.EquipementDeChantier.isEmpty() == false) {
        table.addCell(new Phrase("Equipement De Chantier", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

        for (DevisContenu listeMaterielDevi : EquipementDeChantier) {

            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            /* BACKUP
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            table.addCell(listeMaterielDevi.getMateriel().getUnite());
            table.addCell(Double.toString(listeMaterielDevi.getQuantite()));
            table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+"");
            table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+"");
            */
            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Couverture.isEmpty() == false) {
        table.addCell(new Phrase("Couverture", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Couverture) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureArdoise.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Ardoise", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureArdoise) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureTuile.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Tuile", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureTuile) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (this.Demoussage.isEmpty() == false) {
        table.addCell(new Phrase("Demoussage", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Demoussage) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Velux.isEmpty() == false) {
        table.addCell(new Phrase("Velux", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Velux) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Zinguerie.isEmpty() == false) {
        table.addCell(new Phrase("Zinguerie", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Zinguerie) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Plancher.isEmpty() == false) {
        table.addCell(new Phrase("Plancher", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Plancher) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }

    ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour;

    LineDash solid = new SolidLine();
    PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc;

    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(new CustomBorder(null, null, null, solid));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL"));
    cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellSOUSTOTAL);
    table.addCell(new Phrase(""));
    double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2);
    String httotal = String.valueOf(prixHT_2Chiffre);
    cellhttotal = new PdfPCell(new Phrase(httotal + ""));
    cellhttotal.setBorder(Rectangle.NO_BORDER);
    cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cellhttotal);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    tva = new PdfPCell(new Phrase("TVA"));
    tva.setBorder(Rectangle.NO_BORDER);
    tva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(tva);

    getTva = new PdfPCell(new Phrase(devis.getTva() + "%"));
    getTva.setBorder(Rectangle.NO_BORDER);
    getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(getTva);

    String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100);
    double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2);
    cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + ""));
    cell2.setBorder(PdfPCell.NO_BORDER);
    cell2.setCellEvent(new CustomBorder(null, null, null, solid));
    cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell2);

    table.addCell("");
    table.addCell("");
    totalttc = new PdfPCell(new Phrase("Total TTC"));
    totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    totalttc.setBorder(PdfPCell.NO_BORDER);
    table.addCell(totalttc);
    table.addCell("");
    double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2);
    String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre));
    gettotalttc = new PdfPCell(new Phrase(ttctotal + ""));
    gettotalttc.setBorder(PdfPCell.NO_BORDER);
    gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(gettotalttc);

    table.setSpacingAfter(10);

    document.add(table);

    Pattern p = Pattern.compile("[.^\\.]+");
    String texte = devis.getInformationComplementaire();

    Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlue.setColor(BaseColor.BLUE);
    Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptRed.setColor(BaseColor.RED);
    Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlack.setColor(BaseColor.BLACK);

    Paragraph infoComp = new Paragraph();
    Image BonPourAccord = null;
    BonPourAccord = Image.getInstance("images/BonPourAccord.png");
    infoComp.setAlignment(Element.ALIGN_LEFT);
    BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT);

    String[] phrase = p.split(texte);
    for (int i = 0; i < phrase.length; i++) {
        if (i == 0 || i == 1) {
            infoComp.add(new Paragraph(phrase[i], infoComptBlue));
        }
        if (i == 2 || i == 3 || i == 4 || i == 5) {
            infoComp.add(new Paragraph(phrase[i], infoComptRed));

        }
        if (i > 5 && i <= 11)
            infoComp.add(new Paragraph(phrase[i], infoComptBlack));
        if (i > 11)
            infoComp.add(new Paragraph(phrase[i], infoComptRed));
    }
    /* A OPTIMISER */

    float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex());

    if (taille_tableau > 386) {
        document.newPage();
    }
    document.add(BonPourAccord);
    document.add(infoComp);

    document.close();

    EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis);
    this.CouvertureArdoise.clear();
    this.CouvertureTuile.clear();
    this.Demoussage.clear();
    this.EquipementDeChantier.clear();
    this.Velux.clear();
    this.Zinguerie.clear();
    this.Couverture.clear();
    this.Plancher.clear();
}

From source file:info.longnetpro.examples.PdfLibExamples.java

public static void generatePdf()
        throws DocumentException, URISyntaxException, MalformedURLException, IOException {
    String licFile = getLicenseFilePath();
    loadLicenseFile(licFile);/*from   ww  w . j  av a2  s . co m*/

    String dest = getTargetFilePath();
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream(dest));
    Rectangle pageSize = PageSize.LETTER;
    Rectangle rect = new Rectangle(0f, 0f, 50f, 100f);
    rect.setBorder(15);
    rect.setBorderColor(BaseColor.RED);
    rect.setBorderWidth(.5f);
    rect.setBackgroundColor(BaseColor.BLUE);
    doc.setPageSize(pageSize);
    doc.open();

    Page page = new Page(pageSize.getWidth(), pageSize.getHeight());
    ContentBox rpage = page.margin(new Float[] { 10f, 50f, 10f, 50f });

    for (Anchor anchor : Anchor.values()) {
        ContentBox box = new ContentBox(50f, 100f);
        float offx = anchor.equals(Anchor.CENTER) ? -50f : 0f;
        float offy = anchor.equals(Anchor.CENTER) ? -50f : 0f;

        ContentBox rr = anchor.anchorElement(rpage, box, offx, offy);

        if (anchor.equals(Anchor.BOTTOM_LEFT)) {
            float[] dim = box.scaleByPercentage(0.5f);
            //rr = rr.reposition(dim[0], dim[1], Anchor.TOP_RIGHT);
        }

        rect.setLeft(rr.getLeft());
        rect.setBottom(rr.getBottom());
        rect.setRight(rr.getRight());
        rect.setTop(rr.getTop());
        doc.add(rect);
    }
    String imageFile = getImageFilePath();
    Image image = Image.getInstance(imageFile);

    float width = Measurement.dotsToUserUnits(image.getWidth(), 1200);
    float height = Measurement.dotsToUserUnits(image.getHeight(), 1200);

    System.out.println(width + " " + height);

    ContentBox img = Anchor.BOTTOM_LEFT.anchorElement(rpage, width, height);

    image.scaleToFit(width, height);
    image.setAbsolutePosition(img.getLeft(), img.getBottom());

    System.out.println(image.getWidth() + " " + image.getHeight());
    System.out.println(image.getAbsoluteX() + " " + image.getAbsoluteY());

    doc.add(image);
    doc.close();
}

From source file:info.toegepaste.controller.PdfController.java

public void CreatePdf(long studentId) {
    //Fonts// ww  w . jav  a 2 s  .  c om
    Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
    Font normal = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL);

    //Declaration
    Student student = new Student();
    List<Course> courses;
    List<Exam> exams = null;
    Score score;
    int totaal = 0; //totaal van een vak berekenen
    int maxScore = 0; //max soore van een test
    int aantalVakken = 0; //aantal vakken waaraan student heeft deelgenomen
    int klasgemiddelde = 0; //hulpvariabele om klasgemiddelde op te vragen
    Double totaalGemiddelde = 0.0; //eindpercentage
    Double vermenigvuldigfactor = 0.0; //om score op 20 weer te geven
    ArrayList<Integer> gemiddeldes = new ArrayList<Integer>(); //gemiddeldes per vak
    ArrayList<Integer> gemiddeldesKlas = new ArrayList<Integer>(); //gemiddelde klas per vak

    PdfPCell cell;

    //Document
    Document document = new Document();

    //student opvullen
    student = pdfService.getStudent(studentId);

    //Tempfix
    //student.getClassgroup();

    //cursussen opvullen
    courses = courseService.getWithClassgroup(student.getClassgroup());

    for (int i = 0; i < courses.size(); i++) {
        //testen opvullen
        exams = pdfService.getExamsByCourse(courses.get(i));
        for (int j = 0; j < exams.size(); j++) {
            score = pdfService.getScoreByExamAndStudent(exams.get(j), student);
            //nagaan of de student heeft deelgenomen aan de test
            if (score != null) {
                // score op 20 weergeven
                vermenigvuldigfactor = 20 / (double) exams.get(j).getTotal();
                totaal += (int) (score.getScore() * vermenigvuldigfactor);
            }
            //klasgemiddelde voor een vak
            klasgemiddelde = pdfService.getAverageScoreByExam(exams.get(j));
            gemiddeldesKlas.add(klasgemiddelde);
        }
        if (exams.size() > 0) {
            gemiddeldes.add(totaal / exams.size());
            totaalGemiddelde += totaal / exams.size();
            aantalVakken++;
        }
        totaal = 0;
        exams.clear();
    }

    totaalGemiddelde = totaalGemiddelde / aantalVakken * 5;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        PdfWriter.getInstance(document, outputStream);

        document.open();
        //header
        document.add(new Paragraph("Studenten Rapport", header));
        document.add(new Paragraph("Student:" + student.getFirstname() + " " + student.getLastname(), normal));
        document.add(new Paragraph("Klas:" + student.getClassgroup(), normal));
        document.add(new Paragraph("Alle scores worden op 20 weergegeven", normal));

        //table
        PdfPTable table = new PdfPTable(3);

        //create tableheaders
        PdfPCell c1 = new PdfPCell(new Phrase("Vak"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Score"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Gemiddelde"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.setHeaderRows(1);

        for (int i = 0; i < aantalVakken; i++) {
            cell = new PdfPCell(new Phrase(gemiddeldes.get(i).toString()));
            if (gemiddeldes.get(i) < 10) {
                cell.setBackgroundColor(BaseColor.RED);
            }

            table.addCell(courses.get(i).getName());
            table.addCell(cell);
            table.addCell(gemiddeldesKlas.get(i).toString());
        }

        document.add(table);

        //end
        document.add(new Paragraph("Totaal behaald percentage:" + totaalGemiddelde, normal));
        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
        //  } catch (FileNotFoundException e) {
        //   e.printStackTrace();
    }
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(587);
    email.setSSLOnConnect(true);
    email.setAuthenticator(new DefaultAuthenticator("bitmescoretracker@gmail.com", "bitmeScore"));
    try {

        email.addTo(student.getEmail());
        email.setFrom("bitmescoretracker@gmail.com");
        email.setSubject("Requested scores , scoretracker");
        email.setMsg("Here are the scores you requested!");

        //  EmailAttachment attachment = new EmailAttachment();
        //attachment.setDescription("PDF met uw punten");
        // attachment.setName(student.getFirstname() + " " + student.getLastname() + " scores");
        byte[] bytes = outputStream.toByteArray();

        DataSource source = new javax.mail.util.ByteArrayDataSource(bytes, "application/pdf");
        System.out.println("Stuff");

        /* try{
         source = outputStream.write(bytes);
         }catch(IOException e){
             e.printStackTrace();
         }*/
        email.attach(source, student.getFirstname() + " " + student.getLastname() + " scores", "stuff");

        email.send();
    } catch (EmailException ex) {
        ex.printStackTrace();
    }

}