@@ -14,101 +14,96 @@ fileOut="$2"
14
14
15
15
echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We will filter '$fileIn ' to '$fileOut using ghostscript."
16
16
17
- tempFileA=" $( mktemp) "
18
- echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We will first filter '$fileIn ' to '$tempFileA ' using ghostscript."
17
+ tempFileSrc=" $( mktemp) "
18
+ echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We will first copy '$fileIn ' to '$tempFileSrc '."
19
+ cp " $fileIn " " $tempFileSrc "
20
+ fileSize=" $( stat -c%s " $tempFileSrc " ) "
21
+ oldFileSize=" "
22
+ cycle=0
19
23
20
- gs -dAntiAliasColorImages=true \
21
- -dAntiAliasGrayImages=true \
22
- -dAntiAliasMonoImages=true \
23
- -dAutoFilterColorImages=false \
24
- -dAutoFilterGrayImages=false \
25
- -dAutoRotatePages=/None \
26
- -dBATCH \
27
- -dCannotEmbedFontPolicy=/Error \
28
- -dColorConversionStrategy=/LeaveColorUnchanged \
29
- -dColorImageFilter=/FlateEncode \
30
- -dCompressFonts=true \
31
- -dCompressStreams=true \
32
- -dDetectDuplicateImages=true \
33
- -dDownsampleColorImages=false \
34
- -dDownsampleGrayImages=false \
35
- -dDownsampleMonoImages=false \
36
- -dEmbedAllFonts=true \
37
- -dFastWebView=false \
38
- -dGrayImageFilter=/FlateEncode \
39
- -dHaveTransparency=true \
40
- -dMaxBitmap=2147483647 \
41
- -dNOPAUSE \
42
- -dOptimize=true \
43
- -dPassThroughJPEGImages=true \
44
- -dPassThroughJPXImages=true \
45
- -dPDFSTOPONERROR=true \
46
- -dPDFSTOPONWARNING=true \
47
- -dPreserveCopyPage=false \
48
- -dPreserveEPSInfo=false \
49
- -dPreserveHalftoneInfo=false \
50
- -dPreserveOPIComments=false \
51
- -dPreserveOverprintSettings=false \
52
- -dPreserveSeparation=false \
53
- -dPreserveDeviceN=false \
54
- -dPrinted=false \
55
- -dQUIET \
56
- -dSAFER \
57
- -dSubsetFonts=true \
58
- -dUNROLLFORMS \
59
- -sDEVICE=pdfwrite \
60
- -sOutputFile=" $tempFileA " " $fileIn " \
61
- -c " <</NeverEmbed [ ]>> setdistillerparams" \
62
- -q
24
+ while :
25
+ do
26
+ cycle=$(( cycle+ 1 ))
27
+ tempFileDst=" $( mktemp) "
28
+ echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : Now beginning filter cycle $cycle with destination '$tempFileDst '."
63
29
64
- echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We now filter '$tempFileA ' to '$fileOut ' using ghostscript."
30
+ echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We ghostscript to filter '$tempFileSrc ' to '$tempFileDst '."
31
+ gs -dAntiAliasColorImages=true \
32
+ -dAntiAliasGrayImages=true \
33
+ -dAntiAliasMonoImages=true \
34
+ -dAutoFilterColorImages=false \
35
+ -dAutoFilterGrayImages=false \
36
+ -dAutoRotatePages=/None \
37
+ -dBATCH \
38
+ -dCannotEmbedFontPolicy=/Error \
39
+ -dColorConversionStrategy=/LeaveColorUnchanged \
40
+ -dColorImageFilter=/FlateEncode \
41
+ -dCompatibilityLevel=1.4 \
42
+ -dCompressFonts=true \
43
+ -dCompressStreams=true \
44
+ -dCreateJobTicket=false \
45
+ -dDetectDuplicateImages=true \
46
+ -dDoThumbnails=false \
47
+ -dDownsampleColorImages=false \
48
+ -dDownsampleGrayImages=false \
49
+ -dDownsampleMonoImages=false \
50
+ -dEmbedAllFonts=true \
51
+ -dFastWebView=false \
52
+ -dGrayImageFilter=/FlateEncode \
53
+ -dHaveTransparency=true \
54
+ -dMaxBitmap=2147483647 \
55
+ -dNOPAUSE \
56
+ -dOptimize=true \
57
+ -dPassThroughJPEGImages=true \
58
+ -dPassThroughJPXImages=true \
59
+ -dPDFSTOPONERROR=true \
60
+ -dPDFSTOPONWARNING=true \
61
+ -dPreserveCopyPage=false \
62
+ -dPreserveEPSInfo=false \
63
+ -dPreserveHalftoneInfo=false \
64
+ -dPreserveOPIComments=false \
65
+ -dPreserveOverprintSettings=false \
66
+ -dPreserveSeparation=false \
67
+ -dPreserveDeviceN=false \
68
+ -dPreserveMarkedContent=false \
69
+ -dPrinted=false \
70
+ -dOmitInfoDate=true \
71
+ -dOmitID=true \
72
+ -dOmitXMP=true \
73
+ -dQUIET \
74
+ -dSAFER \
75
+ -dSubsetFonts=true \
76
+ -dUCRandBGInfo=/Remove \
77
+ -dUNROLLFORMS \
78
+ -sDEVICE=pdfwrite \
79
+ -sOutputFile=" $tempFileDst " " $tempFileSrc " \
80
+ -c " <</NeverEmbed [ ]>> setdistillerparams" \
81
+ -c " /PreserveAnnotTypes [/Link] def" \
82
+ -q
65
83
66
- gs -dAntiAliasColorImages=true \
67
- -dAntiAliasGrayImages=true \
68
- -dAntiAliasMonoImages=true \
69
- -dAutoFilterColorImages=false \
70
- -dAutoFilterGrayImages=false \
71
- -dAutoRotatePages=/None \
72
- -dBATCH \
73
- -dCannotEmbedFontPolicy=/Error \
74
- -dColorConversionStrategy=/LeaveColorUnchanged \
75
- -dColorImageFilter=/FlateEncode \
76
- -dCompressFonts=true \
77
- -dCompressStreams=true \
78
- -dDetectDuplicateImages=true \
79
- -dDownsampleColorImages=false \
80
- -dDownsampleGrayImages=false \
81
- -dDownsampleMonoImages=false \
82
- -dEmbedAllFonts=true \
83
- -dFastWebView=false \
84
- -dGrayImageFilter=/FlateEncode \
85
- -dHaveTransparency=true \
86
- -dMaxBitmap=2147483647 \
87
- -dNOPAUSE \
88
- -dOptimize=true \
89
- -dPassThroughJPEGImages=true \
90
- -dPassThroughJPXImages=true \
91
- -dPDFSTOPONERROR=true \
92
- -dPDFSTOPONWARNING=true \
93
- -dPreserveCopyPage=false \
94
- -dPreserveEPSInfo=false \
95
- -dPreserveHalftoneInfo=false \
96
- -dPreserveOPIComments=false \
97
- -dPreserveOverprintSettings=false \
98
- -dPreserveSeparation=false \
99
- -dPreserveDeviceN=false \
100
- -dPrinted=false \
101
- -dQUIET \
102
- -dSAFER \
103
- -dSubsetFonts=true \
104
- -dUNROLLFORMS \
105
- -sDEVICE=pdfwrite \
106
- -sOutputFile=" $fileOut " " $tempFileA " \
107
- -c " <</NeverEmbed [ ]>> setdistillerparams" \
108
- -q
84
+ echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : We filtered '$tempFileSrc ' to '$tempFileDst ' using ghostscript."
85
+ oldFileSize=" $fileSize "
86
+ echo " --- the size of the old file '$tempFileSrc ': $oldFileSize "
87
+ fileSize=" $( stat -c%s " $tempFileDst " ) "
88
+ echo " --- the size of the new file '$tempFileDst ': $fileSize "
109
89
110
- echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : Now deleing '$tempFileA '."
90
+ if (( "$cycle " > 3 )) ; then
91
+ if (( "$fileSize " >= "$oldFileSize ")) ; then
92
+ echo " --- We completed $cycle cycles and the new file is not smaller than the old file, so we stop and use the old file."
93
+ rm " $tempFileDst "
94
+ break
95
+ else
96
+ echo " --- We completed $cycle cycles and the new file is smaller than the old file, so we continue."
97
+ fi
98
+ else
99
+ echo " --- We completed only $cycle cycles, so we continue."
100
+ fi
111
101
112
- rm " $tempFileA "
102
+ rm " $tempFileSrc "
103
+ tempFileSrc=" $tempFileDst "
104
+ done
105
+
106
+ echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : Now moving '$tempFileSrc ' to '$fileOut '."
107
+ mv " $tempFileSrc " " $fileOut "
113
108
114
109
echo " $( date +' %0Y-%0m-%0d %0R:%0S' ) : Successfully finished filtering '$fileIn ' to '$fileOut using ghostscript."
0 commit comments