Example usage for com.lowagie.text Font Font

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

Introduction

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

Prototype


public Font(int family) 

Source Link

Document

Constructs a Font.

Usage

From source file:cz.incad.kramerius.pdf.utils.pdf.FontMap.java

License:Open Source License

private Font createGentiumFont(File fontDirectory) throws DocumentException, IOException {
    File fontFile = new File(fontDirectory.getAbsolutePath(), "GentiumPlus-R.ttf");
    BaseFont bf = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.CP1250, true);
    return new Font(bf);
}

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {/* w w  w . jav a2 s  . com*/
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.ElementVisitorForIText.java

License:Open Source License

@Override
public void visit(TextAElement ele) {
    StylableAnchor anchor = document.createAnchor(currentContainer);
    String reference = ele.getXlinkHrefAttribute();
    applyStyles(ele, anchor);/*from  w w  w  . ja  v a2s. c  om*/

    if (anchor.getFont().getColor() == null) {
        // if no color was applied to the link get the font of the paragraph and set blue color.
        Font linkFont = anchor.getFont();
        Style style = currentContainer.getLastStyleApplied();
        if (style != null) {
            StyleTextProperties textProperties = style.getTextProperties();
            if (textProperties != null) {
                Font font = textProperties.getFont();
                if (font != null) {
                    linkFont = new Font(font);
                    anchor.setFont(linkFont);
                }
            }
        }
        linkFont.setColor(Color.BLUE);
    }

    // set the link
    if (reference.endsWith(StylableHeading.IMPLICIT_REFERENCE_SUFFIX)) {
        reference = "#" + StylableHeading.generateImplicitDestination(reference);
    }
    anchor.setReference(reference);
    // Add to current container.
    addITextContainer(ele, anchor);
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableAnchor.java

License:Open Source License

public void applyStyles(Style style) {
    this.lastStyleApplied = style;

    StyleTextProperties textProperties = style.getTextProperties();
    if (textProperties != null) {
        // Font/*from w  w  w  .  j a  v a 2s .  c  om*/
        Font font = textProperties.getFont();
        if (font != null) {
            if (!font.isUnderlined()) {
                font = new Font(font);
                font.setStyle(font.getStyle() | Font.UNDERLINE);
            }
            super.setFont(font);
        }
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableAnchor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    // underline font if not explicitly set
    ArrayList<Chunk> chunks = getChunks();
    for (Chunk chunk : chunks) {
        Font f = chunk.getFont();
        if (f != null && !f.isUnderlined()) {
            f = new Font(f);
            f.setStyle(f.getStyle() | Font.UNDERLINE);
            chunk.setFont(f);/*from ww w.j a va2s  .  co m*/
        }
    }
    return this;
}

From source file:ilarkesto.integration.itext.Paragraph.java

License:Open Source License

private Font createFont(String name, FontStyle fontStyle) {
    Font font;//from ww  w . ja  va 2  s . c o  m
    try {
        font = new Font(BaseFont.createFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
    } catch (Exception ex) {
        throw new RuntimeException("Loading font failed: " + name, ex);
    }

    if (fontStyle != null) {
        font.setStyle(createStyle(fontStyle));
        font.setSize(PdfBuilder.mmToPoints(fontStyle.getSize()));
        font.setColor(fontStyle.getColor());
    }

    return font;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

/**
 * Method getDefaultTextFont.//from www.  jav  a  2s .c  om
 * 
 * @return Font
 */
private Font getDefaultTextFont() {
    if (defaultTextFont == null) {
        defaultTextFont = new Font(Font.HELVETICA);
        defaultTextFont.setSize(12);
    }
    return defaultTextFont;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private Font getDefaultAddressTextFont() {
    if (defaultAddressTextFont == null) {
        defaultAddressTextFont = new Font(Font.HELVETICA);
        defaultAddressTextFont.setSize(12);
    }/*from   w  w  w .  j av a 2s  .  c o m*/
    return defaultAddressTextFont;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private Font decodeFont(String fontstring, Font returnFont) {
    if (fontstring != null) {
        int family = -1;
        StringTokenizer tokener = new StringTokenizer(fontstring, "-");
        // family part
        if (tokener.hasMoreTokens()) {
            family = Font.getFamilyIndex(tokener.nextToken());
        }/*  w  ww. j av a2  s  . c o  m*/
        if (family > -1) {
            Font font = new Font(family);
            // size part
            if (tokener.hasMoreTokens()) {
                float size = Float.parseFloat(tokener.nextToken());
                font.setSize(size);
            }
            // style part
            if (tokener.hasMoreTokens()) {
                font.setStyle(tokener.nextToken());
            }
            // color part
            if (tokener.hasMoreTokens()) {
                font.setColor(IWColor.getAWTColorFromHex(tokener.nextToken()));
            }
            return font;
        }
    }
    return returnFont;
}

From source file:mitm.common.pdf.FileFontProvider.java

License:Open Source License

public FileFontProvider(File fontDir) {
    Check.notNull(fontDir, "fontDir");

    String[] fontFiles = fontDir.list(new SuffixFileFilter(".ttf"));

    if (fontFiles == null) {
        fontFiles = new String[] {};
    }//from ww  w.  ja v a 2 s  .  c  o  m

    fonts = new ArrayList<Font>(fontFiles.length);

    for (String fontFile : fontFiles) {
        logger.info("Adding font " + fontFile);

        try {
            fonts.add(new Font(
                    BaseFont.createFont(new File(fontDir, fontFile).getPath(), BaseFont.IDENTITY_H, true)));
        } catch (Throwable e) {
            logger.error("Error loading font " + fontFile, e);
        }
    }
}