List of usage examples for com.lowagie.text.pdf BaseFont IDENTITY_H
String IDENTITY_H
To view the source code for com.lowagie.text.pdf BaseFont IDENTITY_H.
Click Source Link
From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java
License:Apache License
public BaseFont awtToPdf(String fontName) { try {// w w w. j ava 2 s . c o m BaseFontParameters p = getBaseFontParameters(fontName); if (p != null) { return BaseFont.createFont(p.fontName, BaseFont.IDENTITY_H, p.embedded, p.cached, p.ttfAfm, p.pfb); } } catch (DocumentException | IOException e) { throw new ExceptionConverter(e); } return null; }
From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java
License:Apache License
public int insertDirectory(String dir) { File file = new File(dir); if (!file.exists() || !file.isDirectory()) return 0; File files[] = file.listFiles(); if (files == null) return 0; int count = 0; for (File file1 : files) { file = file1;//from ww w. java 2 s. co m if (file.isDirectory()) { count += insertDirectory(file.getPath()); } else { String name = file.getPath().toLowerCase(); try { if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) { Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.IDENTITY_H, null); insertNames(allNames, file.getPath()); ++count; } else if (name.endsWith(".ttc")) { String ttcs[] = BaseFont.enumerateTTCNames(file.getPath()); for (int j = 0; j < ttcs.length; ++j) { String nt = file.getPath() + "," + j; Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.IDENTITY_H, null); insertNames(allNames, nt); } ++count; } } catch (Exception ignored) { } } } return count; }
From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java
License:Apache License
private BaseFont getDefaultBaseFont() throws DocumentException, IOException { if (getDefaultFont() != null) { return BaseFont.createFont(getDefaultFont(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); }//from w w w.j a v a2 s .c o m return null; }
From source file:jmemorize.core.io.PdfRtfBuilder.java
License:Open Source License
private static void export(Lesson lesson, int mode, File file) throws IOException { logger = Main.getLogger();//from w ww. j a v a 2s . com FontFactory.registerDirectories(); // set up the fonts we will use to write the front and back of cards String frontFontName = Settings.loadFont(FontType.CARD_FRONT).getFont().getFamily(); frontFont = FontFactory.getFont(frontFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (frontFont == null) { logger.warning("FontFactory returned null (front) font for: " + frontFontName); } String backFontName = Settings.loadFont(FontType.CARD_FLIP).getFont().getFamily(); backFont = FontFactory.getFont(backFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (backFont == null) { logger.warning("FontFactory returned null (back) font for: " + backFontName); } try { Document doc = new Document(); OutputStream out = new FileOutputStream(file); switch (mode) { case PDF_MODE: PdfWriter.getInstance(doc, out); break; case RTF_MODE: RtfWriter2.getInstance(doc, out); break; } doc.setHeader(new HeaderFooter(new Phrase(file.getName()), false)); doc.open(); // add cards in subtrees List<Category> subtree = lesson.getRootCategory().getSubtreeList(); for (Category category : subtree) { writeCategory(doc, category); } doc.close(); } catch (Throwable t) { throw (IOException) new IOException("Could not export to PDF").initCause(t); } }
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[] {}; }/* w w w. java 2 s . co 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); } } }
From source file:net.dervism.FlyingSaucerDemo.java
License:LGPL
/** * This tool uses a customizable XHTML template that supports the CSS 2.1 specification. * * Included with this project is two fonts supporting a large set of the UNICODE charset, * meaning that you can use HTML entities like ☑ (checked checkbox special character ). * With UNICODE support you can easily create PDF's with complex symbols for math, currency, * geometry and many more. See this page for the full list of UNICODE characters available: * http://www.utf8-chartable.de/unicode-utf8-table.pl * * Fonts://from w w w. j av a 2 s . com * Source Sans Pro (SIL Open Font License (OFL), open source, free for personal and commercial use) * Source Sans Pro, Adobe's first open source typeface family, was designed by Paul D. Hunt. It is a * sans serif typeface intended to work well in user interfaces. * * DejaVu Sans, Freeware, (free for personal and commercial use) * * Font are downloaded from fontspace.com: * http://www.fontspace.com/category/unicode * * This tool is built on Flying Saucer 9.0.4 (GNU LGPL license) and IText 2.1.7 (dual licensed * under MPL/LGPL) frameworks. The template is CSS-paged XHTML * * @param templatepath * @param params * @return * @throws DocumentException * @throws IOException * @throws URISyntaxException */ public byte[] toPdf(String templatepath, Map<String, String> params) throws DocumentException, IOException, URISyntaxException { InputStream resourceAsStream = this.getClass().getResourceAsStream(templatepath); String template = IOUtils.toString(resourceAsStream); // collect the generated data in a buffer ByteArrayOutputStream os = new ByteArrayOutputStream(); if (template != null) { // customs params to be replaced for (String param : params.keySet()) { String replacewith = params.get(param); template = template.replaceFirst(param, safestring(replacewith)); } Calendar today = Calendar.getInstance(); SimpleDateFormat shortDate = new SimpleDateFormat("dd-MM-yyyy"); // extra utiliy tags that can be used in the template template = template.replaceAll("#shortdate", "" + shortDate.format(today.getTime())); template = template.replaceAll("#pagebreak", TemplateUtils.getPageBreak()); // choose which font to use template = template.replaceAll("#fontfamily", TemplateUtils.UNICODE_TRUETYPE_SOURCE_SANS_PRO); // example unicode characters for rendering two 'ballot box' characters template = template.replaceAll("#checked", "☑"); template = template.replaceAll("#unchecked", "☐"); // prepare the 'Flying Saucer' and IText frameworks ITextRenderer render = new ITextRenderer(); // we need a font resolver for loading our custom fonts ITextFontResolver resolver = render.getFontResolver(); // unicode truetype font supporting 655 characters resolver.addFont(this.getClass().getResource("/fonts/SourceSansPro-Regular.ttf").getPath(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // unicode truetype font supporting 5572 characters // this font supports almost all the special characters ranging // from U+25A0 to U+25FF ("Geometric Shapes") resolver.addFont(this.getClass().getResource("/fonts/DejaVuSans.ttf").getPath(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // insert the template with replaced values render.setDocumentFromString(template); // render XHTML and CSS 2.1 render.layout(); // create the final PDF render.createPDF(os); } // return the generated bytes return os.toByteArray(); }
From source file:net.sf.jsignpdf.utils.FontUtils.java
License:Mozilla Public License
/** * Returns BaseFont for text of visible signature; * /*from w ww.j av a 2 s . c o m*/ * @return */ public static synchronized BaseFont getL2BaseFont() { if (l2baseFont == null) { final ConfigProvider conf = ConfigProvider.getInstance(); try { final ByteArrayOutputStream tmpBaos = new ByteArrayOutputStream(); String fontPath = conf.getNotEmptyProperty("font.path", null); String fontName; String fontEncoding; InputStream tmpIs; if (fontPath != null) { fontName = conf.getNotEmptyProperty("font.name", null); if (fontName == null) { fontName = new File(fontPath).getName(); } fontEncoding = conf.getNotEmptyProperty("font.encoding", null); if (fontEncoding == null) { fontEncoding = BaseFont.WINANSI; } tmpIs = new FileInputStream(fontPath); } else { fontName = Constants.L2TEXT_FONT_NAME; fontEncoding = BaseFont.IDENTITY_H; tmpIs = FontUtils.class.getResourceAsStream(Constants.L2TEXT_FONT_PATH); } IOUtils.copy(tmpIs, tmpBaos); tmpIs.close(); tmpBaos.close(); l2baseFont = BaseFont.createFont(fontName, fontEncoding, BaseFont.EMBEDDED, BaseFont.CACHED, tmpBaos.toByteArray(), null); } catch (Exception e) { e.printStackTrace(); try { l2baseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception ex) { // where is the problem, dear Watson? } } } return l2baseFont; }
From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java
License:Open Source License
static private Map<FontKey, PdfFont> createFontMap() { final Map<FontKey, PdfFont> result = new HashMap<FontKey, PdfFont>(4); addFont(result, "Quadraat-Regular", "QUAD____.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Bold", "QUADBD__.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Italic", "QUADI___.ttf", BaseFont.CP1252); addFont(result, "Quadraat-BoldItalic", "QUADBDI_.ttf", BaseFont.CP1252); addFont(result, "Arial", "Arial.ttf", BaseFont.CP1252); addFont(result, "Arial Black", "Arial_Black.ttf", BaseFont.CP1252); addFont(result, "Lucida Handwriting", "LucidaHandwriting.ttf", BaseFont.CP1252); addFont(result, "Garamond", "AdobeGaramondPro.ttf", BaseFont.CP1252); addFont(result, "Garamond Bold", "AdobeGaramondBold.ttf", BaseFont.CP1252); addFont(result, "Arial Unicode MS", "arialuni.ttf", BaseFont.IDENTITY_H); addFont(result, "DejaVu Serif Bold", "DejaVuSerif-Bold.ttf", BaseFont.IDENTITY_H); addFont(result, "Times New Roman", "tnr.ttf", BaseFont.CP1252); return result; }
From source file:org.eclipse.birt.report.engine.layout.pdf.font.FontMappingManagerFactory.java
License:Open Source License
/** * Creates iText BaseFont with the given font family name. * //from w w w.jav a 2 s . c o m * @param ffn * the specified font family name. * @return the created BaseFont. */ public BaseFont createFont(String familyName, int fontStyle) { String key = familyName + fontStyle; BaseFont bf = null; synchronized (baseFonts) { if (baseFonts.containsKey(key)) { bf = (BaseFont) baseFonts.get(key); } else { try { String fontEncoding = (String) fontEncodings.get(familyName); if (fontEncoding == null) { fontEncoding = BaseFont.IDENTITY_H; } bf = FontFactory.getFont(familyName, fontEncoding, BaseFont.EMBEDDED, 14, fontStyle) .getBaseFont(); } catch (Throwable de) { logger.log(Level.WARNING, de.getMessage(), de); } baseFonts.put(key, bf); } if (bf == null && fontStyle != Font.NORMAL) { return createFont(familyName, Font.NORMAL); } } return bf; }
From source file:org.onehippo.forge.hst.pdf.renderer.HtmlPDFRenderer.java
License:Open Source License
public void renderHtmlToPDF(Reader htmlInput, boolean convertToXHTML, OutputStream pdfOutput, String documentURL, String externalLinkBaseURL) throws IOException { Reader xhtmlReader = null;//from w ww . j a v a2 s . co m try { if (convertToXHTML) { xhtmlReader = convertHtmlReaderToXhtmlReader(htmlInput); } else { xhtmlReader = htmlInput; } ITextRenderer renderer = new ITextRenderer(); if (fontPaths != null && fontPaths.length > 0) { ITextFontResolver fontResolver = renderer.getFontResolver(); for (String fontPath : fontPaths) { fontResolver.addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } } DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(new InputSource(xhtmlReader)); if (removeExistingCssLinks) { removeExistingCssLinks(document); } if (cssURIs != null && cssURIs.length > 0) { appendCssLinkElementToXhtmlDocument(document, cssURIs); } if (useFullyQualifiedLinks && !StringUtils.isEmpty(externalLinkBaseURL)) { replaceLinksByFullyQualifiedURLs(document, "a", externalLinkBaseURL, documentURL); replaceLinksByFullyQualifiedURLs(document, "A", externalLinkBaseURL, documentURL); } if (userAgentCallback != null) { renderer.getSharedContext().setUserAgentCallback(userAgentCallback); } renderer.setDocument(document, documentURL); renderer.layout(); renderer.createPDF(pdfOutput); } catch (ParserConfigurationException e) { log.error("Parse configuration exception.", e); } catch (SAXException e) { log.error("XML parsing exception.", e); } catch (DocumentException e) { log.error("pdf generation exception.", e); } finally { if (xhtmlReader != htmlInput) { IOUtils.closeQuietly(xhtmlReader); } } }