Example usage for com.lowagie.text FontFactory register

List of usage examples for com.lowagie.text FontFactory register

Introduction

In this page you can find the example usage for com.lowagie.text FontFactory register.

Prototype


public static void register(String path, String alias) 

Source Link

Document

Register a font file and use an alias for the font contained in it.

Usage

From source file:bucks.GenerateChecks.java

License:Open Source License

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String message = "";
    if (url.equals("")) {
        url = getServletContext().getInitParameter("url");
        String str = getServletContext().getInitParameter("debug");
        if (str != null && str.equals("true"))
            debug = true;/*  ww w.  j  a va2s .  c  o  m*/
        imageUrl = url + "js/images/city_logo3.jpg";
        try {
            FontFactory.register("c:/windows/fonts/verdana.ttf", "Verdana");
            FontFactory.register("c:/windows/fonts/verdana.ttf", "VerdanaB");
        } catch (Exception e) {
            // linux 
            // need to be installed
            try {
                FontFactory.register("/srv/webapps/marketbucks/fonts/verdana.ttf", "Verdana");
                FontFactory.register("/srv/webapps/marketbucks/fonts/verdanab.ttf", "VerdanaB");
            } catch (Exception ee) {
                FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "Verdana");
                FontFactory.register("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", "VerdanaB");
            }
        }
        fnts = FontFactory.getFont(fontName, 8); // small
        fnt10 = FontFactory.getFont(fontName, 10);
        fnt = FontFactory.getFont(fontName, 12);
        fntb = FontFactory.getFont(fontName, 12, Font.BOLD);
        fnt2 = FontFactory.getFont(fontName, 14);
        fntb2 = FontFactory.getFont(fontName, 14, Font.BOLD);
    }
    HttpSession session = null;
    Enumeration<String> values = req.getParameterNames();
    String name = "", action = "Generate";
    String value = "", id = "";
    while (values.hasMoreElements()) {
        name = values.nextElement().trim();
        value = req.getParameter(name).trim();
        if (name.equals("action")) {
            action = value;
        }
        if (name.equals("id")) {
            id = value;
        }
    }
    if (!id.equals("")) {
        Batch batch = new Batch(debug, id);
        String back = batch.doSelect();
        if (back.equals("")) {
            generate(res, batch);
        } else {
            message += back;
        }
    } else {
        message = "Batch id not set ";
    }
    if (!message.equals("")) {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        out.println("<head><title></title><body>");
        out.println("<p><font color=red>");
        out.println(message);
        out.println("</p>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
    }

}

From source file:de.cuseb.bilderbuch.pdf.PdfController.java

License:Open Source License

@RequestMapping(value = "/pdf", method = RequestMethod.GET)
public void generatePdf(HttpSession session, HttpServletResponse httpServletResponse) {

    try {/*from   w w w.  j  a  va 2s .c  om*/
        PdfRequest pdfRequest = (PdfRequest) session.getAttribute("pdfRequest");
        httpServletResponse.setContentType("application/pdf");

        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, httpServletResponse.getOutputStream());
        writer.setDefaultColorspace(PdfName.COLORSPACE, PdfName.DEFAULTRGB);

        //document.addAuthor(pdfRequest.getAuthor());
        //document.addTitle(pdfRequest.getTitle());
        document.setPageSize(
                new Rectangle(Utilities.millimetersToPoints(156), Utilities.millimetersToPoints(148)));
        document.open();

        FontFactory.defaultEmbedding = true;
        FontFactory.register("IndieRock.ttf", "IndieRock");
        Font font = FontFactory.getFont("IndieRock");
        BaseFont baseFont = font.getBaseFont();
        PdfContentByte cb = writer.getDirectContent();

        Iterator<PdfPage> pages = pdfRequest.getPages().iterator();
        while (pages.hasNext()) {

            PdfPage page = pages.next();
            if (page.getImage() != null) {

                Image image = Image.getInstance(new URL(page.getImage().getUrl()));
                image.setDpi(300, 300);
                image.setAbsolutePosition(0f, 0f);
                image.scaleAbsolute(document.getPageSize().getWidth(), document.getPageSize().getHeight());
                document.add(image);

                cb.saveState();
                cb.beginText();
                cb.setColorFill(Color.WHITE);
                cb.moveText(10f, 10f);
                cb.setFontAndSize(baseFont, 18);
                cb.showText(page.getSentence());
                cb.endText();
                cb.restoreState();

                if (pages.hasNext()) {
                    document.newPage();
                }
            }
        }
        document.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.kuali.continuity.service.JasperReportServiceImpl.java

License:Educational Community License

public boolean loadFont(String fontLocation, String fontName) {
    boolean ret = false;
    try {//from   w  w  w.  j av a2 s .com
        FontFactory.register(fontLocation, fontName);
        ret = true;
    } catch (Exception de) {
        logger.warn(" loadFont exception: ", de);
    }
    return ret;
}

From source file:org.oss.pdfreporter.font.FontManager.java

License:Open Source License

@Override
String loadFontInternal(String filePath, String encoding, boolean embed) throws IOException {
    Alias alias = new Alias(fontId++, encoding, embed);
    FontFactory.register(filePath, alias.getName());
    loadedFonts.put(alias.getName(), alias);
    return alias.getName();
}

From source file:org.pz.platypus.plugin.rtf.RtfFont.java

License:Open Source License

/**
 * Get the filenames from the typefaceMap and register them in iText's FontFactory.
 *
 * @param typefaceName name of the typeface
 * @return true if the font is now registered, false if an error occurred. (Font was not in fontlist.)
 *///w  w  w  .  j  a v  a 2 s.  c om
boolean findAndRegisterFont(String typefaceName) {
    String[] fontFiles = lookupFontFilenames(typefaceName);
    if (fontFiles.length == 0) {
        gdd.logWarning(gdd.getLit("COULD_NOT_FIND") + " " + typefaceName + " " + gdd.getLit("IN_FONT_LIST")
                + ". " + gdd.getLit("USING_TIMES_ROMAN") + ".");
        return (false);
    } else {
        for (String fontFile : fontFiles) {
            FontFactory.register(fontFile, typefaceName);
        }
        gdd.log("Registered fonts for " + typefaceName + " in iText");
        return (true);
    }
}

From source file:test.itext.html.AimsPdf.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Document doc = new Document(PageSize.LETTER);
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("aims.pdf"));
    doc.open();/*from   w w w . j  a  v  a  2 s.co m*/
    FontFactory.register("C:\\WINDOWS\\FONTS\\ARIAL.TTF", "arial");
    //      AimsPdf.arial = BaseFont.createFont("C:\\WINDOWS\\FONTS\\ARIAL.TTF",BaseFont.CP1252,BaseFont.NOT_EMBEDDED);

    AimsPdf.style = new StyleSheet();

    style.loadTagStyle("p", "size", "10px");
    style.loadTagStyle("p", "align", "justify");
    style.loadTagStyle("p", "face", "arial");
    style.loadTagStyle("p", "leading", "14f");

    style.loadTagStyle("a", "color", "blue");
    style.loadTagStyle("a", "u", "");

    style.loadTagStyle("ul", "face", "arial");
    style.loadTagStyle("ul", "size", "10px");
    style.loadTagStyle("ul", "leading", "14f");

    style.loadTagStyle("li", "align", "justify");

    style.loadTagStyle("td", "cellpadding", "2");

    //      style.loadTagStyle("p", "spacingAfter", "35px"); 
    //      style.loadTagStyle("p", "spacingBefore", "35px"); 
    //      style.loadTagStyle("p", "style", "margin-top:20px;margin-bottom:20px"); 

    AimsPdf.addTitle(doc, "EA SPORTS FIFA 08");
    AimsPdf.addAgreement(doc, "");
    AimsPdf.addProductionDescription(doc, "");
    AimsPdf.addScreenShorts(doc, "");
    AimsPdf.addUsingApplication(doc, "");
    AimsPdf.addTipsAndTricks(doc, "");
    AimsPdf.addFaq(doc, "");
    AimsPdf.temp(doc, "");

    /*StringBuffer sb=new StringBuffer();               
    sb.append("<p><h1><span style=\"font-size: 100px\"><span style=\"\"><span style=\"font-family: Courier New\"><ins>Hello World</ins></span></span></span></h1></p>");
    writeData(doc, sb);*/
    doc.close();
}