public static void embedFonts(ITextRenderer renderer) { final PropertySet propertySet = Properties.instance().getPropertySet(); for (final String propertyName : propertySet.getPropertiesStartsWith("oxf.fr.pdf.font.path")) { final String path = StringUtils.trimToNull(propertySet.getString(propertyName)); if (path != null) { try { // Overriding the font family is optional final String family; { final String[] tokens = StringUtils.split(propertyName, '.'); if (tokens.length >= 6) { final String id = tokens[5]; family = StringUtils.trimToNull( propertySet.getString("oxf.fr.pdf.font.family" + '.' + id)); } else { family = null; } } // Add the font renderer .getFontResolver() .addFont(path, family, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null); } catch (Exception e) { logger.warn( "Failed to load font by path: '" + path + "' specified with property '" + propertyName + "'"); } } } }
private void createPdfStream( final String content, final String baseUrl, final OutputStream outputStream) throws DocumentException, IOException, URISyntaxException { ITextRenderer renderer = new ITextRenderer(); // for unicode renderer.getFontResolver().addFont(FONT_FILE_PATH, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.setDocumentFromString(content, baseUrl); renderer.layout(); renderer.createPDF(outputStream); }