List of usage examples for com.lowagie.text FontFactory getRegisteredFamilies
public static Set getRegisteredFamilies()
From source file:com.amphisoft.epub2pdf.content.TextFactory.java
License:Open Source License
public static Set<String> getFontFamilies() { Set<String> fams = new HashSet<String>(); for (Object o : FontFactory.getRegisteredFamilies()) { fams.add(o.toString());/*from w w w . j ava 2 s. c om*/ } return fams; }
From source file:com.gtdfree.test.PDFTestFont.java
License:Open Source License
/** * Fonts and encoding./* www .j a v a2 s . com*/ * @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:org.pz.platypus.plugin.pdf.PdfFontFactory.java
License:Open Source License
/** * This test whether a font is registered by name or by family name in iText. Either way is * good enough for our purposes./* w w w .ja v a 2s . c o m*/ * * @param fontName the font we're checking * @return true if iText has the font registered by name or by family name, false otherwise. */ boolean isRegisteredWithItext(final String fontName) { assert (fontName != null); if (FontFactory.isRegistered(fontName)) { return (true); } Set<String> regFamilies = (Set<String>) FontFactory.getRegisteredFamilies(); if (regFamilies.contains(fontName.toLowerCase())) { return (true); } return (false); }
From source file:org.squale.welcom.outils.pdf.PDFFontUtil.java
License:Open Source License
/** * Initolisation du repertoire de font pour l'impression * /*from w w w. ja va 2 s. c om*/ * @param s Action Servlet pour la fonc * @return True si TVB */ public static boolean init(final ActionServlet s) { pdfFontUtil = new PDFFontUtil(s); boolean resultSR = true; boolean resultIT = true; /* * TODO FAB : XReport doit tre sorti car il s'agit d'une lib non OSS try { * Class.forName("inetsoft.report.ReportEnv"); inetsoft.report.ReportEnv.setProperty("font.metrics.source", * "truetype"); inetsoft.report.ReportEnv.setProperty("font.truetype.path", * PDFFontUtil.getRealFontPath().trim()); resultSR = true; } catch (final ClassNotFoundException e) { resultSR = * false; } */ try { Class.forName("com.lowagie.text.Document"); final String path = PDFFontUtil.getRealFontPath().trim(); final File fontDir = new File(path); final File[] listFile = fontDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".ttf"); } }); if (listFile != null) { for (int i = 0; i < listFile.length; i++) { FontFactory.register(listFile[i].getCanonicalPath()); } if (logger.isDebugEnabled()) { for (final Iterator iter = FontFactory.getRegisteredFamilies().iterator(); iter.hasNext();) { final String font = (String) iter.next(); logger.debug("registering " + font); } } } resultIT = true; } catch (final ClassNotFoundException e) { if (logger.isDebugEnabled()) { logger.debug("Erreur lors du chargement des fonts pour itext", e); } resultIT = false; } catch (final IOException ie) { if (logger.isDebugEnabled()) { logger.debug("Erreur lors du chargement des fonts pour itext", ie); } resultIT = false; } return resultSR || resultIT; }