Example usage for com.lowagie.text.pdf FontSelector FontSelector

List of usage examples for com.lowagie.text.pdf FontSelector FontSelector

Introduction

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

Prototype

FontSelector

Source Link

Usage

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

License:Open Source License

public FontSelector createFontSelector(String preferredFont, FontStyle fontStyle) {
    FontSelector selector = new FontSelector();
    selector.addFont(createFont(preferredFont, fontStyle));

    // fallback from ilarkesto.jar
    selector.addFont(createFont("fonts/HDZB_36.ttf", fontStyle)); // embeddable chinese

    // fallback from iTextAsian.jar
    selector.addFont(createFont("STSong-Light", fontStyle)); // simplified chinese
    selector.addFont(createFont("MHei-Medium", fontStyle)); // traditional chinese
    selector.addFont(createFont("HeiseiMin-W3", fontStyle)); // japanese
    selector.addFont(createFont("KozMinPro-Regular", fontStyle)); // japanese
    selector.addFont(createFont("HYGoThic-Medium", fontStyle)); // korean

    return selector;
}

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

License:Open Source License

private FontSelector createFontSelector(String fontName, float size, int style, Color color) {
    FontSelector selector = new FontSelector();

    selector.addFont(FontFactory.getFont(fontName, size, style, color));

    /*/*from  w ww.j  av  a  2  s.  c o  m*/
     * Add extra fonts provided by the FontProvider
     */
    if (fontProvider != null) {
        Collection<Font> extraFonts = fontProvider.getFonts();

        for (Font extraFont : extraFonts) {
            selector.addFont(extraFont);
        }
    }

    /*
     * Supported CJK (Chinese, Japanse, Korean)
     * 
     * his is the list of fonts supported in the iTextAsian.jar:
     * Chinese Simplified:
     *      STSong-Light and STSongStd-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V
     * Chinese Traditional:
     *      MHei-Medium, MSung-Light and MSungStd-Light with the encodings UniCNS-UCS2-H and UniCNS-UCS2-V
     * Japanese:
     *      HeiseiMin-W3, HeiseiKakuGo-W5 and KozMinPro-Regular with the encodings UniJIS-UCS2-H, UniJIS-UCS2-V, UniJIS-UCS2-HW-H and UniJIS-UCS2-HW-V
     * Korean:
     *      HYGoThic-Medium, HYSMyeongJo-Medium and HYSMyeongJoStd with the encodings UniKS-UCS2-H and UniKS-UCS2-V
     * 
     * Need to find out which fonts we should add to the selector and in which order
     */
    selector.addFont(FontFactory.getFont("KozMinPro-Regular", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED, size,
            style, color));
    selector.addFont(
            FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED, size, style, color));
    selector.addFont(
            FontFactory.getFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED, size, style, color));

    return selector;
}

From source file:net.nosleep.superanalyzer.Share.java

License:Open Source License

public static void saveListOfAlbumsAsPdf(JFrame window, Analysis analysis, JProgressBar progressBar) {
    File file = askForFile(window, "pdf");
    if (file == null)
        return;//from  ww  w.j a  v a2s.  com

    Hashtable albums = analysis.getHash(Analysis.KIND_ALBUM);

    DecimalFormat timeFormat = new DecimalFormat("0.0");

    StringPair list[] = new StringPair[albums.size()];
    Enumeration keys = albums.keys();
    Integer index = 0;
    String regex = Album.SeparatorRegEx;
    while (keys.hasMoreElements()) {
        String albumartist = (String) keys.nextElement();
        String[] parts = albumartist.split(regex);
        StringPair pair = new StringPair(parts[1], parts[0]);
        list[index] = pair;
        index++;
    }

    Arrays.sort(list, new StringPairComparator());

    int done = 0;
    progressBar.setMinimum(0);
    progressBar.setMaximum(list.length);

    String infoString = NumberFormat.getInstance().format(list.length) + " ";
    if (list.length == 1)
        infoString += Misc.getString("ALBUM") + ", ";
    else
        infoString += Misc.getString("ALBUMS") + ", ";
    DateFormat dateFormat = new SimpleDateFormat().getDateInstance(DateFormat.SHORT);
    infoString += "created on " + dateFormat.format(Calendar.getInstance().getTime());

    try {
        String tmpPath = System.getProperty("java.io.tmpdir") + "/image.png";

        // create the pdf document object
        Document document = new Document();

        // create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter.getInstance(document, new FileOutputStream(file));

        // we open the document
        document.open();

        Font titleFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.NORMAL,
                new Color(0x00, 0x00, 0x00));
        Paragraph p = new Paragraph(Misc.getString("MY_ALBUMS"), titleFont);
        p.setSpacingAfter(4);
        document.add(p);

        Font subtitleFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,
                new Color(0x88, 0x88, 0x88));
        p = new Paragraph("The Super Analyzer by Nosleep Software", subtitleFont);
        p.setSpacingAfter(-2);
        document.add(p);

        p = new Paragraph(infoString, subtitleFont);
        p.setSpacingAfter(30);
        document.add(p);

        FontSelector albumSelector = new FontSelector();
        Color albumColor = new Color(0x55, 0x55, 0x55);
        albumSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, albumColor));
        Font albumAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
        albumAsianFont.setSize(8);
        albumAsianFont.setColor(albumColor);
        albumSelector.addFont(albumAsianFont);

        FontSelector artistSelector = new FontSelector();
        Color artistColor = new Color(0x77, 0x77, 0x77);
        artistSelector.addFont(FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, artistColor));
        Font artistAsianFont = FontFactory.getFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
        artistAsianFont.setSize(8);
        artistAsianFont.setColor(artistColor);
        artistSelector.addFont(artistAsianFont);

        for (index = 0; index < list.length; index++) {
            p = new Paragraph();
            p.setLeading(9);

            // separate the string into the album and artist parts

            Phrase phrase = albumSelector.process(list[index].Value);
            p.add(phrase);

            phrase = artistSelector.process(" " + Misc.getString("BY") + " " + list[index].Name);
            p.add(phrase);

            document.add(p);

            done++;
            progressBar.setValue(done);
        }

        // step 5: we close the document
        document.close();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

}

From source file:optika.sql.java

public PdfPCell getCellWhite(String text, int alignment, int bottom) {
    PdfPCell cell = new PdfPCell();
    FontSelector selector = new FontSelector();
    com.lowagie.text.Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12);
    f1.setColor(Color.white);//from  w  w  w .j a va  2 s .  com
    selector.addFont(f1);
    cell.addElement(selector.process(text));
    cell.setPadding(0);
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingBottom(bottom);
    return cell;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

@Override
public void export(GTDModel model, ActionsCollection collection, OutputStream out,
        ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception {

    fontSelector = new FontSelector();
    fontSelectorB = new FontSelector();
    fontSelectorB2 = new FontSelector();
    fontSelectorB4 = new FontSelector();

    baseFont = fontModel.getBaseFont();/* w w w  . j av a2 s  .  c  om*/

    for (BaseFont bf : fontModel.getFonts()) {
        fontSelector.addFont(new Font(bf, baseFontSize));
        fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD));
        fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD));
        fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD));
    }

    boolean emptyH2 = false;
    boolean emptyH3 = false;

    PdfPTable actionTable = null;

    Document doc = new Document();

    if (sizeSet) {
        doc.setPageSize(pageSize);
    }
    if (marginSet) {
        doc.setMargins(marginLeft, marginRight, marginTop, marginBottom);
    }

    //System.out.println("PDF size "+doc.getPageSize().toString());
    //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom);

    @SuppressWarnings("unused")
    PdfWriter pw = PdfWriter.getInstance(doc, out);

    doc.addCreationDate();
    doc.addTitle("GTD-Free PDF");
    doc.addSubject("GTD-Free data exported as PDF");

    HeaderFooter footer = new HeaderFooter(newParagraph(), true);
    footer.setAlignment(HeaderFooter.ALIGN_CENTER);
    footer.setBorder(HeaderFooter.TOP);
    doc.setFooter(footer);

    doc.open();

    Phrase ch = newTitle("GTD-Free Data");
    Paragraph p = new Paragraph(ch);
    p.setAlignment(Paragraph.ALIGN_CENTER);

    PdfPTable t = new PdfPTable(1);
    t.setWidthPercentage(100f);
    PdfPCell c = newCell(p);
    c.setBorder(Table.BOTTOM);
    c.setBorderWidth(2.5f);
    c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    c.setPadding(5f);
    t.addCell(c);
    doc.add(t);

    Iterator<Object> it = collection.iterator(order);

    while (it.hasNext()) {
        Object o = it.next();

        if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) {

            if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = false;
                emptyH3 = true;
            } else {

                doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = true;
                emptyH3 = false;
            }

            continue;
        }

        if (o instanceof Folder) {

            Folder f = (Folder) o;

            if (actionTable != null) {
                doc.add(actionTable);
                actionTable = null;
            }

            if (f.isProject()) {

                if (order == ExportAddOn.ExportOrder.ProjectsActions
                        || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) {

                    if (emptyH2 || emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSection(f.getName()));

                    if (compact) {
                        if (f.getDescription() != null && f.getDescription().length() > 0) {
                            p = newParagraph(f.getDescription());
                            p.setIndentationLeft(10f);
                            p.setIndentationRight(10f);
                            doc.add(p);
                        }
                    } else {
                        t = new PdfPTable(2);
                        t.setKeepTogether(true);
                        t.setSpacingBefore(5f);
                        t.setWidthPercentage(66f);
                        t.setWidths(new float[] { 0.33f, 0.66f });

                        c = newCell("ID");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                        t.addCell(c);
                        c = newCell("Type");
                        t.addCell(c);
                        c = newCell(newStrongParagraph("Project"));
                        t.addCell(c);
                        c = newCell("Open");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                        t.addCell(c);
                        c = newCell("All");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.size())));
                        t.addCell(c);
                        c = newCell("Description");
                        t.addCell(c);
                        c = newDescriptionCell(f.getDescription());
                        t.addCell(c);

                        doc.add(t);
                    }

                    emptyH2 = true;
                    emptyH3 = false;

                } else {

                    if (emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSubSection("Project:" + " " + f.getName()));

                    emptyH2 = false;
                    emptyH3 = true;
                }

                continue;

            }
            if (order == ExportAddOn.ExportOrder.FoldersActions
                    || order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                if (emptyH2 || emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSection(f.getName()));

                if (compact) {
                    if (f.getDescription() != null && f.getDescription().length() > 0) {
                        p = newParagraph(f.getDescription());
                        p.setIndentationLeft(10f);
                        p.setIndentationRight(10f);
                        doc.add(p);
                    }
                } else {

                    t = new PdfPTable(2);
                    t.setKeepTogether(true);
                    t.setSpacingBefore(5f);
                    t.setWidthPercentage(66f);
                    t.setWidths(new float[] { 0.33f, 0.66f });

                    c = newCell("ID");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                    t.addCell(c);

                    String type = "";
                    if (f.isAction()) {
                        type = "Action list";
                    } else if (f.isInBucket()) {
                        type = "In-Bucket";
                    } else if (f.isQueue()) {
                        type = "Next action queue";
                    } else if (f.isReference()) {
                        type = "Reference list";
                    } else if (f.isSomeday()) {
                        type = "Someday/Maybe list";
                    } else if (f.isBuildIn()) {
                        type = "Default list";
                    }

                    c = newCell("Type");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(type));
                    t.addCell(c);
                    c = newCell("Open");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                    t.addCell(c);
                    c = newCell("All");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.size())));
                    t.addCell(c);
                    c = newCell("Description");
                    t.addCell(c);
                    c = newDescriptionCell(f.getDescription());
                    t.addCell(c);

                    doc.add(t);
                }

                emptyH2 = true;
                emptyH3 = false;

            } else {

                if (emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSubSection("List:" + " " + f.getName()));

                emptyH2 = false;
                emptyH3 = true;

            }

            continue;

        }

        if (o instanceof Action) {
            emptyH2 = false;
            emptyH3 = false;

            Action a = (Action) o;

            if (compact) {

                if (actionTable == null) {
                    actionTable = new PdfPTable(5);
                    actionTable.setWidthPercentage(100f);
                    actionTable.setHeaderRows(1);
                    actionTable.setSpacingBefore(5f);
                    c = newHeaderCell("ID");
                    actionTable.addCell(c);
                    c = newHeaderCell("Pri.");
                    actionTable.addCell(c);
                    c = newHeaderCell("Description");
                    actionTable.addCell(c);
                    c = newHeaderCell("Reminder");
                    actionTable.addCell(c);
                    c = newHeaderCell(CHECK_RESOLVED);
                    actionTable.addCell(c);

                    float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft()
                            - doc.getPageSize().getBorderWidthRight();
                    int i = model.getLastActionID();
                    float step = baseFontSize - 1;
                    int steps = (int) Math.floor(Math.log10(i)) + 1;
                    // ID column
                    float col1 = 8 + steps * step;
                    // Priority column
                    float col2 = 4 + 3 * (baseFontSize + 4);
                    // Reminder column
                    float col4 = 10 + step * 11;
                    // Resolved column
                    float col5 = 8 + baseFontSize;
                    // Description column
                    float col3 = width - col1 - col2 - col4 - col5;
                    actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 });

                }

                addSingleActionRow(a, actionTable);

            } else {
                addSingleActionTable(model, doc, a);
            }
        }

    }

    if (actionTable != null) {
        doc.add(actionTable);
        actionTable = null;
    }
    if (emptyH2 || emptyH3) {

        p = newParagraph(NONE_DOT);
        doc.add(p);
    }

    //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date()));

    doc.close();
}

From source file:org.pz.platypus.plugin.pdf.commands.PdfBulletListPlainStartWithOptions.java

License:Open Source License

/**
 * Look up the symbol in the symbol table and get the Unicode value and any symbol font info.
 * //ww  w .  j a  v a  2 s.c o m
 * @param param value passed with the "bullet:" parameter
 * @param pdd the PDF document data
 * @param tok the token for the whole bullet list command
 * @return Chunk containing for the bullet symbol
 */
Chunk lookupBulletSymbol(final String param, final Token tok, final PdfData pdd) {
    assert (pdd != null);
    assert (tok != null);
    assert (param != null);

    GDD gdd = pdd.getGdd();

    StringBuilder sb = new StringBuilder(10);
    int i = 0;
    while (i < param.length() && param.charAt(i) != '}' && param.charAt(i) != ']')
        sb.append(param.charAt(i++));

    if (param.charAt(i) != '}') {
        errorUnclosedOption(gdd, tok);
        return (new Chunk(DefaultValues.BULLET));
    }

    String root = "[" + sb.toString() + "]";
    ICommand value = gdd.getCommandTable().getCommand(root);
    if (!(value instanceof Symbol)) {
        errorBulletSymbolNotFound(gdd, tok);
    }

    // get the entry for this symbol. Should be a string that specifies the char value
    // as a Unicode value, with an optional font name.
    PdfSymbol processor = (PdfSymbol) pdd.getCommandTable().getCommand(root);
    String symEquivalent = processor.getSymEquivalent();

    // get the Unicode value and font name, if any
    String font = processor.getFontName(symEquivalent, gdd, tok);
    String sym = processor.getCharCode(symEquivalent);

    if (font == null || font.isEmpty()) {
        return (new Chunk(sym));
    } else {
        PdfFont newFont = new PdfFont(pdd, font, pdd.getFont());
        FontSelector fs = new FontSelector();
        fs.addFont(newFont.getItextFont());
        Chunk chk = new Chunk(sym, newFont.getItextFont());
        return (chk);
    }
}

From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java

License:Open Source License

/**
 * Emit a single character in the current font, size, etc. This is used to output
 * a character by its Unicode value and is called by PdfSymbol, which handles the
 * processing of symbols and special characters.
 *
 * @param ch char to be emitted/*from   w  w w . j a  v a2  s .  co  m*/
 * @param fontName fontName to use. If null, use current font.
 */
public void emitChar(final String ch, final String fontName) {
    assert (ch != null) : "ch parameter null in PdfOutfile.emitChar()";

    if (iTPara == null) {
        startNewParagraph();
    }

    FontSelector fs = new FontSelector();
    if (fontName == null || fontName.isEmpty()) {
        fs.addFont(pdfData.getFont().getItextFont());
    } else {
        PdfFont newFont = new PdfFont(pdfData, fontName, pdfData.getFont());
        fs.addFont(newFont.getItextFont());
    }

    Phrase phr = fs.process(ch);
    iTPara.add(phr);
}