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 in a Document instance.
- Call
document.getFontUtilities().getAllFonts()to collect every Font resource referenced by the document. - Iterate through the extracted Font objects and read each font name from the font metadata.
- 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());
}
}
}