Browse Source

adding PDF and image convertion tools

master
mb@ts 3 years ago
parent
commit
c70ac040e8
  1. 74
      command-line/tools/README.md
  2. BIN
      command-line/tools/apple_to_jNP_neutrals.icc
  3. BIN
      command-line/tools/apple_to_jNP_photo.icc
  4. 122
      command-line/tools/color_convert.sh
  5. 3
      command-line/tools/control.txt
  6. 15
      command-line/tools/convert-to-PDFX-3-2002.sh
  7. 10
      command-line/tools/make-images-bw.sh
  8. 30
      command-line/tools/rgb2cmyk.sh
  9. 0
      command-line/tools/texput.log
  10. 68
      command-line/tools/xelatex-PDFX-3-2002.template.tex

74
command-line/tools/README.md

@ -0,0 +1,74 @@
# Tools used for Volumetric Regimes
Before you can run these scripts, they will need to be made executable.
chmod +x *.sh
## OSP-tools.pdfutils: `color_convert.sh`
**Convert PDF RGB to only-Black**
This will convert an RGB PDF (even if it appears only black) to `input-K.pdf`.
./color_convert.sh black input.pdf input-K.pdf
Link: <http://osp.kitchen/tools/pdfutils/>
## OSP-tools.pdfutils: `rgb2cmyk.sh`
**Convert PDF from RGB to CMYK**
Dependencies:
- `gs` (Ghostscript)
- `pdftops`
- `control.txt`
- `apple_to_jNP_photo.icc`
- `apple_to_jNP_neutral.icc`
This will convert a PDF to `input-cmyk.pdf`.
Usage:
./rgb2cmyk.sh input.pdf
Link: <http://osp.kitchen/tools/pdfutils/>
## Custom VR tools: `make-images-bw.sh`
Dependencies:
- `imagemagick`
This will create a copy of an image folder, with all images converted to BW.
Usage:
./make-images-bw.sh ./images-folder/
## Custom VR tools: `convert-to-PDFX-3-2002.sh`
Dependencies:
- `texlive-xetex` (xelatex)
This will convert a PDF into the PDFX/3:2002 format + edit the PDF metadata.
Edit PDF metadata:
Open the xelatex template (`xelatex-PDFX-3-2002.template.tex`) and edit the metadata on line 7-12.
Usage:
convert-to-PDFX-3-2002.sh input.pdf output.pdf
## Other useful tools
- Check metadata of PDF: `pdfinfo filename.pdf`
- Check color space of PDF: `pdfimages -list filename.pdf`

BIN
command-line/tools/apple_to_jNP_neutrals.icc

Binary file not shown.

BIN
command-line/tools/apple_to_jNP_photo.icc

Binary file not shown.

122
command-line/tools/color_convert.sh

@ -0,0 +1,122 @@
#!/bin/bash
#
# USAGE:
# ./color_convert.sh colormodelayer1,colormodelayer2 input_layer1.pdf,input_layer2.pdf output.pdf
# spot colour colormode should look like "spot-COLOR NAME-0 0.64 0.67 0.02"
# where COLOR NAME is the name of the colour and 0 0.64 0.67 0.02 are cmyk values from 0 to 1
DEBUG=1
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function graytospot {
[ $DEBUG -eq 1 ] && echo "converting : $1 to $2 \n"
####################################################################
#part1: let's put our custom color reference in gray_to_spot.ps
IFS='-' read -a args <<< "$2"
IFS=' ' read -a color <<< "${args[2]}"
unset IFS
#args[1] = color name, args[2] = cmyk equivalent in 1 line
#color[0] = C, color[1] = M, color[2] = Y, color[3] = K
spotcolor="\/spotcolor [\/Separation (${args[1]}) \/DeviceCMYK{dup ${color[0]} mul exch dup ${color[1]} mul exch dup ${color[2]} mul exch ${color[3]} mul}] def"
[ $DEBUG -eq 1 ] && echo "spotcolor : $spotcolor \n"
sed -i "s/^\/spotcolor.*$/$spotcolor/g" $DIR/gray_to_spot.ps
#endpart1
######################################################################
#part2: convert to ps file using pdftops
pdftops "$1"
psfile="${1/.pdf/.ps}"
######################################################################
#part3: modify bitmap decode from [0 1] to [1 0] in generated ps
sed -i -e 's/Decode \[0 1\]/Decode [1 0]/g' "$psfile"
######################################################################
#part4: convert back to pdf using gray_to_spot.ps
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$1" $DIR/gray_to_spot.ps "$psfile"
######################################################################
#part5: remove ps file
[ $DEBUG -eq 0 ] && rm "$psfile"
}
IFS=',' read -a layers <<< "$1"
IFS=',' read -a input_files <<< "$2"
unset IFS
if [ $DEBUG -eq 1 ]; then echo "layers : \n"; printf '%s\n' "${layers[@]}"; fi
if [ $DEBUG -eq 1 ]; then echo "files : \n"; printf '%s\n' "${input_files[@]}"; fi
#loop on files and convert them according to layers colormodes
for index in "${!layers[@]}"
do
echo "${input_files[index]} ${layers[index]}"
if [ "${layers[index]}" = "black" ] || [[ "${layers[index]}" == spot* ]]; then
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-sProcessColorModel=DeviceGray \
-sColorConversionStrategy=Gray \
-sDefaultCMYKProfile=ps_cmyk.icc \
-dOverrideICC \
-sOutputFile="${input_files[index]/.pdf/-tmp.pdf}" "${input_files[index]}"
if [[ "${layers[index]}" == spot* ]]; then
graytospot "${input_files[index]/.pdf/-tmp.pdf}" "${layers[index]}"
fi
elif [ "${layers[index]}" = "cmyk" ]; then
gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=pdfwrite \
-dProcessColorModel=/DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sDefaultCMYKProfile=ps_cmyk.icc \
-dOverrideICC \
-sOutputFile="${input_files[index]/.pdf/-tmp.pdf}" "${input_files[index]}"
fi
if [ $DEBUG -eq 0 ]; then
rm "${input_files[index]}"
fi
done
####IF SINGLE LAYER
if [ ${#layers[@]} = 1 ]; then
mv "${input_files[0]/.pdf/-tmp.pdf}" "$3"
exit
fi
####ELSE OVERLAY
inputFile="${input_files[0]/.pdf/-tmp.pdf}"
for(( i=1; i < ${#layers[@]}; i++ ))
do
pdftk "$inputFile" multistamp "${input_files[i]/.pdf/-tmp.pdf}" output "${3/.pdf/$i.pdf}"
if [ $DEBUG -eq 0 ]; then
rm "$inputFile"
rm "${input_files[i]/.pdf/-tmp.pdf}"
fi
inputFile="${3/.pdf/$i.pdf}"
done
lastFileN=$(expr ${#layers[@]} - 1)
mv "${3/.pdf/$lastFileN.pdf}" "$3"
echo "done"
exit

3
command-line/tools/control.txt

@ -0,0 +1,3 @@
Image_RGB apple_to_jNP_photo.icc 0 1 0
Graphic_RGB apple_to_jNP_neutrals.icc 0 1 0
Text_RGB apple_to_jNP_neutrals.icc 0 1 0

15
command-line/tools/convert-to-PDFX-3-2002.sh

@ -0,0 +1,15 @@
# Read first argument from command line: input folder name
INPUT_PDF=$1
OUTPUT_PDF=$2
# Make a tmp copy of the tex template with the input PDF filename
sed "s/XXX/$INPUT_PDF/g" xelatex-PDFX-3-2002.template.tex > xelatex-PDFX-3-2002.tmp.tex
# Run xelatex to convert the PDF to PDFX/3:2002
xelatex xelatex-PDFX-3-2002.tmp.tex
# Rename the output PDF
mv xelatex-PDFX-3-2002.tmp.pdf $OUTPUT_PDF
# Remove the tmp tex files
rm xelatex-PDFX-3-2002.tmp.*

10
command-line/tools/make-images-bw.sh

@ -0,0 +1,10 @@
# Read first argument from command line: input folder name
INPUT_DIR=$1
OUTPUT_DIR=$INPUT_DIR-bw
# Only make an output folder if it does not exist yet
mkdir -p $OUTPUT_DIR
for IMG in $(ls $INPUT_DIR); do
echo "$INPUT_DIR/$IMG ---> $OUTPUT_DIR/$IMG" && convert $INPUT_DIR/$IMG -colorspace Gray $OUTPUT_DIR/$IMG;
done

30
command-line/tools/rgb2cmyk.sh

@ -0,0 +1,30 @@
#! /bin/bash
# CONVERTS RGB PDF TO CMYK PDF PRESERVING TRUE BLACK FOR VECTORS
# OVERPRINT FEATURE IS AVAILABLE WITH AN OPTION
# USAGE:
# ./rgb2cmyk.sh input.pdf
# ./rgb2cmyk.sh input.pdf overprint
# OUTPUT:
# input-cmyk.pdf
# input-cmyk-op.pdf (in case of overprint)
bn=$(basename $1 ".pdf")
op=${2:-knockout}
gs -q -sDEVICE=pdfwrite -o ${bn}-CMYK.pdf -sColorConversionStrategy=CMYK -sSourceObjectICC=control.txt $1
if [ $op == overprint ]
then
pdftops -level2sep ${bn}-CMYK.pdf
sed -e "s/false \(op\)/true \1/gI" ${bn}-CMYK.ps > ${bn}-CMYK-op.ps
#gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=${bn}-CMYK-op.pdf ./forceblack.ps ${bn}-CMYK-op.ps
gs -q -sDEVICE=pdfwrite -o ${bn}-CMYK-op.pdf -sColorConversionStrategy=CMYK -sSourceObjectICC=control.txt ${bn}-CMYK-op.ps
rm ${bn}-CMYK.pdf
rm ${bn}-CMYK.ps
fi

0
command-line/tools/texput.log

68
command-line/tools/xelatex-PDFX-3-2002.template.tex

@ -0,0 +1,68 @@
% !TeX program = xelatex
% Command to run this tex file: xelatex xelatex-make-pdfx-3-2002.tex
\documentclass{book}
\special { pdf:docinfo << /Title (Volumetric Regimes) /Author (Possible Bodies)>> }
\usepackage[unicode,
pdfauthor={Possible Bodies},
pdftitle={Volumetric Regimes},
pdfdisplaydoctitle,
pdfsubject={Material cultures of quantified presence},
pdfkeywords={},
pdfproducer={Paged.js, Chromium, pdftk, LaTeX},
pdfcreator={xelatex}]{hyperref}
\usepackage{pdfpages}
% From: https://tex.stackexchange.com/questions/255480/producing-pdf-x-compliant-document-with-xelatex/275914#275914
%%%%%%%%% PDF-X stuff, IF USING xelatex %%%%%%%%%
%(mm size * 72)/25.4 = bp size
\usepackage{atbegshi}
\AtBeginShipout{% %A hook that is executed for every page (after first one)
\special{pdf: put @thispage
<<
/TrimBox [0 0 648 432] %put here other numbers = size of page in bp
>>
}
}
\special{pdf: put @thispage
<<
/TrimBox [0 0 648 432] %put here other numbers = size of page in bp
>>
}
\special{pdf:docinfo
<<
/GTS_PDFXVersion (PDF/X-3:2002)
/GTS_PDFXConformance (PDF/X-3:2002)
>>
}
\special{pdf:put @catalog
<<
/PageMode /UseNone
/OutputIntents [
<<
/Info (none)
/Type /OutputIntent
/S /GTS_PDFX
/OutputConditionIdentifier (Custom)
/RegistryName (http://www.color.org/)
>>
]
>>
}
\usepackage{datetime} % for \pdfdate command
\usepackage{hyperref} % for \hypersetup
\hypersetup{
pdftitle={DocTitle},% PDF/X document should have a title
pdfinfo={% Setting some more PDF/X stuff for xelatex
ModDate={D:\pdfdate},% PDF/X document should have a modification date
Trapped={False},% PDF/X document should have Trapped tag set
},
}
\begin{document}
\includepdf[pages=-,fitpaper=true]{XXX}
\end{document}
Loading…
Cancel
Save