Example usage for com.lowagie.text Font BOLD

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

Introduction

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

Prototype

int BOLD

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

Click Source Link

Document

this is a possible style.

Usage

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void addTitle(Document doc, String text)
        throws IOException, BadElementException, DocumentException {
    float[] widths = { 62f, 164f, 62f };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage(100);/*  w w  w.j  av  a 2 s . c  om*/
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.setSpacingAfter(10);

    Image image = Image.getInstance("app_title.gif");
    image.scalePercent(70);
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    Paragraph title = new Paragraph(text, FontFactory.getFont("arial", 12, Font.BOLD));
    cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    image = Image.getInstance("title_shot.gif");
    image.scalePercent(70);
    cell = new PdfPCell(image);
    cell.setPadding(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);

    doc.add(table);

    table = new PdfPTable(1);
    table.setWidthPercentage(100);
    cell = new PdfPCell();
    cell.setBackgroundColor(Color.BLACK);
    cell.setFixedHeight(1);
    table.addCell(cell);

    doc.add(table);
}

From source file:textdisplay.TagFilter.java

License:Educational Community License

public void replaceTagsWithPDFEncoding(String[] tags, styles[] tagStyles, OutputStream os)
        throws DocumentException {
    //   FileWriter w = null;

    try {/*from   w w  w  .j a v  a 2s. c o  m*/
        BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

        Document doc = new Document();
        PdfWriter p = PdfWriter.getInstance(doc, os);
        doc.open();
        Paragraph para = new Paragraph();
        para.setFont(new Font(bf, 12, Font.NORMAL));
        //doc.add(para);
        Font italic = new Font(bf, 12, Font.ITALIC);
        Font bold = new Font(bf, 12, Font.BOLD);
        Font underlined = new Font(bf, 12, Font.UNDERLINE);

        StringBuilder chunkBuffer = new StringBuilder(""); //holds the next bit of content that will be added to the pdf as a chunk
        styles chunkStyle = null; //the style to be applied to chunkBuffer when it gets added to the document
        String chunkTag = "";
        Stack<String> wrappingTags = new Stack();
        Stack<styles> wrappingStyles = new Stack();
        String content = text;
        Boolean inTag = false; //is this inside a tag, meaning between the < and >
        String tagTextBuffer = ""; //the text of the tag, including name and any parameters
        Boolean beingTagged = false; //Is the parser currently reading character data that is surrounded by a tag that demands styling
        for (int charCounter = 0; charCounter < this.text.length(); charCounter++) {

            if (text.charAt(charCounter) == '>') {
                inTag = false;
                //if this was a self closing tag, dont do anything
                if (tagTextBuffer.contains("/>")) {
                    tagTextBuffer = "";
                } else {
                    //this is a closing tag, save the chunk and pop the tag and style off of the stack
                    if (tagTextBuffer.startsWith("/")) {
                        if (chunkStyle != null)
                            System.out.print(" closing tag " + tagTextBuffer + " with style "
                                    + chunkStyle.name() + "\n");
                        else
                            System.out.print(" closing tag " + tagTextBuffer + " with style null" + "\n");
                        if (chunkStyle == styles.paragraph)
                            chunkBuffer = new StringBuilder("\n" + chunkBuffer);
                        Chunk c = new Chunk(chunkBuffer.toString());
                        styleChunk(c, chunkStyle);

                        if (chunkStyle != styles.remove)
                            para.add(c);
                        chunkBuffer = new StringBuilder("");
                        chunkStyle = null;
                        chunkTag = "";
                        if (!wrappingStyles.empty()) {
                            chunkStyle = wrappingStyles.pop();
                            chunkTag = wrappingTags.pop();
                        }
                        tagTextBuffer = "";

                    } else {
                        //this is the closing bracket of an opening tag
                        String tagName = tagTextBuffer.split(" ")[0];
                        System.out.print("tag is " + tagName + "\n");
                        for (int i = 0; i < tags.length; i++) {

                            if (tags[i].compareTo(tagName) == 0) {
                                // this is a tag that is suposed to be styled in the pdf
                                if (chunkStyle != null) {
                                    //this tag is nested in a tag that was already applying styling. Add this chunk to the pdf and put the tag/style
                                    //for the previous tag on the stack, so when this new tag ends, the previous styling will resume.
                                    if (chunkStyle == styles.paragraph)
                                        chunkBuffer = new StringBuilder("\n" + chunkBuffer);
                                    Chunk c = new Chunk(chunkBuffer.toString());
                                    styleChunk(c, chunkStyle);
                                    if (chunkStyle != styles.remove)
                                        para.add(c);
                                    wrappingStyles.add(chunkStyle);
                                    wrappingTags.add(chunkTag);
                                    chunkTag = tagName;
                                    chunkStyle = tagStyles[i];
                                    chunkBuffer = new StringBuilder("");
                                } else {
                                    Chunk c = new Chunk(chunkBuffer.toString());
                                    para.add(c);
                                    chunkTag = tagName;
                                    chunkStyle = tagStyles[i];
                                    chunkBuffer = new StringBuilder("");
                                }
                            }
                        }
                        tagTextBuffer = "";
                    }
                }
            }
            if (inTag) {
                tagTextBuffer += text.charAt(charCounter);
            }
            if (text.charAt(charCounter) == '<') {
                if (inTag) {
                    //if we hit another < before hitting a > this was not a tag, so add the tagTextBuffer to the chunk. It was simply conent.
                    chunkBuffer.append(tagTextBuffer);
                    tagTextBuffer = "";
                }
                inTag = true;
            }
            if (!inTag && text.charAt(charCounter) != '>') {
                chunkBuffer.append(text.charAt(charCounter));
            }
        }
        Chunk c = new Chunk(chunkBuffer.toString());
        para.add(c);
        doc.newPage();
        doc.add(para);
        doc.newPage();
        doc.close();
    } catch (IOException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

    }

}

From source file:textdisplay.TagFilter.java

License:Educational Community License

/**Apply a style (font) to a chunk of pdf text*/
private void styleChunk(Chunk c, styles s) {
    try {//from w  w w  .  j ava2  s .c o m

        BaseFont bf = BaseFont.createFont("/usr/Junicode.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont ita = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont bol = BaseFont.createFont("/usr/Junicode-Italic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        if (bf.charExists(540)) {
            System.out.print("font cant do 540\n");
        }
        Font italic = new Font(ita, 12, Font.ITALIC);
        Font bold = new Font(bol, 12, Font.BOLD);
        Font underlined = new Font(bf, 12, Font.UNDERLINE);
        Font superscript = new Font(bf, 9, Font.NORMAL);

        if (s == styles.bold) {
            c.setFont(bold);
        }
        if (s == styles.italic) {
            c.setFont(italic);
        }
        if (s == styles.underlined) {
            c.setFont(underlined);
        }
        if (s == styles.superscript) {
            c.setTextRise(7.0f);
            c.setFont(superscript);

        }

        //wipe out that content

    } catch (DocumentException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TagFilter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createOutline(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612//from   w ww .  j  a v  a  2s.c  o  m
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object               
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        Paragraph p1 = new Paragraph(VUE.getActivePathway().getLabel());
        p1.setSpacingAfter(15.0f);
        Font f = p1.getFont();
        f.setStyle(Font.BOLD);
        p1.setFont(f);
        document.add(p1);

        /*p1.add("The leading of this paragraph is calculated automagically. ");
        p1.add("The default leading is 1.5 times the fontsize. ");
        p1.add(new Chunk("You can add chunks "));
        p1.add(new Phrase("or you can add phrases. "));
        p1.add(new Phrase(
           */
        int entryCount = 1;
        int currentIndex = VUE.getActivePathway().getIndex();

        VUE.getActivePathway().setIndex(-1);
        for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) {

            String notes = entry.getNotes();
            Paragraph p = new Paragraph(entryCount + ".  " + entry.getLabel());
            f = p.getFont();
            f.setStyle(Font.BOLD);
            p.setFont(f);
            Paragraph notesP = new Paragraph(notes);
            notesP.setIndentationLeft(15.0f);
            notesP.setSpacingAfter(15.0f);
            document.add(p);
            document.add(notesP);

            entryCount++;
        }
        VUE.getActivePathway().setIndex(currentIndex);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }
    // step 5: we close the document
    document.close();

}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

public static void createNodeOutline(File file) {
    //page size notes:
    //martin-top,left,right,bottom = 36
    //widht :612//ww w  .  j  ava2  s. c  om
    //height : 792
    //usable space 540 x 720
    // step 1: creation of a document-object               
    Document document = new Document(PageSize.LETTER);

    try {
        GUI.activateWaitCursor();
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file            
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        //  writer.setDefaultColorspace(PdfName.DEFAULTRGB, null);
        // writer.setStrictImageSequence(true);

        // step 3: we open the document
        document.open();

        Paragraph p1 = new Paragraph(VUE.getActiveMap().getLabel());

        p1.setSpacingAfter(15.0f);
        Font f = p1.getFont();
        f.setStyle(Font.BOLD);
        f.setSize(18f);
        p1.setFont(f);
        document.add(p1);

        String n2 = VUE.getActiveMap().getNotes();
        if (n2 != null && n2.length() > 0) {
            Paragraph p2 = new Paragraph(n2);
            p2.setIndentationLeft(30.0f);
            p2.setSpacingAfter(15.0f);
            //   f = p2.getFont();
            //f.setSize(f.getSize()-2);
            //p2.setFont(f);
            document.add(p2);
        }

        int entryCount = 1;
        float indentation = 0.0f;
        Iterator it = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();

        while (it.hasNext()) {
            LWComponent c = (LWComponent) it.next();
            if (c instanceof LWNode) {
                LWNode n = (LWNode) c;
                outlineChildNode(document, indentation, n, entryCount);
                entryCount++;
                iterateChildren(document, indentation + 10, n, 1);
            }

        }

        it = VUE.getActiveMap().getAllDescendents(LWComponent.ChildKind.PROPER).iterator();
        while (it.hasNext()) {
            LWComponent c = (LWComponent) it.next();
            if (c instanceof LWLink) {
                LWLink l = (LWLink) c;
                String notes = l.getNotes();
                String linkLabel = l.getLabel();

                if ((notes == null || notes.length() == 0) && (linkLabel == null || linkLabel.length() == 0))
                    continue;

                if (linkLabel == null || linkLabel.length() == 0)
                    linkLabel = "Link";

                Paragraph p = new Paragraph(entryCount + ".  " + linkLabel.replaceAll("\\n", ""));
                f = p.getFont();
                f.setStyle(Font.BOLD);
                f.setSize(14f);
                p.setFont(f);
                Paragraph notesP = new Paragraph(notes);

                // f = notesP.getFont();
                //   f.setSize(f.getSize()-2);
                notesP.setIndentationLeft(30.0f);
                notesP.setSpacingAfter(15.0f);
                document.add(p);
                document.add(notesP);

                entryCount++;
            }
        }

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    } finally {
        GUI.clearWaitCursor();
    }
    // step 5: we close the document
    document.close();

}

From source file:tufts.vue.PresentationNotes.java

License:Educational Community License

private static void outlineChildNode(Document d, float indentation, LWNode n, int entryCount) {
    String notes = n.getNotes();/* www .  j  a v  a2 s  .co m*/
    String nodeLabel = n.getLabel();

    if (nodeLabel == null || nodeLabel.length() == 0)
        nodeLabel = "Node";

    Paragraph p = new Paragraph(entryCount + ".  " + n.getLabel().replaceAll("\\n", ""));
    Font f = p.getFont();
    f.setStyle(Font.BOLD);
    f.setSize(14f);
    p.setFont(f);
    p.setIndentationLeft(indentation);
    Paragraph notesP = new Paragraph(notes);

    notesP.setIndentationLeft(indentation + 20);
    notesP.setSpacingAfter(15.0f);
    try {
        d.add(p);
        d.add(notesP);
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:uk.ac.bbsrc.tgac.miso.core.data.decorator.itext.ITextProjectDecorator.java

License:Open Source License

public void buildReport() throws DocumentException {
    report = new Document();
    PdfWriter writer = PdfWriter.getInstance(report, stream);
    report.open();//from ww  w.j a va  2s  .c o  m
    report.add(new Paragraph("Project Summary"));
    PdfContentByte cb = writer.getDirectContent();
    cb.setLineWidth(2.0f); // Make a bit thicker than 1.0 default
    cb.setGrayStroke(0.9f); // 1 = black, 0 = white
    float x = 72f;
    float y = 200f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    report.add(new Paragraph(project.getAlias()));
    report.add(new Paragraph(project.getDescription()));

    PdfPTable t = new PdfPTable(1);
    t.setHorizontalAlignment(Element.ALIGN_CENTER);
    t.setWidthPercentage(100f); // this would be the 100 from setHorizontalLine
    t.setSpacingAfter(5f);
    t.setSpacingBefore(0f);
    t.getDefaultCell().setUseVariableBorders(true);
    t.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    t.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    t.getDefaultCell().setBorder(Rectangle.BOTTOM); // This generates the line
    t.getDefaultCell().setBorderWidth(1f); // this would be the 1 from setHorizontalLine
    t.getDefaultCell().setPadding(0);
    t.addCell("");
    report.add(t);

    x = 72f;
    y = 100f;
    cb.moveTo(x, y);
    cb.lineTo(x + 72f * 6, y);
    cb.stroke();

    if (project.getSamples().size() > 0) {
        report.add(new Paragraph("Samples"));
        for (Sample sample : project.getSamples()) {
            Paragraph sPara = new Paragraph(sample.getAlias(), FontFactory.getFont("Helvetica", 12, Font.BOLD));
            sPara.setIndentationLeft(20);
            report.add(sPara);
            report.add(new Paragraph(sample.getDescription()));
        }
    }

    report.close();
}

From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java

private void saveAsPdfBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsPdfBtnActionPerformed
    Document document = new Document(PageSize.A4.rotate());
    String[] headers = new String[] { "Name", "TimeStamp", "Resp Rate", "Heart Rate", "Blood Pressure",
            "Temperature", "Status" };
    String filename = fileNameTxt.getText();
    try {/* ww  w . j a va2  s . c  o  m*/
        if (!filename.equals("")) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));

            document.open();
            PdfContentByte cb = writer.getDirectContent();

            cb.saveState();
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 8, Font.BOLD)));
                table.addCell(cell);

            }
            table.completeRow();

            table.spacingBefore();
            table.spacingAfter();
            document.add(table);
            Graphics2D g2 = cb.createGraphicsShapes(500, 500);
            //cb.showTextAligned(PdfContentByte.ALIGN_CENTER, g2, 200, 300, 0);

            Shape oldClip = g2.getClip();
            g2.clipRect(0, 0, 700, 500);

            vitalSignjTable.print(g2);
            g2.setClip(oldClip);

            g2.dispose();
            cb.restoreState();
            JOptionPane.showMessageDialog(null, "file saved", "Saved", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "enter the filename", "FileName", JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:util.PDFconverter.java

public static void createPDF(String[] header, String[][] data, String path, String tittle,
        float[] columnWidths) {
    try {/*from w w w .  j  a v  a2s . co m*/
        Document doc = new Document();

        PdfWriter.getInstance(doc, new FileOutputStream(path));

        doc.open();
        doc.setPageSize(PageSize.A4);
        doc.setMargins(10, 10, 10, 10);
        Font litle = new Font(Font.COURIER, 7, Font.NORMAL);
        Font norm = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
        Font normBold = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
        Font TitleFont = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);

        doc.add(Chunk.NEWLINE);
        Paragraph judul = new Paragraph(tittle, TitleFont);
        judul.setAlignment(Element.ALIGN_CENTER);
        doc.add(judul);

        //          Paragraph tgl = new Paragraph("tanggal " + tanggal + "\n", TitleFont);            
        //          tgl.setAlignment(Element.ALIGN_CENTER);
        //          doc.add(tgl);
        doc.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(header.length);
        table.setWidthPercentage(100f);

        for (String head : header) {
            table.addCell(new PdfPCell(new Phrase(head, normBold)));
        }

        for (String[] obj : data) {
            for (int i = 0; i < header.length; i++) {
                table.addCell(new PdfPCell(new Phrase(obj[i], norm)));
            }

        }

        //float[] columnWidths = new float[] {10f, 20f, 30f, 10f};
        table.setWidths(columnWidths);

        doc.add(table);

        //            Paragraph stamp = new Paragraph(new Chunk("this report has generated with QCMS by " + System.getProperty("user.name") + " on " + new Date(), litle));
        //            stamp.setAlignment(Element.ALIGN_BOTTOM);
        //            stamp.setAlignment(Element.ALIGN_CENTER);
        //            doc.add(stamp);
        //
        //            Paragraph tanda = new Paragraph(new Chunk("Mengetahui,", norm));
        //            tanda.setSpacingBefore(100);
        //            tanda.setAlignment(Element.ALIGN_RIGHT);
        //            tanda.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(tanda);
        //
        //            Paragraph nama = new Paragraph(new Chunk("MANAGER Dept.RnQ", norm));
        //            nama.setSpacingBefore(30);
        //            nama.setAlignment(Element.ALIGN_RIGHT);
        //            nama.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(nama);
        doc.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(PDFconverter.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:vistas.reportes.procesos.rptAsistenciaEntrada.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*  w w w .  j  a v  a  2 s.c  om*/
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONTROL DE ASISTENCIA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("FECHA: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptAsistenciaEntrada().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}