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

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

Introduction

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

Prototype

public Iterable<COSName> getFontNames() 

Source Link

Document

Returns the names of the font resources, if any.

Usage

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.TableDrawUtils.java

License:EUPL

private static String getFontID(PDFont font, PDResources resources) {
    //      Iterator<java.util.Map.Entry<String, PDFont>> it = resources.getfon
    //            .entrySet().iterator();
    Iterator<COSName> it = resources.getFontNames().iterator();
    while (it.hasNext()) {
        COSName entry = it.next();//from   w  ww .  j  a  v  a2  s . c om
        if (entry.getName().equals(font.getName())) {
            return entry.getName();
        }
    }
    return "";
}

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// w  w  w.j  a v a2  s  .  c o m
                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);//from   www .j a va 2s.  co 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);
        }
    }
}