SEARCH
TOOLBOX
LANGUAGES
modified on 15 September 2014 at 08:05 ••• 2,270 views

Code:text2pdf

From Predictive Chemistry

Jump to: navigation, search

Here's a small shell script that uses the text2pdf utility (along with standard tr, sed, and fold utils) to create pdf documents from text file inputs. Note the ^==*, which turns lines starting with = Name into clearly delimited sections. Tr and sed remove dos formatting and remove extra blank lines.

for i in *.txt; do
  name=`basename $i .txt`
  [ -s $name.pdf ] && continue
  echo $i >tmp
  cat $i | tr -d '\r' | sed -e '/^ *$/d; s/^==*\(.*\)/\
\
\
\
\
#=================== \1 ===================/;' | fold -w 80 -s >>tmp
  text2pdf  -f "Courier" -s 12 -o $name.pdf tmp
done
rm -f tmp