From 58a9e65b5554b2c9552540dfea96b562375cf321 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Mon, 2 Dec 2019 14:23:33 +0100 Subject: Mon 02 Dec 2019 02:23:33 PM CET --- pdfs/asPDF.sh | 14 ++++++++++++++ pdfs/pdfSxiv.sh | 30 ++++++++++++++++++++++++++++++ pdfs/toPDF.sh | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100755 pdfs/asPDF.sh create mode 100755 pdfs/pdfSxiv.sh create mode 100755 pdfs/toPDF.sh (limited to 'pdfs') diff --git a/pdfs/asPDF.sh b/pdfs/asPDF.sh new file mode 100755 index 0000000..a03f0aa --- /dev/null +++ b/pdfs/asPDF.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +outdir="/tmp/pdf" +name="${1%.*}" +ext="${1##*.}" +[ -d "$outdir" ] || mkdir -p "$outdir" + +case "$ext" in + "md") + pandoc -s -o "$outdir/$name.pdf" "$1" 1>/dev/null 2>&1 ;; + *) + lowriter --convert-to pdf --outdir "$outdir" "$1" 1>/dev/null 2>&1 ;; +esac +"$READER" "$outdir/$name.pdf" diff --git a/pdfs/pdfSxiv.sh b/pdfs/pdfSxiv.sh new file mode 100755 index 0000000..0a63586 --- /dev/null +++ b/pdfs/pdfSxiv.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# pdfSxiv.sh +# +# Usage: pdfSxiv.sh FILE +# +# Opens all images of a pdf with sxiv + +[ -z "$1" ] && exit 1 + +baseDir="/tmp/pdfSxiv" +directory="${1##*/}" +directory="${directory%%.*}" +fullPath="${baseDir}/001-${directory}" +if [ -d "$fullPath" ]; then + last="$(ls "${fullPath}/.." | sort | tail -n 1)" + last="${last%%-*}" + while echo "$last" | grep -E -q '^0'; do + last="${last#0}" + done + index="$((last+1))" + while ! echo "$index" | grep -E -q '.{3}'; do + index="0$index" + done + fullPath="${baseDir}/${index}-${directory}" +fi + +mkdir -p "$fullPath" +pdfimages -png "$1" "${fullPath}/pdfSxiv" +sxiv "${fullPath}"/* diff --git a/pdfs/toPDF.sh b/pdfs/toPDF.sh new file mode 100755 index 0000000..e4e6ece --- /dev/null +++ b/pdfs/toPDF.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# toPDF.sh +# +# Usage: toPDF.sh [-o] INPUTFILE +# +# Compiles a file to a temporal PDF using pandoc, updating the temporal file if +# it already exists. +# Opens the file with $READER if -o option is given. + +if [ "$1" = "-o" ]; then + open="1" + shift +fi + +[ -z "$1" ] && exit 1 + +targetDir="/tmp/toPDF" +sourceFile="$1" +targetFile="${targetDir}/${sourceFile##*/}" +targetFile="${targetFile%.*}.pdf" + +[ -d "$targetDir" ] || mkdir -p "$targetDir" +pandoc "$sourceFile" -o "$targetFile" +[ -n "$open" ] && "$READER" "$targetFile" & -- cgit v1.2.1