From 7420585cdec9f88a5886c94b58c86ee6372f0934 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 27 Jan 2022 19:19:33 +0300 Subject: [PATCH] ps2pdf sanitizes XMP. Rewritten on zsh --- bin/bin/ps2pdf.sh | 14 -------------- bin/bin/ps2pdf.zsh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) delete mode 100755 bin/bin/ps2pdf.sh create mode 100755 bin/bin/ps2pdf.zsh diff --git a/bin/bin/ps2pdf.sh b/bin/bin/ps2pdf.sh deleted file mode 100755 index b892beb..0000000 --- a/bin/bin/ps2pdf.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -gs \ - -dBATCH -dNOPAUSE -dSAFER \ - -sDEVICE=pdfwrite -dPDFA \ - -dPDFSETTINGS=/default \ - -dAutoRotatePages=/None \ - -sColorConversionStrategy=DeviceRGB \ - -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \ - -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode \ - -dMonoImageFilter=/FlateEncode \ - -dOptimize=true \ - -dEmbedAllFonts=true \ - -sOutputFile="$1".pdf "$1" diff --git a/bin/bin/ps2pdf.zsh b/bin/bin/ps2pdf.zsh new file mode 100755 index 0000000..5f7bef2 --- /dev/null +++ b/bin/bin/ps2pdf.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# Original ps2pdf is just a trivial caller to gs too. +# That ones is lossless, tries to be closer to PDF/A-1. +# It also copies Producer metainformation tag to Creator, +# removes all empty metainformation fields, removed fields +# with uuid:s, removes Format (that is application/pdf). + +set -e +opts=( + -dQUIET + -dBATCH + -dNOPAUSE + -dSAFER + -sDEVICE=pdfwrite + -dPDFSETTINGS=/default + -dPDFA=1 + -dCompatibilityLevel=1.4 + -dPDFACompatibilityPolicy=3 # that will skip some errors about XMP + -dAutoRotatePages=/None + -dOptimize=true + -sColorConversionStrategy=RGB # advised for PDF/A + -sProcessColorModel=DeviceRGB # advised for PDF/A + -dAutoFilterColorImages=false + -dAutoFilterGrayImages=false + -dAutoFilterMonoImages=false + -dColorImageFilter=/FlateEncode + -dGrayImageFilter=/FlateEncode + -dMonoImageFilter=/FlateEncode + -sOutputFile="$1".pdf +) +gs ${=opts} $1 + +toremove=(Format) +exiftool $1.pdf | while read l ; do + f=${${(s/:/)l}[1]:gs/ //} + [[ "$l" =~ ": " ]] || toremove=($f $toremove) + [[ "$l" =~ ": uuid:" ]] && toremove=($f $toremove) +done +for i ({1..${#toremove}}) toremove[$i]=-${toremove[$i]}= +exiftool -zip -overwrite_original -quiet \ + -tagsFromFile $1 -Producer\>Creator \ + ${=toremove} $1.pdf -- 2.44.0