Skip to content

Instantly share code, notes, and snippets.

@davidaknowles
Last active September 17, 2024 08:27
Show Gist options
  • Save davidaknowles/ba5a2b69f255b748782bd38fe25e4c41 to your computer and use it in GitHub Desktop.
Save davidaknowles/ba5a2b69f255b748782bd38fe25e4c41 to your computer and use it in GitHub Desktop.
Use ghostscript to convert PDFs to version 1.5 (better for pdflatex)
#!/bin/bash
set -e
outfile=$2
if [ "$#" -eq 1 ]; then
outfile=$1
fi
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dCompatibilityLevel=1.5 -sOutputFile=temp.pdf $1
# so you can run on the same file
mv temp.pdf $outfile
#!/bin/bash
set -e
for var in "$@"
do
./ghostscript_pdf_1p7_to_1p5.sh $var
done
@JoKalliauer
Copy link

I prefer to convert PDFs to PDF/A-1 (PDF-version 1.4):
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dPDFA=1 -sOutputFile=temp.pdf $1
I would also copy the metadata from the old file to the new one (otherwise, the pdf-creator is saved as ghostscript)
exiftool -TagsFromFile "$1" -All:All --CreatorTool --MetadataDate -XMPToolkit= temp.pdf -overwrite_original
And I would copy the date of the original file: (otherwise you have the convertion-time and not the creation-time of the original pdf)
touch -d @$(stat -c "%Y" "$1") "temp.pdf"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment