Example usage for com.itextpdf.text Font BOLD

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

Introduction

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

Prototype

int BOLD

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

Click Source Link

Document

this is a possible style.

Usage

From source file:GUI.frameNewVentaKit.java

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

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {//  ww  w.j a va2 s .  c o  m

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);

            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:GUI.FrameUserPanier.java

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

    jLabel8.setText("" + CalculSomme());

    String val1 = TFidpan.getText();
    String val2 = TFnomut.getText();
    String val3 = TFNomprod.getText();
    String val4 = TFnombreprod.getText();
    String val5 = TFdescription.getText();
    try {/*from   w  w  w. ja  va 2s .  co m*/

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
        document.open();
        document.add(new Paragraph("VotrePanier",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLUE)));
        document.add(new Paragraph(new Date().toString()));
        PdfPTable table = new PdfPTable(5);

        PdfPCell cell = new PdfPCell(new Paragraph("Mes achats"));

        cell.setColspan(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.BLUE);
        table.addCell(cell);

        table.addCell("IdPanier");
        table.addCell("NomUtilsateur");
        table.addCell("Nomprod");
        table.addCell("Nombreprod");
        table.addCell("Description");
        cell.setBackgroundColor(BaseColor.BLUE);

        int i = TablePanier.getRowCount();
        TableModel model = TablePanier.getModel();

        for (int j = 0; j < i; j++) {
            val1 = model.getValueAt(j, 0).toString();
            val2 = model.getValueAt(j, 2).toString();
            val3 = model.getValueAt(j, 4).toString();
            val4 = model.getValueAt(j, 5).toString();
            val5 = model.getValueAt(j, 6).toString();

            table.addCell(val1);
            table.addCell(val2);
            table.addCell(val3);
            table.addCell(val4);
            table.addCell(val5);

        }
        int z = TablePanier.getRowCount();
        model = TablePanier.getModel();
        float sum = 0;
        int bonus = 0;
        float net = 0;
        for (int j = 0; j < z; j++) {
            String x = model.getValueAt(j, 3).toString();
            int idprod = Integer.parseInt(x);
            String q = model.getValueAt(j, 5).toString();
            int qu = Integer.parseInt(q);
            Produit p = pdao.findByprodId(idprod);
            sum += p.getPrix() * qu;
            bonus += (p.getPtbonus() * qu);
            net += sum - (p.getReduction() * qu);
        }

        table.addCell("Somme: " + sum);
        table.addCell("");

        table.addCell("Net: " + net);
        table.addCell("");
        table.addCell("Bonus :" + bonus);

        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Report Saved");
    } catch (Exception 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 {//  w w  w .ja  v  a  2s.  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:hr.ws4is.tn3812.drivers.listeners.PdfListener.java

License:Open Source License

@Override
public void onStart(final IControls controls) {

    this.controls = controls;

    Rectangle ps = null;/*w  w  w.  ja v a 2s  . com*/
    if (controls.getPageOrientation() == SCSPageOrientation.LANDSCAPE) {
        ps = PageSize.A4.rotate();
    } else {
        ps = PageSize.A4;
    }
    document = new Document(ps, 15, 0, 0, 0);

    font = new Font(courier, controls.getFontSize());
    fontBold = new Font(courier, controls.getFontSize());
    fontBold.setStyle(Font.BOLD);
    current = font;

    file = prepareFile();
    fos = open(file);
    try {
        printWriter = PdfWriter.getInstance(document, fos);
        printWriter.setViewerPreferences(PdfWriter.PrintScalingNone);
    } catch (DocumentException exception) {
        LOGGER.error(exception.getMessage(), exception);
    }

    document.open();

}

From source file:IAS.Class.BackIssueLabels.java

public Paragraph prepareBILLabelPDFContent(subInfo sLabelInfo, String bilLabel) {
    Paragraph info = null;//from  w  ww  . ja  va 2  s .com

    info = new Paragraph();
    info.setLeading(lfixedLeading, lmultipliedLeadingPlus);
    info.setAlignment(textAlignment);

    Font font;
    font = new Font(sfontType, sfontSizeHeader - 1, sfontStyle, BaseColor.BLACK);
    if (!bilLabel.isEmpty() && !sLabelInfo.getsubscriberNumber().isEmpty()) {
        String header = sLabelInfo.getsubscriberNumber() + " " + bilLabel;
        info.add(new Chunk(header, font));
        info.add(Chunk.NEWLINE);
    }

    font = new Font(sfontType, sfontSize, sfontStyle, BaseColor.BLACK);
    String firstLine = sLabelInfo.getsubscriberName();
    // + " " + sLabelInfo.getjournalCode();

    //if(!noHeader){

    //if(sLabelInfo.getcopies() > 1){
    //    firstLine = firstLine + " " + sLabelInfo.getcopies();
    //}

    //firstLine = firstLine + " " + sLabelInfo.getsubtypecode();

    //if(sLabelInfo.equals("Paid")) {
    //    firstLine = firstLine + " " + sLabelInfo.getstartDate()+
    //        " " + "to" +
    //        " " + sLabelInfo.getendDate();
    //}
    if (!firstLine.isEmpty()) {
        info.add(new Chunk(firstLine, font));
        info.add(Chunk.NEWLINE);
    }
    //}

    //info.add(new Chunk(sLabelInfo.getsubscriberName(), font));
    //info.add(Chunk.NEWLINE);
    if (!sLabelInfo.getdepartment().isEmpty()) {
        info.add(new Chunk(sLabelInfo.getdepartment(), font));
        info.add(Chunk.NEWLINE);
    }
    if (!sLabelInfo.getinstitution().isEmpty()) {
        info.add(new Chunk(sLabelInfo.getinstitution(), font));
        info.add(Chunk.NEWLINE);
    }

    if (!sLabelInfo.getaddress().isEmpty()) {
        info.add(new Chunk(sLabelInfo.getaddress(), font));
        info.add(Chunk.NEWLINE);
    }
    font = new Font(sfontType, sfontSize, Font.BOLD);
    /*
    String lastLine = sLabelInfo.getcity() +
        " " + sLabelInfo.getpincode() +
        " " + sLabelInfo.getstate() +
        " ";
    if(!sLabelInfo.getcountry().equals("India")){
    lastLine = lastLine + sLabelInfo.getcountry();
    }
    */

    String lastLine = "";
    if (!sLabelInfo.getcity().isEmpty()) {
        lastLine = lastLine + sLabelInfo.getcity();
    }
    if (sLabelInfo.getcity().isEmpty()) {
        lastLine = lastLine + sLabelInfo.getpincode();
    } else {
        lastLine = lastLine + " " + sLabelInfo.getpincode();
    }
    if (sLabelInfo.getpincode().isEmpty()) {
        lastLine = lastLine + sLabelInfo.getstate();
    } else {
        lastLine = lastLine + " " + sLabelInfo.getstate();
    }

    String country = "";
    if (!sLabelInfo.getcountry().equals("India")) {
        country = sLabelInfo.getcountry();
    }

    if (sLabelInfo.getstate().isEmpty()) {
        lastLine = lastLine + country;
    } else {
        lastLine = lastLine + " " + country;
    }

    if (!lastLine.isEmpty()) {
        lastLine = lastLine.trim();
        // Remove the leading spaces
        //lastLine.replaceAll("^\\s+", "");
        info.add(new Chunk(lastLine, font));
    }

    return info;

}

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);//  ww w .  ja  v a  2s . 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.toegepaste.controller.PdfController.java

public void CreatePdf(long studentId) {
    //Fonts//from  w ww .  ja v  a  2  s  .  c o  m
    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();
    }

}

From source file:jeanderson.br.nota.Notas.java

public boolean gerarNotas(int desconto) {
    PdfPTable tabela = new PdfPTable(new float[] { 0.7f, 0.18f, 0.2f });
    Document doc = new Document(PageSize.A4, 72, 72, 72, 72);
    try {//w  w  w .j a  v  a 2 s  . c  o  m
        OutputStream os = new FileOutputStream("/Users/" + System.getProperty("user.name")
                + "/Google Drive/Notas Fiscais/PDF/" + nomeCliente + ".pdf");
        PdfWriter.getInstance(doc, os); // instancio o pdf que vou gravar
        doc.open(); // abro o pdf
        // seleciono a fonte, tamanho
        Font f = new Font(Font.FontFamily.COURIER, 20, Font.BOLD);
        //crio o paragrafo.
        Paragraph p1 = new Paragraph("Nota Eletrnica", f);
        Paragraph p2 = new Paragraph("Comprador(a): " + nomeCliente + "\nEndereo: " + endereco + "\nBairro: "
                + bairro + "  " + "Cidade: " + cidade + "\nVendedor: Jonatha Monteiro");
        PdfPCell celula = new PdfPCell(p1);
        celula.setColspan(3);
        celula.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(celula);
        PdfPCell celula2 = new PdfPCell(p2);
        celula2.setColspan(3);
        tabela.addCell(celula2);
        PdfPCell nProduto = new PdfPCell(new Paragraph("Produto"));
        PdfPCell nValor = new PdfPCell(new Paragraph("Valor(UN)"));
        nProduto.setHorizontalAlignment(Element.ALIGN_CENTER);
        nValor.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(nProduto);
        tabela.addCell("Quantidade");
        tabela.addCell(nValor);
        double valorTotal = 0;
        for (int i = 0; i < this.produtos.size(); i++) {
            tabela.addCell(produtos.get(i));
            tabela.addCell(quantidades.get(i));
            tabela.addCell(valor.get(i));
            valorTotal += Integer.parseInt(quantidades.get(i)) * Double.parseDouble(valor.get(i));
        }
        Paragraph p3 = null;
        if (desconto == 0) {
            p3 = new Paragraph("Data de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
        } else {
            p3 = new Paragraph(
                    "\n\nData de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
        }
        PdfPCell celula3 = new PdfPCell(p3);
        celula3.setColspan(1);
        tabela.addCell(celula3);
        DecimalFormat df = new DecimalFormat("###,##0.00");
        Paragraph p4 = new Paragraph("Valor Total: R$" + df.format(valorTotal));
        PdfPCell celula4 = null;
        double valorDesc = 0;
        double valorComDesc = 0;
        switch (desconto) {
        case 0:
            celula4 = new PdfPCell(p4);
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 1:
            valorDesc = (valorTotal * 7) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 7% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 2:
            valorDesc = (valorTotal * 10) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n - 10% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 3:
            valorDesc = (valorTotal * 12) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 12% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 4:
            valorDesc = (valorTotal * 15) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 15% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        }
        //tabela.addCell(celula4);
        tabela.setWidthPercentage(100.0f);
        doc.add(tabela); // adiciono a tabela
        doc.close();
        os.close();
        return false;
    } catch (FileNotFoundException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    } catch (DocumentException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    } catch (IOException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    }
}

From source file:Logic.DocsCreation.java

public void createPdfDoc(JTable Table, GetPatientData data, StartDB con, boolean flag,
        ArrayList<String> arrPatient, String crb) {
    try {// ww w  . j a  va 2  s.  c om
        norm.getNorm(con.getConnection());
        int b = arrPatient.size();
        if (b == -1) {
            return;
        }
        String path = System.getProperty("user.home");
        path = path + "//Desktop//";
        File theDir = new File(path, "???");
        // if the directory does not exist, create it
        if (!theDir.exists()) {

            boolean result = false;

            try {
                theDir.mkdir();
                result = true;
            } catch (SecurityException se) {
                //handle it
            }
            if (result) {
                System.out.println("DIR created");
            }
        }
        for (int k = 0; k < b; k++) {
            String id = arrPatient.get(k);//Table.getModel().getValueAt(k, 0).toString(); 
            data = new GetPatientData();
            data.getMainData(con.getConnection(), id, crb);
            data.getPatientDocs(con.getConnection(), id);
            String[] arr = null;
            String fname = data.getName().replaceAll(" ", "") + data.getBirth();

            Document doc = new Document();
            String fileName = path + "\\???\\" + fname + ".pdf";
            String pdfName = "";
            FileOutputStream fos = new FileOutputStream(fileName);
            PdfWriter.getInstance(doc, fos);
            doc.open();

            BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\ARIAL.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            BaseFont bfn = BaseFont.createFont("C:\\Windows\\Fonts\\ARIALI.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            // 
            Paragraph title = new Paragraph(data.getCrbName() + "\n", new Font(bf, 16, Font.BOLD));
            title.setAlignment(Element.ALIGN_CENTER);
            doc.add(title);
            // ? 
            Paragraph lpu = new Paragraph("?   " + data.getLpu(), new Font(bf, 12));
            lpu.setAlignment(Element.ALIGN_RIGHT);
            doc.add(lpu);
            doc.add(new Phrase(
                    "____________________________________________________________________________________\n",
                    new Font(bf, 11, Font.BOLD)));

            doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getName() + " (" + data.getSex() + ")\n", new Font(bf, 13)));
            doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getBirth() + "\n", new Font(bf, 13)));
            doc.add(new Phrase(" ? ??: ",
                    new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getDate() + "\n", new Font(bf, 13)));

            if (data.getSnils() != null) {
                doc.add(new Phrase("? : ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getSnils() + "\n", new Font(bf, 13)));
            }
            if (data.getDocs() != null) {
                doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getDocs() + " ", new Font(bf, 13)));
                ;
            }
            if (data.getPolicy() != null) {
                doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPolicy() + "; ", new Font(bf, 13)));
            }

            if (data.getPhone() != null) {
                doc.add(new Phrase("?  ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPhone() + "; ", new Font(bf, 13)));
            }
            //  ?

            data.getDoneServiceCount(con.getConnection(), id);
            data.getDoneServiceData(con.getConnection(), id);
            // data.getDoneServiceProp(con.getConnection(), id,data.getService_code().get(k));
            //  ?
            doc.add(new Paragraph("\n ?: \n", new Font(bf, 16, Font.BOLD)));

            for (int i = 0; i < data.getCount(); i++) {
                data.getDoneServiceProp(con.getConnection(), id, data.getService_code().get(i));
                doc.add(new Phrase(data.getService_name().get(i) + " : \n", new Font(bf, 12, Font.BOLD)));
                if (data.getService_result().get(i) != null) {
                    arr = data.getService_result().get(i).split(";");

                    for (int l = 0; l < norm.getCode().size(); l++) {
                        if (data.getService_code().get(i).equals(norm.getCode().get(l))) {
                            flagExistNorm = true;
                            if ("".equals(data.getSex()))
                                arrNorm = norm.getNormsWoman().get(l).split(";");
                            else if ("".equals(data.getSex())) {
                                arrNorm = norm.getNormsMan().get(l).split(";");
                            }

                            break;
                        } else
                            flagExistNorm = false;
                    }

                    //<editor-fold defaultstate="collapsed" desc="?? ?? ">
                    //                switch(data.getService_name().get(i)){            
                    //                    
                    //                    case "01.?()":
                    //                    doc.add(new Phrase("  ? - " +arr[0]+ " ;\n " ,new Font(bf, 12)));
                    //                    break;
                    //                    
                    //                    case "02.??":                 
                    //                        doc.add(new Phrase("? - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?  - " + arr[1] +" ;\n ",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                    case "03.  ?":                 
                    //                        doc.add(new Phrase("   - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?   - " + arr[1] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ;\n ",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                     case "06.?  " :                 
                    //                            
                    //                     {   
                    //                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
                    //                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
                    //                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                    //                            targetFile.write(data.getPDFData(con.getConnection(), id));
                    //                            targetFile.close();
                    //                            log.info("pdf  ? "+id+ "?");
                    //                            } catch (Exception ex) {
                    //                                    log.error(ex, ex);                            
                    //                            }
                    //                        }
                    //                     break;         
                    //
                    //                     case "08.? ":                 
                    //                        doc.add(new Phrase(" ?? - " + arr[0] +" ;\n",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                     case "13.  ":                 
                    //                        doc.add(new Phrase("\n (), / - " + arr[0] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", /- " + arr[1] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[2] +" - \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (),-/ - " + arr[3] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), -/ - " + arr[4] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? ? - " + arr[5] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("pH - " + arr[6] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[7] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("??? ?, / - " + arr[8] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[9] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), / - " + arr[10] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[11] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[12] +" ;\n",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                        case "16.  ?":                 
                    //                        doc.add(new Phrase(" - " + arr[0] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[1] +" ;",new Font(bf, 12)));                
                    //                        break;
                    //                    } 
                    //</editor-fold>    
                    //            
                    int arrSize = arr.length;
                    for (int j = 0; (j < arrSize); j++) {

                        if (data.getService_name().get(i).contains("?")
                                || data.getService_name().get(i).contains("")) {
                            doc.add(new Phrase("  " + ";\n ", new Font(bf, 12)));
                            pdfName = "C:\\MDKTemp\\" + fname + "ECG.pdf";
                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                                targetFile.write(data.getPDFData(con.getConnection(), id));
                                targetFile.close();
                                log.info("pdf  ? " + id + "?");

                                break;
                            } catch (Exception ex) {
                                log.error(ex, ex);
                            }
                        }
                        if (flagExistNorm) {
                            String[] border;
                            border = new String[2];

                            border = arrNorm[j].split(" - ");
                            if (Float.parseFloat(arr[j]) >= Float.parseFloat(border[0])) {
                                if (Float.parseFloat(arr[j]) <= Float.parseFloat(border[1])) {
                                    //   ?

                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                            new Font(bf, 12)));
                                } else {
                                    //    
                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                            new Font(bf, 12, Font.UNDERLINE)));
                                    if (border[0].equals(border[1])) {
                                        doc.add(new Phrase("! (? " + border[0] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                    } else
                                        doc.add(new Phrase(
                                                "! (? " + border[0] + " - " + border[1] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                }
                            } else {
                                //    
                                doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                        new Font(bf, 12, Font.UNDERLINE)));
                                if (border[0].equals(border[1])) {
                                    doc.add(new Phrase("! (? " + border[0] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                                } else
                                    doc.add(new Phrase(
                                            "! (? " + border[0] + " - " + border[1] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                            }
                        } else
                            doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                    new Font(bf, 12)));

                    }

                }
            }
            //  ?
            data.getAppoitedServiceCount(con.getConnection(), id);
            data.getAppServiceData(con.getConnection(), id);
            doc.add(new Phrase("? ? :\n", new Font(bf, 16, Font.BOLD)));
            for (int j = 0; j < data.getCount(); j++) {
                if (data.getService_result().get(j) != null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_result().get(j) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(j) == null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " ; ", new Font(bf, 12, Font.BOLD)));
                }
            }
            // 
            data.getRenServiceCount(con.getConnection(), id);
            data.getRenServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_name().get(i) == null) {
                    doc.add(new Phrase("? ", new Font(bf, 12)));
                }
                doc.add(new Phrase(data.getService_name().get(i) + " ; ", new Font(bf, 12, Font.BOLD)));
            }
            // 
            data.getEarlierServiceCount(con.getConnection(), id);
            data.getEarServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n  : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_result().get(i) != null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_date().get(i) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(i) == null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " ;", new Font(bf, 12)));
                }

            }
            doc.close();
            if (!flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = path + "//???//" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                }
            }

            if (flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = "C:\\" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                    File pfile = new File(res);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                } else {
                    File pfile = new File(fileName);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e, e);
    }

}

From source file:logica.Generar_pdf.java

public void ConvertirPDF(int num, String nombre, String nombre2, String cedula, String cedula2,
        String direccion, String direccion2, String telefono, String telefono2, String sede, String tipo,
        String observacion, int peso, int declaracion_precio, int precio_neto, int precio_seguro,
        int precio_impuesto, int total_envio, String forma_pago, String fecha) throws FileNotFoundException {
    String nombre_pdf = "Factura No " + num + ".pdf";
    System.out.println(nombre_pdf);
    try {/* www  .ja  v  a  2  s .  c  om*/
        //Creamos documento indicando el tamao y margenes
        Document documento = new Document(PageSize.LETTER, 20, 20, 20, 20);

        //Creamos el PDF y lo instanceamos para poder escribir sobre el
        PdfWriter.getInstance(documento, new FileOutputStream(nombre_pdf)).setInitialLeading(20);

        //Abrimos el documento
        documento.open();
        System.out.println("Documento Abierto");

        //Anexamos el texto a un objeto Pharagraph
        Paragraph parametro = new Paragraph("Factura Envio de Paquete No. " + num,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, BaseColor.BLACK));
        parametro.setAlignment(1);
        Paragraph parametro17 = new Paragraph("Fecha: " + fecha,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD, BaseColor.BLACK));
        parametro17.setAlignment(1);
        Paragraph parametro2 = new Paragraph("Datos Remitente",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro3 = new Paragraph("Nombre: " + nombre + "        Telefono: " + telefono,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro4 = new Paragraph("Cedula: " + cedula + "        Direccin: " + direccion,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro5 = new Paragraph("Datos Destinatario",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro6 = new Paragraph("Nombre: " + nombre2 + "        Telefono: " + telefono2,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro7 = new Paragraph("Cedula: " + cedula2 + "        Direccin: " + direccion2,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));

        Paragraph parametro8 = new Paragraph("Datos Envio",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro9 = new Paragraph("Tipo de Envio: " + tipo + "        Observacin: " + observacion,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro10 = new Paragraph(
                "Peso: " + peso + "        Declaracin precio Envio: " + declaracion_precio,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro11 = new Paragraph("Datos Pago",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
        Paragraph parametro12 = new Paragraph("Precio de Envio Neto: " + precio_neto,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro13 = new Paragraph("Precio Seguro:  " + precio_seguro,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro14 = new Paragraph("Excedente Impuesto:  " + precio_impuesto,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro15 = new Paragraph("Total Envio:  " + total_envio,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));
        Paragraph parametro16 = new Paragraph("Forma de Pago:  " + forma_pago,
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK));

        //Escribimos sobre el
        documento.add(parametro);
        documento.add(parametro17);
        documento.add(parametro2);
        documento.add(parametro3);
        documento.add(parametro4);
        documento.add(parametro5);
        documento.add(parametro6);
        documento.add(parametro7);
        documento.add(parametro8);
        documento.add(parametro9);
        documento.add(parametro10);
        documento.add(parametro11);
        documento.add(parametro12);
        documento.add(parametro13);
        documento.add(parametro14);
        documento.add(parametro15);
        documento.add(parametro16);

        //Cerrar documento
        documento.close();

        //Mensaje de Exito
        JOptionPane.showMessageDialog(null, "PDF Creado con exito.");

    } catch (DocumentException de) {
        System.out.println("Error...");
    }

}