Created
May 20, 2025 18:37
-
-
Save juanfal/4e4f48cdfd06c385c3c03e71f0915690 to your computer and use it in GitHub Desktop.
Converts each argument.pdf file in argument-pdfa.pdf compliant file using Ghostscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# pdfamaker.sh | |
# 2025-05-20 | |
# | |
# build by ChatGPT | |
# it depends only on Ghostscript | |
# it works with my current one: | |
# Ghostscript 10.05.1 (2025-04-29) | |
# Exit on any error | |
set -e | |
# Check if arguments were passed | |
if [ "$#" -eq 0 ]; then | |
echo "Usage: $0 file1.pdf [file2.pdf ...]" | |
exit 1 | |
fi | |
# Process each file passed as an argument | |
for file in "$@"; do | |
# Check if file exists and is a PDF | |
if [[ ! -f "$file" ]]; then | |
echo "File not found: $file" | |
continue | |
fi | |
if [[ "$file" != *.pdf ]]; then | |
echo "Skipping non-PDF file: $file" | |
continue | |
fi | |
# Skip files that already have -pdfa suffix | |
if [[ "$file" == *-pdfa.pdf ]]; then | |
echo "Skipping already converted: $file" | |
continue | |
fi | |
# Strip extension and create output filename | |
base="${file%.pdf}" | |
output="${base}-pdfa.pdf" | |
echo "Converting $file → $output" | |
gs -dPDFA=2 \ | |
-dBATCH \ | |
-dNOPAUSE \ | |
-dNOOUTERSAVE \ | |
-sDEVICE=pdfwrite \ | |
-sProcessColorModel=DeviceRGB \ | |
-dPDFACompatibilityPolicy=1 \ | |
-sOutputFile="$output" \ | |
"$file" | |
echo "✔ Converted: $output" | |
done | |
echo "Done." | |
exit 0 | |
# -sColorConversionStrategy=UseDeviceIndependentColor \ | |
# gs -dPDFA=2 -dBATCH -dNOPAUSE -sProcessColorModel=DeviceRGB \ | |
# -sDEVICE=pdfwrite -sPDFACompatibilityPolicy=1 \ | |
# -sOutputFile=galileo-pdfa.pdf out.pdf | |
# gs -dPDFA=2 -dBATCH -dNOPAUSE \ | |
# -sDEVICE=pdfwrite \ | |
# -sOutputFile=galileo-pdfa.pdf out.pdf | |
# gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf galileo.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment