Example usage for com.lowagie.text.pdf BaseFont TIMES_ROMAN

List of usage examples for com.lowagie.text.pdf BaseFont TIMES_ROMAN

Introduction

In this page you can find the example usage for com.lowagie.text.pdf BaseFont TIMES_ROMAN.

Prototype

String TIMES_ROMAN

To view the source code for com.lowagie.text.pdf BaseFont TIMES_ROMAN.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:org.pz.platypus.plugin.html.HtmlFont.java

License:Open Source License

/**
 * Get the name by which iText refers to this font. This routine is mostly occupied
 * with the special handling of the base14 fonts. For all other fonts, this routine
 * simply returns its existing name.//  ww  w. j  a va  2s.co m
 *
 * @param f PdfFont whose iText name we're getting
 * @return a string containing the iText usable name for this font.
 */
String createItextFontName(final HtmlFont f) {
    String iTextFontName;
    String typefaceName = f.typeface;

    // handle the different versions of base14 fonts
    if (typefaceName.equals("COURIER")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.COURIER_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.COURIER_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.COURIER_OBLIQUE;
        else
            iTextFontName = BaseFont.COURIER;
    } else if (typefaceName.equals("HELVETICA")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.HELVETICA_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.HELVETICA_OBLIQUE;
        else
            iTextFontName = BaseFont.HELVETICA;
    } else if (typefaceName.equals("TIMES_ROMAN")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.TIMES_BOLDITALIC;
            else
                iTextFontName = BaseFont.TIMES_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.TIMES_ITALIC;
        else
            iTextFontName = BaseFont.TIMES_ROMAN;
    } else if (typefaceName.equals("SYMBOL")) {
        iTextFontName = BaseFont.SYMBOL;
    } else if (typefaceName.equals("DINGBATS")) {
        iTextFontName = BaseFont.ZAPFDINGBATS;
    } else
    // not a base14 font. So make sure we've loaded the font files for Platypus
    // then look up this font among them. If it's still not there, then return
    // a TIMES_ROMAN and note the error.
    {
        //            if( htmlData.getTypefaceMap() == null ) {
        //                TypefaceMap typefaceMap = new TypefaceMap( htmlData.getGdd() );
        //                typefaceMap.loadFamilies();
        //                htmlData.setTypefaceMap( typefaceMap );
        //            }

        // if the font files for this typeface/font family have not been previously registered,
        // then get the filenames from the typefaceMap and register them in iText's FontFactory
        if (!FontFactory.isRegistered(typefaceName)) {
            String[] fontFiles = pdfData.getTypefaceMap().getFamilyFilenames(typefaceName);
            for (String fontFile : fontFiles) {
                FontFactory.register(fontFile);
            }
            gdd.log("Registered fonts for " + typefaceName + " in iText");
        }

        if (FontFactory.isRegistered(typefaceName)) {
            iTextFontName = typefaceName;
        } else {
            // the filename does not exist on the system, so substitute TIMES_ROMAN
            iTextFontName = BaseFont.TIMES_ROMAN;
        }
        //            }
        //            else {
        //                gdd.logInfo(
        //                        gdd.getLit( "FILE#" ) + " " + source.getFileNumber() + " " +
        //                        gdd.getLit( "LINE#" ) + " " + source.getLineNumber() + ": " +
        //                        gdd.getLit( "ERROR.INVALID_FONT_TYPEFACE" ) + " " +
        //                        f.typeface + " " +
        //                        gdd.getLit( "IGNORED" ));
        //                iTextFontName = typeface;
    }
    return (iTextFontName);
}

From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java

License:Open Source License

/**
 * Creates an iText Font object based on a passed-in PdfFont
 *
 * @param f the PdfFont containing the parameters for the font
 * @return the iText Font object//from   ww w  .j av a  2  s  .  c o  m
 */
public Font createItextFont(final PdfFont f) {
    PdfFont pf = f;

    int style = 0;

    Font font = null;

    if (pf == null) {
        pf = new PdfFont(pdfData);
    }

    Color col = new Color(pf.getColor().getR(), pf.getColor().getG(), pf.getColor().getB());
    String iTextFontName = createItextFontName(pf);

    if (!isBase14Font(pf.getFace())) {
        style = computeItextStyle(pf);
        font = getIdentityHFont(iTextFontName, pf.getSize(), style, col);
    }

    if (font == null) { //TODO: identify when this would be the case.
        font = getCp1252Font(iTextFontName, pf.getSize(), style, col);
    }

    if (font == null || font.getBaseFont() == null) { //TODO: Make error msg use literals
        gdd.logWarning("iText could not find font for: " + iTextFontName + ". Using Times-Roman");
        font = FontFactory.getFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED, pf.getSize(),
                style, col);
    }

    // #if debug
    //        Set fonts = FontFactory.getRegisteredFonts();
    //        Set families = FontFactory.getRegisteredFamilies();

    return (font);
}

From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java

License:Open Source License

/**
 * Gets the iText font name for any of the Base14 fonts.
 *
 * @param font the PdfFont whose name we're looking up.
 * @return the iText name or null if an error has occured
 *//*from w  ww. j a va  2  s . com*/
String computeBase14ItextFontName(final PdfFont font) {
    final String typefaceName;
    String iTextFontName = null;
    PdfFont f;

    // in the impossible event this gets passed a null, then
    // replace it with the default font. It might be better
    // to just throw an exception. Should revisit this later.
    if (font == null) {
        f = new PdfFont(pdfData);
    } else {
        f = font;
    }

    typefaceName = f.getFace();

    if (typefaceName.equals("COURIER")) {
        if (f.getBold()) {
            if (f.getItalics()) {
                iTextFontName = BaseFont.COURIER_BOLDOBLIQUE;
            } else {
                iTextFontName = BaseFont.COURIER_BOLD;
            }
        } else if (f.getItalics()) {
            iTextFontName = BaseFont.COURIER_OBLIQUE;
        } else
            iTextFontName = BaseFont.COURIER;

        return (iTextFontName);
    }

    if (typefaceName.equals("HELVETICA")) {
        if (f.getBold()) {
            if (f.getItalics()) {
                iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE;
            } else {
                iTextFontName = BaseFont.HELVETICA_BOLD;
            }
        } else if (f.getItalics()) {
            iTextFontName = BaseFont.HELVETICA_OBLIQUE;
        } else {
            iTextFontName = BaseFont.HELVETICA;
        }

        return (iTextFontName);
    }

    if (typefaceName.equals("TIMES_ROMAN")) {
        if (f.getBold()) {
            if (f.getItalics())
                iTextFontName = BaseFont.TIMES_BOLDITALIC;
            else
                iTextFontName = BaseFont.TIMES_BOLD;
        } else if (f.getItalics())
            iTextFontName = BaseFont.TIMES_ITALIC;
        else
            iTextFontName = BaseFont.TIMES_ROMAN;

        return (iTextFontName);
    }

    if (typefaceName.equals("SYMBOL")) {
        iTextFontName = BaseFont.SYMBOL;
        return (iTextFontName);
    }

    if (typefaceName.equals("DINGBATS")) {
        iTextFontName = BaseFont.ZAPFDINGBATS;
        return (iTextFontName);
    }

    // in theory, impossible, since the font is validated before the function is called.
    return (iTextFontName);
}

From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java

License:Open Source License

/**
 * Get the name by which iText refers to this font. This routine is mostly occupied
 * with the special handling of the Base14 fonts.
 *
 * For all other fonts, this method makes sure the font is registered with iText and
 * returns its name as registered by iText (which is the family name for the font).
 *
 * @param f PdfFont whose iText name we're getting
 * @return a string containing the iText usable name for this font. If passed-in font is
 *             null or the font name is not recognized or found, TIMES_ROMAN is returned.
 *///from  w  w w  .  j  av a2 s .co m
String createItextFontName(final PdfFont f) {
    if (f == null) {
        errFontNotFound("NULL");
        return (BaseFont.TIMES_ROMAN);
    }

    String typefaceName = f.getFace();

    // if it's a Base14 font, compute the name
    if (isBase14Font(typefaceName)) {
        return (computeBase14ItextFontName(f));
    }

    // It's not a base14 font, so is the font already registered in iText?
    if (isRegisteredWithItext(typefaceName)) {
        return (typefaceName);
    }

    // If not, load the font from Platypus into iText, then look up the
    // iText name and return that. In case of error, return TIMES_ROMAN.

    if (!findAndRegisterFont(typefaceName)) {
        errFontNotFound(typefaceName);
        return (BaseFont.TIMES_ROMAN);
    }

    if (isRegisteredWithItext(typefaceName)) {
        return (typefaceName);
    }

    // in theory, cannot get here.
    //        Set regFonts = FontFactory.getRegisteredFonts();   // debug statements, in case we do get here.
    //        Set regFamilies = FontFactory.getRegisteredFamilies();
    errFontNotFound(typefaceName);
    return (BaseFont.TIMES_ROMAN);
}

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

License:Open Source License

/**
 * Creates an iText Font object based on the class fields
 * @param f the PdfFont containing the parameters for the font
 * @return the iText Font object//from  ww  w.  j  a  v  a2s  .c o m
 */
Font createFont(final RtfFont f) {
    int style = 0;
    //       Color col  = new Color( color.getR(), color.getG(), color.getB() );
    Font font = null;

    String iTextFontName = createItextFontName(f);
    if (iTextFontName == null) { // if the font is not in the fontlist nor is it a Base14 font
        f.typeface = DefaultValues.FONT_TYPEFACE;
        iTextFontName = BaseFont.TIMES_ROMAN;
    }

    if (!isBase14Font(f.typeface)) {
        style = computeItextStyle();
        font = getIdentityHFont(iTextFontName, size, style);
    }

    if (font == null) {
        font = getCp1252Font(iTextFontName, size, style);
    }

    if (font == null || font.getBaseFont() == null) { //TODO: Make error msg use literals
        gdd.logWarning("iText could not find font for: " + iTextFontName + ". Using Times-Roman");
        font = FontFactory.getFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED, size, style);
    }

    return (font);
}

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

License:Open Source License

/**
 * Get the name by which iText refers to this font. This routine is mostly occupied
 * with the special handling of the base14 fonts.
 *
 * For all other fonts, this method makes sure the font is registered with iText and
 * returns its name as registered by iText (which is the family name for the font).
 *
 * @param f PdfFont whose iText name we're getting
 * @return a string containing the iText usable name for this font.
 *//*  ww  w . j a v  a2 s.c  o  m*/
String createItextFontName(final RtfFont f) {
    String iTextFontName;
    String typefaceName = f.typeface;

    // handle the different versions of base14 fonts
    if (typefaceName.equals("COURIER")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.COURIER_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.COURIER_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.COURIER_OBLIQUE;
        else
            iTextFontName = BaseFont.COURIER;
    } else if (typefaceName.equals("HELVETICA")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE;
            else
                iTextFontName = BaseFont.HELVETICA_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.HELVETICA_OBLIQUE;
        else
            iTextFontName = BaseFont.HELVETICA;
    } else if (typefaceName.equals("TIMES_ROMAN")) {
        if (f.bold) {
            if (f.italics)
                iTextFontName = BaseFont.TIMES_BOLDITALIC;
            else
                iTextFontName = BaseFont.TIMES_BOLD;
        } else if (f.italics)
            iTextFontName = BaseFont.TIMES_ITALIC;
        else
            iTextFontName = BaseFont.TIMES_ROMAN;
    } else if (typefaceName.equals("SYMBOL")) {
        iTextFontName = BaseFont.SYMBOL;
    } else if (typefaceName.equals("DINGBATS")) {
        iTextFontName = BaseFont.ZAPFDINGBATS;
    } else
    // It's not a base14 font. So make sure we've loaded the font files for Platypus
    // then look up this font among them. If it's still not there, then return
    // a TIMES_ROMAN and note the error.
    {
        if (!FontFactory.isRegistered(typefaceName)) {
            if (!findAndRegisterFont(typefaceName)) {
                return (null);
            }
        }

        if (FontFactory.isRegistered(typefaceName)) {
            iTextFontName = typefaceName;
        } else {
            // in theory, cannot get here.
            gdd.logWarning(gdd.getLit("COULD_NOT_FIND") + " " + typefaceName + " "
                    + gdd.getLit("IN_FONT_REGISTER") + ". " + gdd.getLit("USING_TIMES_ROMAN") + ".");
            iTextFontName = null;
        }
    }
    return (iTextFontName);
}

From source file:org.xhtmlrenderer.pdf.ITextFontResolver.java

License:Open Source License

private static void addTimes(HashMap result) throws DocumentException, IOException {
    FontFamily times = new FontFamily();
    times.setName("Times");

    times.addFontDescription(//from w ww  .  jav  a 2s.  c om
            new FontDescription(createFont(BaseFont.TIMES_BOLDITALIC), IdentValue.ITALIC, 700));
    times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_ITALIC), IdentValue.ITALIC, 400));
    times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_BOLD), IdentValue.NORMAL, 700));
    times.addFontDescription(new FontDescription(createFont(BaseFont.TIMES_ROMAN), IdentValue.NORMAL, 400));

    result.put("Serif", times);
    result.put("TimesRoman", times);
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

public void printPdf() throws IOException, DocumentException {

    // check that we have data to print
    if (handler == null)
        throw new DocumentException();

    //response.setContentType("application/pdf");  //octet-stream
    //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\"");

    //Create the document we are going to write to
    document = new Document();
    //PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
    PdfWriter writer = PdfWriter.getInstance(document, os);

    //Set page event, function onEndPage will execute each time a page is finished being created
    writer.setPageEvent(this);

    document.setPageSize(PageSize.LETTER);
    document.addTitle("Title of the Document");
    document.addCreator("OSCAR");
    document.open();//from  www  .j  a va2s  .co m

    //Create the fonts that we are going to use
    bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, 9, Font.NORMAL);
    boldFont = new Font(bf, 10, Font.BOLD);
    redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

    // add the header table containing the patient and lab info to the document
    createInfoTable();

    // add the tests and test info for each header
    ArrayList<String> headers = handler.getHeaders();
    for (int i = 0; i < headers.size(); i++)
        addLabCategory(headers.get(i));

    // add end of report table
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100);
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPhrase(new Phrase("  "));
    table.addCell(cell);
    cell.setBorder(15);
    cell.setBackgroundColor(new Color(210, 212, 255));
    cell.setPhrase(new Phrase("END OF REPORT", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    document.add(table);

    document.close();

    os.flush();
}

From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {//from w  w  w .  j a  v  a 2  s.  c  o  m

        Rectangle page = document.getPageSize();
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        int pageNum = document.getPageNumber();
        float width = page.getWidth();
        float height = page.getHeight();

        //add patient name header for every page but the first.
        if (pageNum > 1) {
            cb.beginText();
            cb.setFontAndSize(bf, 8);
            cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, handler.getPatientName(), 575, height - 30, 0);
            cb.endText();

        }

        //add footer for every page
        cb.beginText();
        cb.setFontAndSize(bf, 8);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "-" + pageNum + "-", width / 2, 30, 0);
        cb.endText();

        // add promotext as footer if it is enabled
        if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) {
            cb.beginText();
            cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED),
                    6);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER,
                    OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), width / 2, 19, 0);
            cb.endText();
        }

        // throw any exceptions
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:questions.directcontent.InterpretOCR.java

public static void main(String[] args) throws IOException, DocumentException {
    Document document = new Document(PageSize.LETTER);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    document.open();//  w w w .j  ava2 s  .  c om
    PdfContentByte cb = writer.getDirectContent();
    BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    cb.beginText();
    cb.setFontAndSize(font, 12);
    String line;
    String word;
    @SuppressWarnings("unused")
    float llx, lly, urx, ury;
    StringTokenizer tokenizer;
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(RESOURCE)));
    while ((line = reader.readLine()) != null) {
        tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            tokenizer.nextToken();
            word = tokenizer.nextToken();
            llx = Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            lly = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            urx = Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            ury = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10;
            cb.showTextAligned(Element.ALIGN_LEFT, word, (llx + urx) / 2, lly, 0);
        }
    }
    cb.endText();
    document.close();
}