Example usage for com.itextpdf.text.pdf PdfName WIDTHS

List of usage examples for com.itextpdf.text.pdf PdfName WIDTHS

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfName WIDTHS.

Prototype

PdfName WIDTHS

To view the source code for com.itextpdf.text.pdf PdfName WIDTHS.

Click Source Link

Document

A name

Usage

From source file:pl.edu.icm.cermine.structure.ITextCharacterExtractor.java

License:Open Source License

/**
 * Processes PDF's fonts dictionary. During the process alternative names
 * of Standard 14 Fonts are changed to the standard ones, provided that
 * the font definition doesn't include Widths array.
 *
 * Font dictionary in PDF file often includes an array of individual glyphs' widths.
 * Widths array is always required except for the Standard 14 Fonts, which widths
 * are kept by iText itself. Unfortunately, if the font uses alternative name instead of
 * standard one (see PDF Reference 1.7, table H.3), iText doesn't recognize the font as
 * one of the Standard 14 Fonts, and is unable to determine glyphs widths. In such cases
 * this method will change alternative names to standard ones before PDF's parsing process
 *//*from  ww w  .  j  av  a2s  .  c om*/
private void processAlternativeFontNames(PdfDictionary resources) {
    if (resources == null) {
        return;
    }
    PdfDictionary fontsDictionary = resources.getAsDict(PdfName.FONT);

    if (fontsDictionary == null) {
        return;
    }
    for (PdfName pdfFontName : fontsDictionary.getKeys()) {
        if (!(fontsDictionary.get(pdfFontName) instanceof PRIndirectReference)) {
            return;
        }
        PRIndirectReference indRef = (PRIndirectReference) fontsDictionary.get(pdfFontName);
        if (!(PdfReader.getPdfObjectRelease(indRef) instanceof PdfDictionary)) {
            return;
        }
        PdfDictionary fontDictionary = (PdfDictionary) PdfReader.getPdfObjectRelease(indRef);

        PdfName baseFont = fontDictionary.getAsName(PdfName.BASEFONT);
        if (baseFont != null) {
            String fontName = PdfName.decodeName(baseFont.toString());
            if (fontDictionary.getAsArray(PdfName.WIDTHS) == null
                    && ALT_TO_STANDART_FONTS.containsKey(fontName)) {
                fontDictionary.put(PdfName.BASEFONT, ALT_TO_STANDART_FONTS.get(fontName));
            }
        }
    }
}