List of usage examples for com.itextpdf.text.pdf PdfDictionary getAsArray
public PdfArray getAsArray(final PdfName key)
PdfObject
as a PdfArray
, resolving indirect references. 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 www . j a v a2 s.com*/ 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)); } } } }
From source file:pl.edu.icm.cermine.structure.ITextCharacterExtractor.java
License:Open Source License
private void processAlternativeColorSpace(PdfDictionary resources) { if (resources == null) { return;/*from w w w. j ava 2 s. c o m*/ } PdfDictionary csDictionary = resources.getAsDict(PdfName.COLORSPACE); if (csDictionary == null) { return; } for (PdfName csName : csDictionary.getKeys()) { if (csDictionary.getAsArray(csName) != null) { csDictionary.put(csName, PdfName.DEVICEGRAY); } } }