List of usage examples for com.itextpdf.text FontFactory getRegisteredFonts
public static Set<String> getRegisteredFonts()
From source file:com.dandymadeproductions.ajqvue.structures.DataExportProperties.java
License:Open Source License
private void loadPDFFonts() { // Method Instances. String fileSeparator;/*from w w w . j a v a 2s. c o m*/ String fontPath, fontName; String fontsDirectoryName; Iterator<String> fontNameIterator; File fontsDirectory; File[] fontsSubDirectories; String[] fontNames; TreeSet<String> fonts; // Setting up. fileSeparator = Utils.getFileSeparator(); fontsDirectoryName = "fonts" + fileSeparator; fonts = new TreeSet<String>(); // Insure have one default font. fontTreeMap.put(PDFExportPreferencesPanel.DEFAULT_FONT, new Font(Font.FontFamily.UNDEFINED)); // Create the default registered fonts. fontNameIterator = FontFactory.getRegisteredFonts().iterator(); while (fontNameIterator.hasNext()) { fontName = fontNameIterator.next(); fontTreeMap.put(fontName, FontFactory.getFont(fontName)); } // Create embedded fonts from fonts directory. fontsDirectory = new File(fontsDirectoryName); if (fontsDirectory.exists()) { // Handle one level of sub-directories. fontsSubDirectories = fontsDirectory.listFiles(new DirectoriesFilter()); if (fontsSubDirectories != null) { for (int i = 0; i < fontsSubDirectories.length; i++) { fontNames = fontsSubDirectories[i].list(new FontNameFilter()); if (fontNames != null) for (int j = 0; j < fontNames.length; j++) fonts.add(fontsSubDirectories[i] + fileSeparator + fontNames[j]); } } // Handle all direct font names in the directory. fontNames = fontsDirectory.list(new FontNameFilter()); if (fontNames != null) { for (int i = 0; i < fontNames.length; i++) fonts.add(fontsDirectoryName + fontNames[i]); } // Load the found fonts. fontNameIterator = fonts.iterator(); while (fontNameIterator.hasNext()) { fontPath = fontNameIterator.next(); if (fontPath.indexOf(fileSeparator) != -1) fontName = fontPath.substring((fontPath.lastIndexOf(fileSeparator) + 1), fontPath.indexOf(".")); else fontName = fontPath.substring(0, fontPath.indexOf(".")); // System.out.println(fontName + " " + fontPath); try { BaseFont currentBaseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); fontTreeMap.put(fontName, new Font(currentBaseFont, 12)); } catch (DocumentException de) { } catch (IOException ioe) { } } } }
From source file:com.dandymadeproductions.myjsqlview.structures.DataExportProperties.java
License:Open Source License
private void loadPDFFonts() { // Method Instances. String fileSeparator;/*from w ww. j av a2s .c o m*/ String fontPath, fontName; String fontsDirectoryName; Iterator<String> fontNameIterator; File fontsDirectory; File[] fontsSubDirectories; String[] fontNames; TreeSet<String> fonts; // Setting up. fileSeparator = MyJSQLView_Utils.getFileSeparator(); fontsDirectoryName = "fonts" + fileSeparator; fonts = new TreeSet<String>(); // Insure have one default font. fontTreeMap.put(PDFExportPreferencesPanel.DEFAULT_FONT, new Font(Font.FontFamily.UNDEFINED)); // Create the default registered fonts. fontNameIterator = FontFactory.getRegisteredFonts().iterator(); while (fontNameIterator.hasNext()) { fontName = fontNameIterator.next(); fontTreeMap.put(fontName, FontFactory.getFont(fontName)); } // Create embedded fonts from fonts directory. fontsDirectory = new File(fontsDirectoryName); if (fontsDirectory.exists()) { // Handle one level of sub-directories. fontsSubDirectories = fontsDirectory.listFiles(directoriesFilter); for (int i = 0; i < fontsSubDirectories.length; i++) { fontNames = fontsSubDirectories[i].list(fontNameFilter); for (int j = 0; j < fontNames.length; j++) fonts.add(fontsSubDirectories[i] + fileSeparator + fontNames[j]); } // Handle all direct font names in the directory. fontNames = fontsDirectory.list(fontNameFilter); for (int i = 0; i < fontNames.length; i++) fonts.add(fontsDirectoryName + fontNames[i]); // Load the found fonts. fontNameIterator = fonts.iterator(); while (fontNameIterator.hasNext()) { fontPath = fontNameIterator.next(); if (fontPath.indexOf(fileSeparator) != -1) fontName = fontPath.substring((fontPath.lastIndexOf(fileSeparator) + 1), fontPath.indexOf(".")); else fontName = fontPath.substring(0, fontPath.indexOf(".")); // System.out.println(fontName + " " + fontPath); try { BaseFont currentBaseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); fontTreeMap.put(fontName, new Font(currentBaseFont, 12)); } catch (DocumentException de) { } catch (IOException ioe) { } } } }
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
/** * This method will append to the pdf a legend explaining the visual feedback in the pdf, an overview of the styles * used and an overview of the properties used. * * @throws DocumentException/* w ww. ja va2 s .c om*/ */ public static void appendDebugInfo(PdfWriter writer, Document document, EnhancedMap settings, StylerFactory stylerFactory) throws DocumentException, VectorPrintException { PdfContentByte canvas = writer.getDirectContent(); canvas.setFontAndSize(FontFactory.getFont(FontFactory.COURIER).getBaseFont(), 8); canvas.setColorFill( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); canvas.setColorStroke( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); Font f = FontFactory.getFont(FontFactory.COURIER, 8); f.setColor(itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); float top = document.getPageSize().getTop(); document.add(new Phrase(new Chunk("table: ", f).setLocalDestination(DEBUGPAGE))); document.add(Chunk.NEWLINE); document.add(new Phrase("cell: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("image: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("text: ", f)); document.add(Chunk.NEWLINE); document.add(new Phrase("background color is shown in a small rectangle", f)); document.add(Chunk.NEWLINE); canvas.setLineWidth(2); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); float left = document.leftMargin(); canvas.rectangle(left + 80, top - 25, left + 80, 8); canvas.closePathStroke(); canvas.setLineWidth(0.3f); canvas.setLineDash(new float[] { 2, 2 }, 0); canvas.rectangle(left + 80, top - 37, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 1, 0 }, 0); canvas.rectangle(left + 80, top - 50, left + 80, 8); canvas.closePathStroke(); canvas.setLineDash(new float[] { 0.3f, 5 }, 0); canvas.rectangle(left + 80, top - 63, left + 80, 8); canvas.closePathStroke(); document.add(Chunk.NEWLINE); document.add(new Phrase("fonts available: " + FontFactory.getRegisteredFonts(), f)); document.add(Chunk.NEWLINE); if (settings.getBooleanProperty(false, DEBUG)) { document.add(new Phrase("OVERVIEW OF STYLES FOR THIS REPORT", f)); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } Font b = new Font(f); b.setStyle("bold"); Set<Map.Entry<String, String>> entrySet = stylerFactory.getStylerSetup().entrySet(); for (Map.Entry<String, String> styleInfo : entrySet) { String key = styleInfo.getKey(); document.add(new Chunk(key, b).setLocalDestination(key)); document.add(new Chunk(": " + styleInfo.getValue(), f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" styling configured by " + key + ": ", f)); for (BaseStyler st : (Collection<BaseStyler>) stylerFactory.getBaseStylersFromCache((key))) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add(new Chunk(st.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(st.getClass().getSimpleName())); document.add(new Chunk(":", f)); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + st.getClass().getSimpleName() + ": " + getParamInfo(st), f)); document.add(Chunk.NEWLINE); if (!st.getConditions().isEmpty()) { document.add(new Phrase(" conditions for this styler: ", f)); } for (StylingCondition sc : (Collection<StylingCondition>) st.getConditions()) { document.add(Chunk.NEWLINE); document.add(new Chunk(" ", f)); document.add( new Chunk(sc.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings)) .setLocalGoto(sc.getClass().getSimpleName())); document.add(Chunk.NEWLINE); document.add(new Phrase(" non default parameters for " + sc.getClass().getSimpleName() + ": " + getParamInfo(sc), f)); } } document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } document.newPage(); document.add(new Phrase("Properties used for the report", f)); document.add(Chunk.NEWLINE); ByteArrayOutputStream bo = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bo); settings.listProperties(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); document.newPage(); try { bo = new ByteArrayOutputStream(); ps = new PrintStream(bo); Help.printHelpHeader(ps); ps.close(); document.add(new Paragraph(bo.toString(), f)); Help.printStylerHelp(document, f); Help.printConditionrHelp(document, f); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { log.log(Level.SEVERE, null, ex); } }
From source file:com.vectorprint.report.itext.style.stylers.DocumentSettings.java
License:Open Source License
/** * If your settings contain a key {@link #FONTS} it is assumed to be a list of directory names where fonts are loaded * from./*ww w . j a va 2 s. com*/ * * @see EnhancedMap#getStringProperties(java.lang.String..., java.lang.String...) * @see FontFactory#registerDirectory(java.lang.String) * @throws VectorPrintException */ @Override public void loadFonts() throws VectorPrintException { if (getSettings().containsKey(FONTS)) { if (getValue(PDFA, Boolean.class)) { FontFactory.defaultEmbedding = true; } log.info("loading fonts from " + Arrays.asList(getSettings().getStringProperties(null, FONTS))); for (String dir : getSettings().getStringProperties(null, FONTS)) { int i = FontFactory.registerDirectory(dir); log.fine(String.format("%s fonts loaded from %s", i, dir)); } log.info("fonts available: " + FontFactory.getRegisteredFonts()); } else { log.warning(String.format("setting \"%s\" for font directory not found, not loading fonts", FONTS)); } }
From source file:org.javad.pdf.fonts.FontRegistry.java
License:Apache License
public void initializeFonts() { if (!registered) { String path = getFontPath(); if (path != null) { FontFactory.registerDirectory(path, true); if (logger.isLoggable(Level.FINEST)) { logger.finest(FontFactory.getRegisteredFonts().toString()); }//from w w w.j a v a 2s . c om } registered = true; } }