Example usage for com.lowagie.text Font COURIER

List of usage examples for com.lowagie.text Font COURIER

Introduction

In this page you can find the example usage for com.lowagie.text Font COURIER.

Prototype

int COURIER

To view the source code for com.lowagie.text Font COURIER.

Click Source Link

Document

a possible value of a font family.

Usage

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1/*ww w  . j  av a 2s  . c  o m*/
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:com.bibisco.export.ITextExporter.java

License:GNU General Public License

private void initFont(RichTextEditorSettings pRichTextEditorSettings) {
    mFont = new Font();

    if (pRichTextEditorSettings.getFont().equals("courier")) {
        mFont = new Font(Font.COURIER);
    } else if (pRichTextEditorSettings.getFont().equals("times")) {
        mFont = new Font(Font.TIMES_ROMAN);
    } else if (pRichTextEditorSettings.getFont().equals("arial")) {
        mFont = new Font(Font.HELVETICA);
    }// w  w  w.j  av a  2  s  .  c o m

    mFont.setSize(12);
}

From source file:com.geek.tutorial.itext.text.Chunk_Example.java

License:Open Source License

public Chunk_Example() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("chunk_example.pdf"));
    document.open();/*from   w ww. j av a  2s  .c o  m*/

    Font font = new Font(Font.COURIER, 10, Font.BOLD); // 1
    font.setColor(new Color(0x92, 0x90, 0x83));

    Chunk chunk = new Chunk("testing text element", font); // 2

    chunk.setBackground(new Color(0xff, 0xe4, 0x00)); // 3

    document.add(chunk); // 4
    document.close();

}

From source file:com.geek.tutorial.itext.text.Paragraph_Example.java

License:Open Source License

public Paragraph_Example() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf"));
    document.open();/*  ww  w. j ava2s  . com*/

    Font font = new Font(Font.COURIER, 10, Font.BOLD);
    font.setColor(new Color(0x92, 0x90, 0x83));
    Chunk chunk = new Chunk("testing text element ", font);
    chunk.setBackground(new Color(0xff, 0xe4, 0x00));

    Phrase phrase = new Phrase(20, "This is initial text. ");

    for (int i = 0; i < 10; i++) {
        phrase.add(chunk);
    }

    Paragraph paragraph = new Paragraph(); // 1
    paragraph.add(phrase); // 2

    document.add(paragraph); // 3   

    document.add(paragraph); // 4   

    document.close();
}

From source file:com.geek.tutorial.itext.text.Phrase_Example.java

License:Open Source License

public Phrase_Example() throws Exception {

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("phrase_example.pdf"));
    document.open();// ww  w  . ja va  2  s .  co  m

    Font font = new Font(Font.COURIER, 10, Font.BOLD);
    font.setColor(new Color(0x92, 0x90, 0x83));
    Chunk chunk = new Chunk("testing text element ", font);
    chunk.setBackground(new Color(0xff, 0xe4, 0x00));

    Phrase phrase = new Phrase(20, "This is initial text. "); // 1      

    for (int i = 0; i < 10; i++) {
        phrase.add(chunk); // 2
    }

    document.add(phrase); // 3

    document.close();
}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void init() {

    try {/*from  ww  w  .ja v  a2s.com*/

        // COURIER is monospaced font
        font = new Font(Font.COURIER, fontSize, Font.NORMAL);
        document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);

        PdfWriter.getInstance(document, getOut());
        // PdfWriter.getInstance(document, new FileOutputStream(new File(new URI(path + fileName()))));
        document.open();
        addMetaData(document);
    } catch (Exception e) {
        document = null;
        throw new RuntimeException("Error creating report " + e);
    }

}

From source file:com.sumeet.kraiglist.pdfview.PdfReportView.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document pdfdoc, PdfWriter pdfwriter,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession();
    String name = (String) session.getAttribute("firstname");
    if (name == null) {
        name = "";
    }/*w ww .ja v  a 2  s  .c  o  m*/

    Font font_helvetica_12_normal_black = new Font(Font.HELVETICA, 12, Font.NORMAL, Color.BLACK);
    Font font_courier_16_italic_blue = new Font(Font.COURIER, 10, Font.ITALIC, Color.BLUE);
    Font font_courier_16_italic_red = new Font(Font.COURIER, 16, Font.ITALIC, Color.BLUE);
    Font font_times_16_bold_green = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, Color.BLACK);

    Paragraph prg0 = new Paragraph(
            "                                             Terms of Use of MyNEU KRAIGLIST",
            font_helvetica_12_normal_black);
    Paragraph prg1 = new Paragraph(
            "____________________________________________________________________________________________________________",
            font_courier_16_italic_red);
    Paragraph prg2 = new Paragraph("");
    Chunk c1 = new Chunk("Hello " + name + ",", font_courier_16_italic_blue);
    Paragraph prg3 = new Paragraph("PRODUCT SALES : "
            + "The GSI Products listed on this Site are offered for sale solely pursuant to GSIs standard terms and conditions of sale applicable"
            + "to such products. The terms and conditions are accessible for viewing by clicking on the link on each product line home page."
            + "GSI objects to and rejects any other terms that may be proposed by any customer or potential customer. No offers to sell or purchase"
            + "GSI products are valid and binding on GSI unless and until specifically accepted, in writing, by GSI.",
            font_times_16_bold_green);
    //Phrase phr2 = new Phrase("Phrase 2", font_helvetica_16_normal_blue);
    Paragraph prg4 = new Paragraph("");
    Paragraph prg5 = new Paragraph("LICENSE TO USE THIS SITE : "
            + "We at the GSI Group Inc. and its subsidiaries (GSI) are happy to have you as a visitor. We have established the following"
            + "terms and conditions, including our Privacy Statement, as a requirement for visitors using our site. In order to use our site, you"
            + "must agree to these terms and conditions (Terms). BY CHOOSING TO ACCESS AND USE THIS SITE, YOU ARE EXPRESSLY"
            + "AGREEING TO BE LEGALLY BOUND BY THESE TERMS. IF YOU DO NOT AGREE, DO NOT USE OR VIEW THE SITE."
            + "These Terms apply only to the use of this Site and do not supercede any other contractual agreement between you and GSI."
            + "Use of Materials: Upon your agreement to the Terms, GSI grants you the right to view the site and to download materials from"
            + "this site for your personal, non-commercial use. You are not authorized to use the materials for any other purpose. If you do"
            + "download or otherwise reproduce the materials from this Site, you must reproduce all of GSIs proprietary markings, such as"
            + "copyright and trademark notices, in the same form and manner as the original."
            + "Private Pages: Some parts of this Site are not available to the general public, but only to certain business associates of GSI."
            + "These sections may only be accessed by authorized entities and are controlled by password-protected access. If you are not"
            + "authorized to use these sections, then you agree that you will not attempt to gain access. If you are authorized, then by accessing"
            + "those areas, you expressly agree to the supplemental terms that are posted as part of the access process."
            + "No Harmful Use: In exchange for our permission to use this Site, you agree that you will not do anything to harm the functioning"
            + "or content of the Site. You will not attempt to upload, insert or change any information or image to or on this Site, except for providing"
            + "information where prompted by the Site. You agree that you will not take any action that imposes an unreasonably or disproportionately"
            + "large load on the Site or interferes with its functioning. You also agree that you will not use any false identity"
            + "when interacting with the Site, or do anything that is fraudulent, obscene, libelous or legally prohibited."
            + "You may not use any deep-link, page-scrape, robot, spider or any other automatic device, program, algorithm or methodology"
            + "or any similar or equivalent manual process to access, acquire, copy or monitor any portion of the Site or any of its content,"
            + "or in any way reproduce or circumvent the navigational structure or presentation of the Site."
            + "INDEMNITY: YOU AGREE THAT YOU WILL DEFEND, INDEMNIFY AND HOLD HARMLESS GSI, ITS CUSTOMERS, SUPPLIERS"
            + "AND JOINT VENTURE PARTNERS AND THEIR RESPECTIVE EMPLOYEES, OFFICERS, DIRECTORS, CONTRACTORS,"
            + "VENDORS, ASSIGNEES AND AGENTS FOR AND AGAINST ANY COSTS, CLAIMS, DAMAGES, LOSSES, OR"
            + "OTHER LIABILITIES ARISING FROM YOUR USE OF THE SITE IN BREACH OF THESE TERMS OR IN VIOLATION OF THE"
            + "LAW. IF GSI TAKES ANY LEGAL ACTION AGAINST YOU AS A RESULT OF YOUR VIOLATION OF THESE TERMS, YOU"
            + "AGREE THAT YOU WILL BE RESPONSIBLE FOR AND WILL PAY ALL OF GSIS LEGAL FEES IN CONNECTION WITH"
            + "SUCH ACTION. ", font_times_16_bold_green);

    pdfdoc.add(c1);
    pdfdoc.add(prg0);
    pdfdoc.add(prg1);
    pdfdoc.add(prg2);
    pdfdoc.add(prg3);
    pdfdoc.add(prg4);
    pdfdoc.add(prg5);

}

From source file:datasoul.servicelist.ServiceListExporterDocument.java

License:Open Source License

private void addSongChords(String[] text) throws DocumentException {
    Font chordfont = new Font(Font.COURIER, 12, Font.BOLD, Color.BLUE.darker());
    Font lyricfont = new Font(Font.COURIER, 12, Font.NORMAL);
    Paragraph p;/*  w  w  w  .java2  s. c om*/

    for (String line : text) {

        Matcher matcher = Song.CHORDS_REGEX_PATTERN.matcher(line);

        if (matcher.find()) {
            if (line.startsWith("=")) {
                line = line.replaceFirst("=", " ");
            }
            p = new Paragraph(line, chordfont);
        } else {
            p = new Paragraph(line, lyricfont);
        }
        document.add(p);
    }

}

From source file:mesquite.lib.MesquitePDFFile.java

License:Open Source License

/**
@arg s String holds the text that the pdf file will contain
@arg font java.awt.Font the font is specified this way for compatibility with the similar method in MesquitePrintJob
 *///from   w w w . j av  a2s  . c  o m
public void printText(String s, java.awt.Font font) {
    final String exceptionMessage = "Error, an exception occurred while creating the pdf text document: ";
    if (s == null || font == null)
        return;

    //do the translation from logical to physical font here      
    //currently, the only font this method ever gets called with is "Monospaced",PLAIN,10.  So the
    //translation effort here will be minimal      
    int desiredFontFamily; // "Monospaced" isn't defined in com.lowagie.text.Font
    if (font.getFamily().equals("Monospaced"))
        desiredFontFamily = com.lowagie.text.Font.COURIER;
    else
        desiredFontFamily = com.lowagie.text.Font.TIMES_ROMAN;
    com.lowagie.text.Font textFont;
    switch (font.getStyle()) {
    case java.awt.Font.BOLD: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.BOLD);
        break;
    }
    case java.awt.Font.ITALIC: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.ITALIC);
        break;
    }
    case java.awt.Font.PLAIN: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.NORMAL);
        break;
    }
    default: {
        textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(),
                com.lowagie.text.Font.BOLDITALIC);
    }
    }
    document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(pdfPathString));
        addMetaData(document);
        document.open();
        document.add(new Paragraph(s, textFont));
    } catch (DocumentException de) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + de.getMessage());
    } catch (IOException ioe) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + ioe.getMessage());
    }
    this.end();
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
* write a label in pdf document./*from  ww  w  .j  av a2s.c o  m*/
* <br/>
* escribe una etiqueta en el documento pdf.
* @param doc pdf document / documento pdf.
* @param dto object that encompasses the values of the labels to be placed in the document / objeto que engloba los valores de las etiquetas que se colocaran en el documento.
* @param offset jump on the Y axis to be given before placing the tag in the document / salto en el eje Y que se dara antes de colocar la etiqueta en el documento.
* @param table container table if applicable / contenedor de tabla si es que aplica.
* @throws Exception If an error occurs / si ocurre algun error.
*/
public void estampaEtiqueta(Document doc, Object dto, Float offset, PdfPTable table) throws Exception {
    List<Field> fields = new ArrayList<Field>();

    for (Field m : dto.getClass().getDeclaredFields()) {
        m.setAccessible(true);
        if (m.getAnnotation(DRPdfLabel.class) != null) {
            fields.add(m);
        }
    }
    Collections.sort(fields, new Comparator<Field>() {

        public int compare(Field o1, Field o2) {
            DRPdfLabel etiqueta1 = o1.getAnnotation(DRPdfLabel.class);
            DRPdfLabel etiqueta2 = o2.getAnnotation(DRPdfLabel.class);
            String uno = int2String(etiqueta1.y()) + "." + int2String(etiqueta1.order());
            String dos = int2String(etiqueta2.y()) + "." + int2String(etiqueta2.order());
            return uno.compareTo(dos);

        }

        private String int2String(int num) {
            if (num < 10) {
                return "0" + num;
            } else {
                return String.valueOf(num);
            }
        }
    });
    DRPdfLabel etiqueta;
    DRPdfTable etiquetaTabla;
    int lineaActual = 0;
    Paragraph pantagram = null;
    StringBuffer sb = null;
    Font font;
    Object valor;
    String label;
    DRPdfImage img;
    int residuo;
    int adicional = 0;
    for (Field m : fields) {
        etiqueta = m.getAnnotation(DRPdfLabel.class);
        img = m.getAnnotation(DRPdfImage.class);
        valor = m.get(dto);
        if (valor != null && valor instanceof List) {
            etiquetaTabla = m.getAnnotation(DRPdfTable.class);
            PdfPTable tableDance = null;
            if (etiquetaTabla != null) {
                tableDance = new PdfPTable(etiquetaTabla.colsPercentage());
                tableDance.setSpacingBefore(etiqueta.offset());
                for (String c : etiquetaTabla.columnLabels()) {
                    tableDance.addCell(c);
                }
            }
            if (pantagram != null) {
                doc.add(pantagram);
                pantagram = null;
            }
            for (int i = 0; i < ((List) valor).size(); i++) {
                if (i == 0 && etiqueta.offset() > 0) {
                    estampaEtiqueta(doc, ((List) valor).get(i), etiqueta.offset(), tableDance);
                } else {
                    estampaEtiqueta(doc, ((List) valor).get(i), null, tableDance);
                }
            }
            if (etiquetaTabla != null) {
                doc.add(tableDance);
            }
        } else if (img != null) {
            /* File file = new File(IMGDIR + valor);
            FileInputStream inImg = new FileInputStream(file);
            byte[] b=new byte[(int)file.length()];
            inImg.read(b);*/

            Image ima = Image.getInstance(IMGDIR + valor);

            //System.out.println(ima.getPlainWidth());
            ima.scaleAbsoluteWidth(img.width());
            //System.out.println(ima.getScaledWidth());
            ima.scaleAbsoluteHeight(ima.getScaledWidth());
            ima.setAlignment(img.style());
            ima.setAbsolutePosition(img.x(), img.y());
            doc.add(ima);

        } else if (table != null) {

            PdfPCell cerda = null;

            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;
            DRPdfColumn col = m.getAnnotation(DRPdfColumn.class);
            if (col != null) {
                cerda = new PdfPCell(new Paragraph(label));
                cerda.setColspan(col.colspan());
                table.addCell(cerda);
            } else {
                table.addCell(label);
            }

        } else {
            if (lineaActual < etiqueta.y()) {
                if (pantagram != null) {
                    doc.add(pantagram);
                }
                if (offset == null || etiqueta.y() > 1) {
                    if (etiqueta.offset() > 0) {
                        pantagram = new Paragraph(etiqueta.offset());
                    } else {
                        pantagram = new Paragraph();
                    }
                } else {
                    pantagram = new Paragraph(offset);
                }
                lineaActual = etiqueta.y();
            }

            if (etiqueta.wspacesBefore() > 0) {
                sb = new StringBuffer("");
                fillEmpty(etiqueta.wspacesBefore(), sb);
                font = new Font(Font.COURIER, 12);
                pantagram.add(new Chunk(sb.toString(), font));
            }
            sb = new StringBuffer("");
            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;

            if (etiqueta.font().equals(BaseFont.COURIER)) {
                font = new Font(Font.COURIER, etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = 0;
            } else {
                font = FontFactory.getFont(TTFDIR + etiqueta.font(), BaseFont.CP1252, BaseFont.EMBEDDED,
                        etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = label.equals("") ? (residuo / 2) + 1 : 0;
            }

            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.DER) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            sb.append(label);
            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.IZQ) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            pantagram.add(new Chunk(sb.toString(), font));
        }
    }
    if (pantagram != null) {
        doc.add(pantagram);
    }

}