Added pdf conversion scripts

This commit is contained in:
Georgy Litvinov 2021-01-08 19:53:21 +01:00
commit 101c47872e
5 changed files with 104 additions and 0 deletions

48
HackRGB-cmyk-inv.ps Normal file
View file

@ -0,0 +1,48 @@
%!
/oldsetrgbcolor /setrgbcolor load def
/setrgbcolor {
(in replacement setrgbcolor\n) print
%% R G B
1 index 1 index %% R G B G B
eq { %%
2 index 1 index %% R G B R B
eq {
%% Here if R = G = B
pop pop %% remove two values
% setgray % "replace the 'setgray' with":
0 0 0 4 -1 roll % setcmykcolor
-1 mul %% obtain -R on top of stack
1 add %% obtain 1-R on top of stack
setcmykcolor %% now set(cmykcolor) K (as 1-R)
} {
oldsetrgbcolor %% set the RGB values
} ifelse
}{
oldsetrgbcolor %% Set the RGB values
}ifelse
} bind def
/oldsetgray /setgray load def
/setgray {
(in replacement setgray\n) print
% == % debug: pop last element and print it
% here we're at a gray value;
% http://www.tailrecursive.org/postscript/operators.html#setcymkcolor
% setgray: "gray-value must be a number from 0 (black) to 1 (white)."
% setcymkcolor: "The components must be between 0 (none) to 1 (full)."
% so convert here again:
0 0 0 4 -1 roll % push CMY:000 after Gray and roll down,
% so top of stack becomes
% ...:C:M:Y:Gray
-1 mul %% obtain -Gray on top of stack
1 add %% obtain 1-Gray on top of stack
setcmykcolor %% now set(cmykcolor) K (as 1-Gray)
} bind def
%~ # test: rgb2gray
%~ gs -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=./blah-slide-hackRGB-gray.ps ./HackRGB.ps ./blah-slide-gsps2w.ps
%~ # gray2cmyk
%~ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=./blah-slide-hackRGB-gray-ci.pdf ./HackRGB-cmyk-inv.ps ./blah-slide-hackRGB-gray.ps
%~ # check separations - looks OK
%~ gs -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=1 -sOutputFile=p%02d.tif blah-slide-hackRGB-gray-ci.pdf && eog p01.tif 2>/dev/null

11
pdf2flattened.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
name=$1
gs \
-sDEVICE=pdfwrite \
-sProcessColorModel=DeviceCMYK \
-sColorImageResolution=1200 \
-sColorImageFilter=/FlatEncode \
-dOverrideICC \
-o "$name-flattened.pdf" \
"$name"

18
rgb2cmyk.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
name=$1
pdftops -level3sep "$name" "$name.ps"
# PS to PDF using replacement function in HackRGB-cmyk-inv.ps
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-dProcessColorModel=/DeviceCMYK \
-dCompatibilityLevel=1.4 \
-dAutoRotatePages=/None \
-dOverrideICC \
-dNoOutputFonts \
-sOutputFile="$name-cmyk.pdf" \
~/bin/HackRGB-cmyk-inv.ps \
"$name.ps"
rm -f "$name.ps"

13
rgb2grey-fonts.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
name=$1
gs \
-sDEVICE=pdfwrite \
-sProcessColorModel=DeviceGray \
-sColorConversionStrategy=Gray \
-sColorImageResolution=600 \
-sColorImageFilter=/FlatEncode \
-dOverrideICC \
-dCompatibilityLevel=1.4 \
-dAutoRotatePages=/None \
-o "$name-grey.pdf" \
"$name"

14
rgb2grey.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
name=$1
gs \
-sDEVICE=pdfwrite \
-sProcessColorModel=DeviceGray \
-sColorConversionStrategy=Gray \
-sColorImageResolution=600 \
-sColorImageFilter=/FlatEncode \
-dOverrideICC \
-dCompatibilityLevel=1.4 \
-dAutoRotatePages=/None \
-dNoOutputFonts \
-o "$name-grey.pdf" \
"$name"