epub2md/tools/qa/check_pdf.sh

11 lines
931 B
Shell
Raw Normal View History

#!/bin/bash
# Kurzprüfung von PDFs: Seiten, Inhaltsverzeichnis-Seite, Text-Reste, nicht eingebettete Schriften
for pdf in "$@"; do
pages=$(pdfinfo "$pdf" 2>/dev/null | awk '/^Pages:/{print $2}')
txt=$(pdftotext -enc UTF-8 "$pdf" - 2>/dev/null)
tocpage=$(for p in $(seq 1 15); do pdftotext -f $p -l $p "$pdf" - 2>/dev/null | grep -qiE '^(Inhalt|Inhaltsverzeichnis|Contents)$' && { echo $p; break; }; done)
first=$(for p in 1 2 3 4; do printf '%s | ' "$(pdftotext -f $p -l $p "$pdf" - 2>/dev/null | grep -v '^\s*$' | head -1 | cut -c1-28)"; done)
printf '%s\tSeiten=%s\tInhalt-S.=%s\t[!]=%s\t<a id=%s\tTeX=%s\tfehlende-Einbettung=%s\n\t\tS.1-4: %s\n' "$(basename "$pdf" | cut -c1-14)" "$pages" "${tocpage:--}" \
"$(grep -c '\[!' <<<"$txt")" "$(grep -c '<a id' <<<"$txt")" "$(grep -cE '\\\\(frac|begin|mathbb)|\$\$' <<<"$txt")" \
"$(pdffonts "$pdf" 2>/dev/null | awk 'NR>2 && $(NF-4)=="no"' | wc -l)" "$first"
done