Skip to content

Instantly share code, notes, and snippets.

@ninlith
Last active September 9, 2026 13:04
Show Gist options
  • Select an option

  • Save ninlith/d703c36b8c44c1030238b48844e3516a to your computer and use it in GitHub Desktop.

Select an option

Save ninlith/d703c36b8c44c1030238b48844e3516a to your computer and use it in GitHub Desktop.
PDF embedded font sizes
#!/usr/bin/env bash
#
# PDF Font Sizer - Analyze embedded font sizes in PDFs
#
# Assisted by DeepSeek & ChatGPT
#
# Requirements: pdffonts (poppler-utils) and mutool (mupdf-tools)
#
# Usage: ./pdf_font_sizes.sh document.pdf
set -euo pipefail
pdf=${1:?Usage: $0 PDF}
echo "Font sizes in: $pdf"
echo "=========================================="
pdffonts "$pdf" |
awk 'NR > 2 && NF >= 7 { print $1, $7 }' |
while read -r font obj; do
# Remove the six-character PDF subset prefix
name=${font#??????+}
# Get the FontDescriptor object number
desc=$(mutool show "$pdf" "$obj" 0 |
grep -m1 'FontDescriptor' |
grep -oE '[0-9]+ [0-9]+ R' |
awk '{print $1}')
[[ -n "$desc" ]] || continue
# Get the embedded font stream object number
data_obj=$(mutool show "$pdf" "$desc" 0 |
grep -m1 -E 'FontFile[23]?' |
grep -oE '[0-9]+ [0-9]+ R' |
awk '{print $1}')
[[ -n "$data_obj" ]] || continue
size=$(mutool show "$pdf" "$data_obj" 0 | wc -c)
size_kb=$(echo "scale=1; $size/1024" | bc)
printf '%-30s %8d bytes (%6s KB)\n' "$name" "$size" "$size_kb"
done
echo "=========================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment