Extract Fonts from PDF via Java

Contents
[ ]

Use font extraction when you need to audit document typography, inspect embedded resources, or verify font usage before conversion or archival workflows.

  1. Open the source PDF in a Document instance.
  2. Call document.getFontUtilities().getAllFonts() to collect every Font resource referenced by the document.
  3. Iterate through the extracted Font objects and read each font name from the font metadata.
  4. Print the font names so the document typography can be audited or exported.
public static void extractFonts(Path inputFile) {
    try (Document document = new Document(inputFile.toString())) {
        Font[] fonts = document.getFontUtilities().getAllFonts();
        for (Font font : fonts) {
            System.out.println(font.getFontName());
        }
    }
}