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 Document.
  2. Get all Font objects used in the document.
  3. Iterate through the extracted Font objects.
  4. Print each font name.
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());
        }
    }
}