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:com.openkm.util.PDFUtils.java
License:Open Source License
/** * Obtain base font for PDF processing/* w w w . ja v a 2 s . c o m*/ */ private static BaseFont getBaseFont() throws DocumentException, IOException { String fontName = Config.HOME_DIR + "/lib/unicode.ttf"; String fontEncoding = BaseFont.IDENTITY_H; if (!new File(fontName).exists()) { log.warn("Unicode TTF font not found: {}", fontName); fontName = BaseFont.HELVETICA; fontEncoding = BaseFont.WINANSI; } return BaseFont.createFont(fontName, fontEncoding, BaseFont.EMBEDDED); }
From source file:com.qcadoo.report.api.FontUtils.java
License:Open Source License
/** * Prepare fonts.//from w w w .jav a 2 s. c o m * * @throws DocumentException * @throws IOException */ public static synchronized void prepare() throws DocumentException, IOException { if (dejavuBold10Dark == null) { if (LOG.isDebugEnabled()) { LOG.debug("Pdf fonts initialization"); } try { FontFactory.register("/fonts/dejaVu/DejaVuSans.ttf"); dejavu = BaseFont.createFont("/fonts/dejaVu/DejaVuSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (ExceptionConverter e) { LOG.warn("Font not found, using embedded font helvetica"); dejavu = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } dejavuBold70Light = new Font(dejavu, 70); dejavuBold70Light.setStyle(Font.BOLD); dejavuBold70Light.setColor(ColorUtils.getLightColor()); dejavuBold70Dark = new Font(dejavu, 70); dejavuBold70Dark.setStyle(Font.BOLD); dejavuBold70Dark.setColor(ColorUtils.getDarkColor()); dejavuBold19Light = new Font(dejavu, 19); dejavuBold19Light.setStyle(Font.BOLD); dejavuBold19Light.setColor(ColorUtils.getLightColor()); dejavuBold19Dark = new Font(dejavu, 19); dejavuBold19Dark.setStyle(Font.BOLD); dejavuBold19Dark.setColor(ColorUtils.getDarkColor()); dejavuBold14Dark = new Font(dejavu, 14); dejavuBold14Dark.setStyle(Font.BOLD); dejavuBold14Dark.setColor(ColorUtils.getDarkColor()); dejavuBold17Light = new Font(dejavu, 17); dejavuBold17Light.setStyle(Font.BOLD); dejavuBold17Light.setColor(ColorUtils.getLightColor()); dejavuBold14Light = new Font(dejavu, 17); dejavuBold14Light.setStyle(Font.BOLD); dejavuBold14Light.setColor(ColorUtils.getLightColor()); dejavuBold17Dark = new Font(dejavu, 17); dejavuBold17Dark.setStyle(Font.BOLD); dejavuBold17Dark.setColor(ColorUtils.getDarkColor()); dejavuRegular9Light = new Font(dejavu, 9); dejavuRegular9Light.setColor(ColorUtils.getLightColor()); dejavuRegular9Dark = new Font(dejavu, 9); dejavuRegular9Dark.setColor(ColorUtils.getDarkColor()); dejavuRegular7Dark = new Font(dejavu, 7); dejavuRegular7Dark.setColor(ColorUtils.getDarkColor()); dejavuBold9Dark = new Font(dejavu, 9); dejavuBold9Dark.setColor(ColorUtils.getDarkColor()); dejavuBold9Dark.setStyle(Font.BOLD); dejavuBold11Dark = new Font(dejavu, 11); dejavuBold11Dark.setColor(ColorUtils.getDarkColor()); dejavuBold11Dark.setStyle(Font.BOLD); dejavuBold11Light = new Font(dejavu, 11); dejavuBold11Light.setColor(ColorUtils.getLightColor()); dejavuBold11Light.setStyle(Font.BOLD); dejavuRegular10Dark = new Font(dejavu, 10); dejavuRegular10Dark.setColor(ColorUtils.getDarkColor()); dejavuBold10Dark = new Font(dejavu, 10); dejavuBold10Dark.setColor(ColorUtils.getDarkColor()); dejavuBold10Dark.setStyle(Font.BOLD); dejavuRegular7Light = new Font(dejavu, 7); dejavuRegular7Light.setColor(ColorUtils.getLightColor()); dejavuBold7Dark = new Font(dejavu, 7); dejavuBold7Dark.setColor(ColorUtils.getDarkColor()); dejavuBold7Dark.setStyle(Font.BOLD); dejavuBold8Dark = new Font(dejavu, 8); dejavuBold8Dark.setColor(ColorUtils.getDarkColor()); dejavuBold8Dark.setStyle(Font.BOLD); } }
From source file:com.qubit.terra.docs.util.FontManager.java
License:Open Source License
protected FontEntry createFontEntry(File ttfFile) throws FontFormatException, IOException, FileNotFoundException, DocumentException { InputStream is = null;/* w ww . ja v a 2 s . c om*/ try { is = new FileInputStream(ttfFile); byte[] fontData = RandomAccessFileOrArray.InputStreamToArray(is); BaseFont baseFont = BaseFont.createFont(ttfFile.getName(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, false, fontData, null); FontEntry fontEntry = new FontEntry(ttfFile.getName(), baseFont); return fontEntry; } finally { if (is != null) { is.close(); } } }
From source file:com.vinhteam.flyingsaucer.cli.Main.java
public static void htmlToPdf(String html, String pdfFile) { try {// w w w . j a va2 s . c o m OutputStream pdfOut = new FileOutputStream(pdfFile); ITextRenderer renderer = new ITextRenderer(); ITextFontResolver resolver = renderer.getFontResolver(); Main main = new Main(); File fontFile = main.getFileFont(); try { resolver.addFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } catch (Exception ex) { ex.printStackTrace(); } renderer.setDocumentFromString(html); renderer.layout(); renderer.createPDF(pdfOut); pdfOut.close(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:controllers.PdfGenerator.java
public void toStream(String string, OutputStream os, String documentBaseURL, List<String> fonts) { try {//from w w w .j a v a 2s.c om InputStream input = new ByteArrayInputStream(string.getBytes("UTF-8")); ITextRenderer renderer = new ITextRenderer(); if (fonts != null) for (String font : fonts) { renderer.getFontResolver().addFont(font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } PdfUserAgent myUserAgent = new PdfUserAgent(renderer.getOutputDevice()); myUserAgent.setSharedContext(renderer.getSharedContext()); renderer.getSharedContext().setUserAgentCallback(myUserAgent); Document document = new HtmlDocumentBuilder().parse(input); renderer.setDocument(document, documentBaseURL); renderer.layout(); renderer.createPDF(os); } catch (Exception e) { Logger.error("Error creating document from template", e); } }
From source file:de.thorstenberger.taskmodel.view.webapp.filter.ExportPDFFilter.java
License:Open Source License
/** * Render the given xhtml document as pdf and write it to the response outputstream. * * @param dom/*from w ww . j ava2 s . c o m*/ * xhtml document * @param request * @param response * @throws IOException * if the document could not get renderered */ private void renderPdf(final Document dom, final HttpServletRequest request, final ServletResponse response) throws IOException { final ITextRenderer renderer = new ITextRenderer(80 / 3f, 15); if (fontPath != null) { try { log.debug("Using unicode font at path " + fontPath); renderer.getFontResolver().addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e1) { e1.printStackTrace(); } } renderer.setDocument(dom, getLocalURL(request)); renderer.layout(); response.setContentType("application/pdf"); // set an appropriate filename ((HttpServletResponse) response).setHeader("Content-Disposition", "attachment; filename=" + request.getParameter(EXPORTFILENAME)); try { renderer.createPDF(response.getOutputStream()); } catch (final DocumentException e) { log.error("Could not render pdf.", e); // FIXME should we just return the original content? throw new IOException(e.getMessage()); } }
From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFTitlePage.java
License:Apache License
/************************************************************************************ * get font as {@link Font} from given font name and size * /*from w ww . j av a 2 s . c o m*/ * @param fontname name of font * @param fontsize size of font * * @throws PDFManagerException ************************************************************************************/ private Font getPDFFont(int fontsize) throws PDFManagerException { Font resultfont = null; // set the base font try { if (this.ttffontpath == null) { // don't use TTF LOGGER.debug("Do not use TrueType Font... instead standard Arial is used"); resultfont = FontFactory.getFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, fontsize); // String[] codePages = basefont.getCodePagesSupported(); // System.out.println("All available encodings for font:\n\n"); // for (int i = 0; i < codePages.length; i++) { // System.out.println(codePages[i]); // } } else { // load font, embedd it - use unicode LOGGER.debug("Use TrueType Font... at:" + this.ttffontpath); BaseFont bf = BaseFont.createFont(this.ttffontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); resultfont = new Font(bf, fontsize); } } catch (Exception e) { LOGGER.error("DocumentException while creating title page for PDF", e); throw new PDFManagerException("Exception while creating Titlepage for PDF", e); } return resultfont; }
From source file:fr.opensagres.odfdom.converter.pdf.PdfOptions.java
License:Open Source License
private PdfOptions() { this.fontEncoding = BaseFont.IDENTITY_H; this.fontProvider = ITextFontRegistry.getRegistry(); }
From source file:gr.abiss.calipso.util.PdfUtils.java
License:Open Source License
public static void writePdf(String fontDir, String resourcesBasePath, OutputStream os, String html) { try {//from w w w . j av a 2 s .c o m // Create a buffer to hold the cleaned up HTML // Note: you can safely ignore both flush() and close(), // as they do nothing in ByteArrayOutputStream's implementation. // ByteArrayOutputStream out = new ByteArrayOutputStream(); // Clean up the HTML to be well formed HtmlCleaner cleaner = new HtmlCleaner(); CleanerProperties props = cleaner.getProperties(); props.setAdvancedXmlEscape(true); props.setRecognizeUnicodeChars(true); props.setTranslateSpecialEntities(true); props.setUseCdataForScriptAndStyle(false); props.setOmitXmlDeclaration(false); props.setOmitDoctypeDeclaration(false); TagNode node = cleaner.clean(html); // write to the ByteArray buffer html = new PrettyXmlSerializer(props).getAsString(node); // logger.info("CLEANED HTML: " + html); // update the html string using the cleaned-up version // html = new String(out.toByteArray()); ITextRenderer renderer = new ITextRenderer(); renderer.getFontResolver().addFont(fontDir + File.separator + "ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); if (StringUtils.isNotBlank(resourcesBasePath)) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(html)); Document doc = builder.parse(is); String rsPath = new File(resourcesBasePath + File.separator).toURI().toURL().toString(); renderer.setDocument(doc, rsPath); } catch (Exception e) { throw new RuntimeException(e); } } else { renderer.setDocumentFromString(html); } renderer.layout(); renderer.createPDF(os); } catch (Exception e) { logger.error("Failed to creare PDF for item, html: \n" + html, e); } }
From source file:ilarkesto.integration.itext.Paragraph.java
License:Open Source License
private Font createFont(String name, FontStyle fontStyle) { Font font;/*from w ww . ja v a 2 s . co m*/ try { font = new Font(BaseFont.createFont(name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); } catch (Exception ex) { throw new RuntimeException("Loading font failed: " + name, ex); } if (fontStyle != null) { font.setStyle(createStyle(fontStyle)); font.setSize(PdfBuilder.mmToPoints(fontStyle.getSize())); font.setColor(fontStyle.getColor()); } return font; }