Example usage for com.itextpdf.text FontFactory getFont

List of usage examples for com.itextpdf.text FontFactory getFont

Introduction

In this page you can find the example usage for com.itextpdf.text FontFactory getFont.

Prototype


public static Font getFont(final String fontname, final String encoding, final boolean embedded,
        final float size, final int style, final BaseColor color) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:com.github.ossdevs.jhocr.converter.HocrPageProcessor.java

License:Open Source License

/**
 * TODO describe this method./*from w  w w  . j  a v a2 s.com*/
 *
 * @param imageInputStream of the image.
 * @return true if the initialisation was successful.
 */
private boolean init(InputStream imageInputStream) {

    boolean result = false;

    try {

        /**
         * fontname the name of the font
         * encoding the encoding of the font
         * embedded true if the font is to be embedded in the PDF
         * size the size of this font
         * style the style of this font
         * color the BaseColor of this font.
         */
        font = FontFactory.getFont("/fonts/Sansation_Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.NORMAL, BaseColor.BLACK);
        baseFont = font.getBaseFont();
        logger.trace("Loaded font: '{}'.", baseFont.getPostscriptFontName());

        byte[] bytes = new byte[imageInputStream.available()];

        imageInputStream.read(bytes);

        this.image = Image.getInstance(bytes);

        int dpiX, dpiY;

        /**
         * TODO add documentation, for example what if and what else
         */
        if (useImageDpi) {
            dpiX = getImage().getDpiX();
            if (dpiX == 0) {
                dpiX = DPI_DEFAULT;
            }
            dpiY = getImage().getDpiY();
            if (dpiY == 0) {
                dpiY = DPI_DEFAULT;
            }

        } else {
            dpiX = DPI_DEFAULT;
            dpiY = DPI_DEFAULT;
        }

        this.dotsPerPointX = dpiX / HocrToPdf.POINTS_PER_INCH;
        this.dotsPerPointY = dpiY / HocrToPdf.POINTS_PER_INCH;

        /**
         * TODO add documentation
         * TODO simplify this line, too many arguments.
         */
        this.imageRectangle = new Rectangle(getHocrPage().getBbox().getWidth() / getDotsPerPointX(),
                getHocrPage().getBbox().getHeight() / getDotsPerPointY());

        result = true;

    } catch (DocumentException e) {
        logger.error("Error while processing the document, please check th elog for more information.", e);
        result = false;
    } catch (IOException e) {
        logger.error("Error while processing the document, please check th elog for more information.", e);
        result = false;
    }

    return result;

}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public void createPDF(Context context) throws DocumentException, IOException {
    LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml"));
    this.mContext = context;
    Map<String, String> pdfParams = new HashMap();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US);
    dateFormat.setTimeZone(TimeZone.getDefault());
    this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf";
    float leftMargin = Txtbook.RIGHT_MARGIN_EVEN;
    float rightMargin = Txtbook.RIGHT_MARGIN_ODD;
    if (this.settings.addFrontCover.booleanValue()) {
        leftMargin = Txtbook.RIGHT_MARGIN_ODD;
        rightMargin = Txtbook.RIGHT_MARGIN_EVEN;
    }/*www. j a va 2s . c  om*/
    Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN,
            Txtbook.TOP_MARGIN);
    File file = new File(Environment.getExternalStorageDirectory(), this.filename);
    if (!(file.exists() && file.canRead())) {
        file.createNewFile();
    }
    this.writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    this.writer.setCompressionLevel(this.settings.compressionLevel);
    this.writer.setStrictImageSequence(true);
    FontFactory.register("assets/fonts/DroidSans.ttf");
    this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0,
            new BaseColor(152, 152, 152));
    this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f);
    this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0,
            new BaseColor(103, 103, 103));
    this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0,
            new BaseColor(152, 152, 152));
    FontFactory.register("assets/fonts/CourierNew.ttf");
    this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0,
            new BaseColor(103, 103, 103));
    this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f);
    this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f);
    this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f);
    document.open();
    document.setMarginMirroring(true);
    document.addCreationDate();
    document.addCreator("Created with txt-book for Android www.txt-book.com");
    document.addTitle("txt-book for Android");
    if (this.settings.bookStyle == 1) {
        ConversationHeaderFooter hf = new ConversationHeaderFooter();
        hf.footerFont = this.sansFont9;
        hf.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf);
    } else {
        StorybookHeaderFooter hf2 = new StorybookHeaderFooter();
        hf2.title = this.settings.bookCoverTitle;
        hf2.headerFont = this.serifFont8Gray;
        hf2.hasFrontCover = this.settings.addFrontCover;
        this.writer.setPageEvent(hf2);
    }
    if (this.settings.addFrontCover.booleanValue()) {
        createFrontCoverPage(document, this.settings.bookCoverTitle,
                this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null);
        pdfParams.put("PDF Front Cover", "YES");
    } else {
        pdfParams.put("PDF Front Cover", "NO");
    }
    if (this.settings.addFrontCoverImage.booleanValue()) {
        pdfParams.put("PDF Front Cover Image", "YES");
    } else {
        pdfParams.put("PDF Front Cover Image", "NO");
    }
    if (this.settings.bookStyle == 1) {
        createContentPagesConversation(document);
    } else {
        createContentPagesStorybook(document, this.settings.bookCoverTitle);
    }
    int pages = this.writer.getPageNumber();
    if (this.settings.bookStyle == 2) {
        ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    } else {
        ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true);
    }
    if (this.settings.addBackCover.booleanValue()) {
        pages++;
        pdfParams.put("PDF Back Cover", "YES");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
        createBackCoverPage(document, this.settings.backCoverNote);
    } else {
        pdfParams.put("PDF Back Cover", "NO");
        if (pages % 2 == 1) {
            createBlankSpacerPage(document);
        }
    }
    if (this.settings.bookStyle == 2) {
        pdfParams.put("PDF Style", "Storybook");
    } else {
        pdfParams.put("PDF Style", "Conversation");
    }
    pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString());
    document.close();
    FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams);
}

From source file:com.iisigroup.cap.report.factory.ItextFontFactory.java

License:Open Source License

public Font getFont(String fontname, String fontType, String encoding, boolean embedded, float size, int style,
        BaseColor color) {//from w ww .  j a  v a  2  s  .c om
    try {
        return FontFactory.getFont(getFontPath(fontname, fontType), encoding, embedded, size, style, color);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return new Font();
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getFooterFont() {
    if (footerFont == null) {
        Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.5f,
                Font.NORMAL, BaseColor.BLACK);
        footerFont = font.getBaseFont();
    }//from   w  w  w. ja v a  2s  .co  m
    return footerFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineFont() {
    if (lineFont == null) {
        Font font = FontFactory.getFont("/" + LINE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.NORMAL, BaseColor.BLACK);
        lineFont = font.getBaseFont();//w  ww .j  a  v a2s .c  o m
    }
    return lineFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineItalicFont() {
    if (lineItalicFont == null) {
        Font font = FontFactory.getFont("/" + LINE_FONT_ITALIC_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.ITALIC, BaseColor.BLACK);
        lineItalicFont = font.getBaseFont();
    }/*from   w  w w .ja v  a  2 s  . c  om*/
    return lineItalicFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getLineFontBold() {
    if (lineBoldFont == null) {
        Font font = FontFactory.getFont("/" + LINE_BOLD_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.BOLD, BaseColor.BLACK);
        lineBoldFont = font.getBaseFont();
    }/*from  w  ww. j a  va 2s  . c  o m*/
    return lineBoldFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getTitleFont() {
    if (titleFont == null) {
        Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f,
                Font.NORMAL, BaseColor.BLACK);
        titleFont = font.getBaseFont();/*from  ww  w  .j av  a2  s . c o  m*/
    }
    return titleFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getSubtitleFont() {
    if (tableSubtitleFont == null) {
        Font font = FontFactory.getFont("/" + TABLE_SUBTITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.ITALIC, BaseColor.BLACK);
        tableSubtitleFont = font.getBaseFont();
    }//from w  w  w . ja va 2 s . co m
    return tableSubtitleFont;
}

From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java

License:Open Source License

public static BaseFont getHandwrittingFont() {
    if (handwrittingFont == null) {
        Font font = FontFactory.getFont("/" + HANDWRITTING_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
                0.8f, Font.NORMAL, BaseColor.BLACK);
        handwrittingFont = font.getBaseFont();
    }//w ww .ja v  a  2s .  c o m
    return handwrittingFont;
}