]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/my-ps2pdf
Have not used zshfe for years
[dotfiles.git] / bin / bin / my-ps2pdf
1 #!/usr/bin/env zsh
2 # Original ps2pdf is just a trivial caller to gs too.
3 # That ones is lossless, tries to be closer to PDF/A-1.
4 # It also copies Producer metainformation tag to Creator,
5 # removes all empty metainformation fields, removed fields
6 # with uuid:s, removes Format (that is application/pdf).
7
8 setopt ERR_EXIT
9 opts=(
10     -dQUIET
11     -dBATCH
12     -dNOPAUSE
13     -dSAFER
14     -sDEVICE=pdfwrite
15     -dPDFSETTINGS=/default
16     -dPDFA=1
17     -dCompatibilityLevel=1.4
18     -dPDFACompatibilityPolicy=3 # that will skip some errors about XMP
19     -dAutoRotatePages=/None
20     -dOptimize=true
21     -sColorConversionStrategy=RGB # advised for PDF/A
22     -sProcessColorModel=DeviceRGB # advised for PDF/A
23     -dAutoFilterColorImages=false
24     -dAutoFilterGrayImages=false
25     -dAutoFilterMonoImages=false
26     -dColorImageFilter=/FlateEncode
27     -dGrayImageFilter=/FlateEncode
28     -dMonoImageFilter=/FlateEncode
29     -sOutputFile="$1".pdf
30 )
31 gs ${=opts} $1
32
33 toremove=(Format)
34 exiftool $1.pdf | while read l ; do
35     f=${${(s/:/)l}[1]:gs/ //}
36     [[ "$l" =~ ": " ]] || toremove=($f $toremove)
37     [[ "$l" =~ ": uuid:" ]] && toremove=($f $toremove)
38 done
39 for i ({1..${#toremove}}) toremove[$i]=-${toremove[$i]}=
40 exiftool -zip -overwrite_original -quiet \
41     -tagsFromFile $1 -Producer\>Creator \
42     ${=toremove} $1.pdf
43 [[ -z $LINEARIZE ]] || LINEARIZE=--linearize
44 qpdf $LINEARIZE --compress-streams=y $1.pdf $1.pdf.pdf
45 mv $1.pdf.pdf $1.pdf