Using FontCollection fontCollection = pageObject.getResources().getFonts();
I’m getting fontCollection
equals to null. Seems like bug, because using TextFragmentAbsorber
and going through the all page checking textFragment
font we will find out that there are 5 fonts in the pdf (Symbol, TimesNewRomanPSMT, CMSKMO+TimesNewRomanPSMT, TimesNewRomanPS-BoldMT, TimesNewRomanPS-BoldItalicMT ):
TextFragmentAbsorber absorber = new TextFragmentAbsorber(); pageObject.accept(absorber); List<Font> fonts = new ArrayList<>(); for (TextFragment textFragment : absorber.getTextFragments()) { Font font = textFragment.getTextState().getFont(); if (fonts.stream().noneMatch(existingFont -> MATCH_FONT.apply(existingFont, font))) { fonts.add(font); } }
Also fetching fonts from the whole document, not page, works okay:
Font[] allFonts = document.getFontUtilities().getAllFonts();
Document for test: orion2-synopsis-pg1-approved.pdf
orion2-synopsis-pg1-approved.pdf (40.8 KB)