add EMF conversion scripts
authorDan White <dan@whiteaudio.com>
Wed, 13 Dec 2017 15:47:56 +0000 (09:47 -0600)
committerDan White <dan@whiteaudio.com>
Wed, 13 Dec 2017 15:47:56 +0000 (09:47 -0600)
emf2pdf [new file with mode: 0755]
emf2png [new file with mode: 0755]

diff --git a/emf2pdf b/emf2pdf
new file mode 100755 (executable)
index 0000000..bc2ba03
--- /dev/null
+++ b/emf2pdf
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Convert EMF file (like from LTspice) to PDF file.
+# Leave the new file in the same directory if no second argument
+
+EMFNAME="$1"
+
+BASENAME=$(basename "$1" .emf)
+
+if [[ "$2" = "" ]]; then
+    OUTNAME="$BASENAME.pdf"
+else
+    OUTNAME="$2"
+fi
+
+PDFNAME="$BASENAME.pdf"
+CROPNAME="$BASENAME-crop.pdf"
+# template from:
+# https://stackoverflow.com/a/34676160
+
+
+# the directory of the script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# the temp directory used, within $DIR
+WORK_DIR=$(mktemp -d "$0.XXXXXXXX")
+
+# check if tmp dir was created
+if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
+  echo "Could not create temp dir" >&2
+  exit 1
+fi
+
+# deletes the temp directory
+function cleanup {      
+  rm -rf "$WORK_DIR"
+  #echo "Deleted temp working directory $WORK_DIR"
+}
+
+function exiterr {
+    echo "Something went wrong... exiting." >&2
+    exit 1
+}
+
+
+# register the cleanup function to be called on the EXIT signal
+trap cleanup EXIT
+
+
+libreoffice --convert-to pdf --outdir "$WORK_DIR" $1 || exiterror
+
+pdfcrop "$WORK_DIR/$PDFNAME" "$WORK_DIR/$CROPNAME" || exiterror
+
+mv "$WORK_DIR/$CROPNAME" "$OUTNAME"
+
+echo "Output is: $OUTNAME"
diff --git a/emf2png b/emf2png
new file mode 100755 (executable)
index 0000000..9e6ffe0
--- /dev/null
+++ b/emf2png
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Convert EMF file (like from LTspice) to PNG file.
+# Leave the new file in the same directory if no second argument
+
+EMFNAME="$1"
+
+BASENAME=$(basename "$1" .emf)
+
+if [[ "$2" = "" ]]; then
+    PNGNAME="$BASENAME.png"
+else
+    PNGNAME="$2"
+fi
+
+PDFNAME="$BASENAME.pdf"
+CROPNAME="$BASENAME-crop.pdf"
+# template from:
+# https://stackoverflow.com/a/34676160
+
+
+# the directory of the script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# the temp directory used, within $DIR
+WORK_DIR=$(mktemp -d "$0.XXXXXXXX")
+
+# check if tmp dir was created
+if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
+  echo "Could not create temp dir" >&2
+  exit 1
+fi
+
+# deletes the temp directory
+function cleanup {      
+  rm -rf "$WORK_DIR"
+  #echo "Deleted temp working directory $WORK_DIR"
+}
+
+function exiterr {
+    echo "Something went wrong... exiting." >&2
+    exit 1
+}
+
+
+# register the cleanup function to be called on the EXIT signal
+trap cleanup EXIT
+
+
+libreoffice --convert-to pdf --outdir "$WORK_DIR" $1 || exiterror
+
+pdfcrop "$WORK_DIR/$PDFNAME" "$WORK_DIR/$CROPNAME" || exiterror
+
+convert -density 300 "$WORK_DIR/$CROPNAME" "$PNGNAME" || exiterror
+
+echo "Output is: $PNGNAME"