Refactor PDF generation in make_pdf.sh to streamline the process by removing reliance on textutil. The script now directly converts plain text to PDF using cupsfilter, enhancing compatibility and reducing complexity.

This commit is contained in:
2026-01-22 19:29:59 +09:00
parent bd59c19301
commit 06dc5d0499
2 changed files with 37 additions and 12 deletions

View File

@@ -15,7 +15,7 @@ Outputs (in the same folder as this script):
- EXPORT_COMPLIANCE.pdf
Notes:
- Uses macOS built-in /usr/bin/textutil + /usr/sbin/cupsfilter to generate the PDF.
- Uses macOS built-in /usr/sbin/cupsfilter to generate the PDF from plain text.
EOF
}
@@ -23,6 +23,7 @@ script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
template="${script_dir}/EXPORT_COMPLIANCE.txt"
filled="${script_dir}/EXPORT_COMPLIANCE.filled.txt"
pdf="${script_dir}/EXPORT_COMPLIANCE.pdf"
tmp_html="${script_dir}/EXPORT_COMPLIANCE.tmp.html"
bundle_id=""
version=""
@@ -57,10 +58,6 @@ if [[ ! -f "$template" ]]; then
exit 1
fi
if [[ ! -x /usr/bin/textutil ]]; then
echo "Error: /usr/bin/textutil not found. This should exist on macOS." >&2
exit 1
fi
if [[ ! -x /usr/sbin/cupsfilter ]]; then
echo "Error: /usr/sbin/cupsfilter not found. This should exist on macOS." >&2
exit 1
@@ -87,15 +84,11 @@ sed \
"$template" > "$filled"
rm -f "$pdf" >/dev/null 2>&1 || true
# textutil does not support direct PDF output on modern macOS; convert to HTML first, then print-to-PDF via cupsfilter.
tmp_html="${script_dir}/EXPORT_COMPLIANCE.tmp.html"
rm -f "$tmp_html" >/dev/null 2>&1 || true
/usr/bin/textutil -convert html "$filled" -output "$tmp_html" >/dev/null
# Convert HTML to PDF. cupsfilter writes to stdout by default.
/usr/sbin/cupsfilter -i text/html -m application/pdf "$tmp_html" > "$pdf"
rm -f "$tmp_html" >/dev/null 2>&1 || true
# Convert plain text to PDF. cupsfilter writes PDF to stdout.
# Suppress noisy DEBUG output from cupsfilter on stderr.
/usr/sbin/cupsfilter -i text/plain -m application/pdf "$filled" > "$pdf" 2>/dev/null
echo "Wrote:"
echo " $filled"