Last active
September 17, 2024 08:27
-
-
Save davidaknowles/ba5a2b69f255b748782bd38fe25e4c41 to your computer and use it in GitHub Desktop.
Use ghostscript to convert PDFs to version 1.5 (better for pdflatex)
This file contains 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/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 |
This file contains 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/bash | |
set -e | |
for var in "$@" | |
do | |
./ghostscript_pdf_1p7_to_1p5.sh $var | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"