Example usage for org.apache.pdfbox.pdmodel PDResources getFont

List of usage examples for org.apache.pdfbox.pdmodel PDResources getFont

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDResources getFont.

Prototype

public PDFont getFont(COSName name) throws IOException 

Source Link

Document

Returns the font resource with the given name, or null if none exists.

Usage

From source file:org.fit.pdfdom.PDFBoxTree.java

License:Open Source License

private void processFontResources(PDResources resources, FontTable table) throws IOException {
    String fontNotSupportedMessage = "Font: {} skipped because type '{}' is not supported.";

    for (COSName key : resources.getFontNames()) {
        PDFont font = resources.getFont(key);
        if (font instanceof PDTrueTypeFont) {
            table.addEntry(font.getName(), font.getFontDescriptor());
            log.debug("Font: " + font.getName() + " TTF");
        } else if (font instanceof PDType0Font) {
            PDCIDFont descendantFont = ((PDType0Font) font).getDescendantFont();
            if (descendantFont instanceof PDCIDFontType2)
                table.addEntry(font.getName(), descendantFont.getFontDescriptor());
            else//from  ww  w . j  a  v a  2 s  .  com
                log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
        } else if (font instanceof PDType1CFont)
            table.addEntry(font.getName(), font.getFontDescriptor());
        else
            log.warn(fontNotSupportedMessage, font.getName(), font.getClass().getSimpleName());
    }

    for (COSName name : resources.getXObjectNames()) {
        PDXObject xobject = resources.getXObject(name);
        if (xobject instanceof PDFormXObject) {
            PDFormXObject xObjectForm = (PDFormXObject) xobject;
            PDResources formResources = xObjectForm.getResources();
            if (formResources != null)
                processFontResources(formResources, table);
        }
    }

}

From source file:org.mabb.fontverter.pdf.PdfFontExtractor.java

License:Open Source License

private void extractFontResources(PDResources resources) throws IOException {
    for (COSName key : resources.getFontNames()) {
        PDFont font = resources.getFont(key);
        extractStrategy.extract(font);/* www .java2 s  .  c o  m*/
    }

    for (COSName name : resources.getXObjectNames()) {
        PDXObject xobject = resources.getXObject(name);
        if (xobject instanceof PDFormXObject) {
            PDFormXObject xObjectForm = (PDFormXObject) xobject;
            PDResources formResources = xObjectForm.getResources();

            if (formResources != null)
                extractFontResources(formResources);
        }
    }
}