Extract Fonts from PDF via Java
Contents
[
Hide
]
Use font extraction when you need to audit document typography, inspect embedded resources, or verify font usage before conversion or archival workflows.
- Open the source PDF Document.
- Get all Font objects used in the document.
- Iterate through the extracted Font objects.
- 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());
}
}
}