Files
Wallenc/Report/scripts/merge_front_matter.sh

45 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Склеивает 3 страницы ВКР_первы_3_страницы_Пытков.pdf и тело ПЗ (оригинальные страницы, без полей Typst).
set -euo pipefail
merge_front_into_pz() {
local report_dir="$1"
local body_pdf="$2"
local front_pdf="$report_dir/front-matter-export/ВКР_первы_3_страницы_Пытков.pdf"
local out_pdf="$report_dirояснительная_записка_ПытковРЕ.pdf"
local front_pages=3 # = pz-vkr-front-page-count в includes/pz-page-offset.typ
if [[ ! -f "$front_pdf" ]]; then
echo "error: нет PDF первых страниц: $front_pdf" >&2
return 1
fi
if [[ ! -f "$body_pdf" ]]; then
echo "error: нет тела ПЗ: $body_pdf" >&2
return 1
fi
if ! command -v qpdf >/dev/null; then
echo "error: нужен qpdf (https://qpdf.sourceforge.io/)" >&2
return 1
fi
if command -v pdfinfo >/dev/null; then
local n
n="$(pdfinfo "$front_pdf" 2>/dev/null | awk '/^Pages:/ {print $2}')"
if [[ -n "$n" && "$n" != "$front_pages" ]]; then
echo "warning: в $front_pdf страниц: $n (ожидалось $front_pages)" >&2
fi
fi
echo "== merge: $(basename "$front_pdf") + body → $(basename "$out_pdf") =="
# qpdf вместо pdfunite: poppler сыпет «recursive dicts» на каждую страницу Typst-PDF
qpdf --warning-exit-0 --empty \
--pages "$front_pdf" "1-$front_pages" "$body_pdf" 1-z \
-- "$out_pdf"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
REPORT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
BODY="${2:-$REPORT_DIR/.Пояснительная_записка_ПытковРЕ.body.pdf}"
merge_front_into_pz "$REPORT_DIR" "$BODY"
fi