Example usage for com.lowagie.text Phrase Phrase

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

Introduction

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

Prototype

public Phrase(float leading, String string, Font font) 

Source Link

Document

Constructs a Phrase with a certain leading, a certain String and a certain Font.

Usage

From source file:com.gtdfree.test.PDFTestFont.java

License:Open Source License

/**
 * Fonts and encoding.//from  www. j a va2  s. co  m
 * @param args no arguments needed
 */
public static void main(String[] args) {

    System.out.println("Encodings");

    String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

    System.out.println(Arrays.toString(names));

    /*System.out.println("---");
    try {
    System.getProperties().store(System.out, "");
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    System.out.println("---");*/
    //System.out.println(System.getenv());
    //System.out.println("---");

    //String font= System.getProperty("java.home")+"/lib/fonts/LucidaBrightRegular.ttf";
    //String font= "fonts/DejaVuSans.ttf";

    //byte[] ttf= ApplicationHelper.loadResource(font);

    try {
        // step 1
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream("encodingfont.pdf"));
        // step 3
        document.open();
        // step 4
        String all[] = { "Symbol", "ZapfDingbats" };
        Font hex = new Font(Font.HELVETICA, 5);
        for (int z = 0; z < all.length; ++z) {
            String file = all[z];
            document.add(new Paragraph(
                    "Unicode equivalence for the font \"" + file + "\" with the encoding \"" + file + "\"\n"));
            /*char tb[];
            if (z == 0)
               tb = SYMBOL_TABLE;
            else
               tb = DINGBATS_TABLE;*/
            BaseFont bf;
            if (z == 2) {
                bf = BaseFont.createFont(file, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, null, null);
                ;
            } else {
                bf = BaseFont.createFont(file, file, true);
            }
            Font f = new Font(bf, 12);
            PdfPTable table = new PdfPTable(16);
            table.setWidthPercentage(100);
            table.getDefaultCell().setBorderWidth(1);
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            for (char k = 0; k < Character.MAX_VALUE; ++k) {
                char c = k;
                if (bf.charExists(c)) {
                    Phrase ph = new Phrase(12, new String(new char[] { c }), f);
                    ph.add(new Phrase(12, "\n" + Integer.toString(c) + "\n" + cst(c), hex));
                    table.addCell(ph);
                } /*
                  else {
                     Phrase ph = new Phrase("\u00a0");
                     ph.add(new Phrase(12, "\n\n" + cst(c), hex));
                     table.addCell(ph);
                  }*/
            }
            document.add(table);
            document.newPage();
        }
        // step 5
        document.close();

        FontFactory.registerDirectories();

        Set<?> s = FontFactory.getRegisteredFonts();

        System.out.println("Fonts: " + s);

        s = FontFactory.getRegisteredFamilies();

        System.out.println("Families: " + s);

        ArrayList<Font> f = new ArrayList<Font>(s.size());

        for (Object name : s) {

            try {
                f.add(FontFactory.getFont(name.toString(), "UTF-8", true, 12, Font.NORMAL, Color.BLACK, true));
            } catch (Exception e) {
                f.add(FontFactory.getFont(name.toString(), "UTF-8", false, 12, Font.NORMAL, Color.BLACK, true));
            }

        }

        Collections.sort(f, new Comparator<Font>() {
            @Override
            public int compare(Font o1, Font o2) {
                return o1.getFamilyname().compareTo(o2.getFamilyname());
            }
        });

        for (Font ff : f) {

            if (ff.getBaseFont() == null) {
                continue;
            }
            System.out.println(ff.getFamilyname() + " " + ff.getBaseFont().isEmbedded());

        }

    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu de la liste./*from   w w w. j ava2s  .  c  o  m*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private void renderList(final ExportSheet parameters, final Table datatable) throws BadElementException {
    // data rows
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    final Font whiteFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    whiteFont.setColor(Color.WHITE);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // datatable.getDefaultCell().setGrayFill(0);

    // Parcours des DTO de la DTC
    for (final DtObject dto : parameters.getDtList()) {
        for (final ExportField exportColumn : parameters.getExportFields()) {
            final DtField dtField = exportColumn.getDtField();
            final Object value = dtField.getDataAccessor().getValue(dto);
            final int horizontalAlignement;
            if (value instanceof Number || value instanceof Date) {
                horizontalAlignement = Element.ALIGN_RIGHT;
            } else if (value instanceof Boolean) {
                horizontalAlignement = Element.ALIGN_CENTER;
            } else {
                horizontalAlignement = Element.ALIGN_LEFT;
            }
            datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

            String text = ExportUtil.getText(persistenceManager, referenceCache, denormCache, dto,
                    exportColumn);
            if (text == null) {
                text = "";
            }
            datatable.addCell(new Phrase(8, text, font));
        }
    }
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu de la liste./* www. jav  a 2  s.  c  o m*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private void renderList(final ExportSheet parameters, final Table datatable) throws BadElementException {
    // data rows
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    final Font whiteFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    whiteFont.setColor(Color.WHITE);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

    // Parcours des DTO de la DTC
    for (final DtObject dto : parameters.getDtList()) {
        for (final ExportField exportColumn : parameters.getExportFields()) {
            final DtField dtField = exportColumn.getDtField();
            final Object value = dtField.getDataAccessor().getValue(dto);
            final int horizontalAlignement;
            if (value instanceof Number || value instanceof LocalDate || value instanceof Instant) {
                horizontalAlignement = Element.ALIGN_RIGHT;
            } else if (value instanceof Boolean) {
                horizontalAlignement = Element.ALIGN_CENTER;
            } else {
                horizontalAlignement = Element.ALIGN_LEFT;
            }
            datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

            String text = ExportUtil.getText(storeManager, referenceCache, denormCache, dto, exportColumn);
            if (text == null) {
                text = "";
            }
            datatable.addCell(new Phrase(8, text, font));
        }
    }
}

From source file:net.bull.javamelody.swing.print.MPdfWriter.java

License:Apache License

/**
 * Effectue le rendu de la liste./*from  w  ww.jav  a 2s  . c o  m*/
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderList(final MBasicTable table, final Table datatable) throws BadElementException {
    final int columnCount = table.getColumnCount();
    final int rowCount = table.getRowCount();
    // data rows
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // datatable.setDefaultCellGrayFill(0);
    Object value;
    String text;
    int horizontalAlignment;
    for (int k = 0; k < rowCount; k++) {
        for (int i = 0; i < columnCount; i++) {
            value = getValueAt(table, k, i);
            if (value instanceof Number || value instanceof Date) {
                horizontalAlignment = Element.ALIGN_RIGHT;
            } else if (value instanceof Boolean) {
                horizontalAlignment = Element.ALIGN_CENTER;
            } else {
                horizontalAlignment = Element.ALIGN_LEFT;
            }
            datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment);
            text = getTextAt(table, k, i);
            datatable.addCell(new Phrase(8, text != null ? text : "", font));
        }
    }
}

From source file:org.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

public void printDocHeaderFooter() throws DocumentException {
    document.resetHeader();/*from w  w  w. j  av a 2 s  .c om*/
    document.resetFooter();

    String headerTitle = "Tickler re: " + tickler.getDemographic().getFormattedName() + " DOB:"
            + tickler.getDemographic().getFormattedDob();

    if (newPage) {
        document.newPage();
        newPage = false;
    }

    //Header will be printed at top of every page beginning with p2
    Phrase headerPhrase = new Phrase(LEADING, headerTitle, boldFont);

    getDocument().add(headerPhrase);
    getDocument().add(new Phrase("\n"));
}