From ac7a18ce26da864dd7272edd4f8e2ca24257f0dd Mon Sep 17 00:00:00 2001 From: Dan White Date: Wed, 13 Dec 2017 09:47:56 -0600 Subject: [PATCH] add EMF conversion scripts --- emf2pdf | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ emf2png | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100755 emf2pdf create mode 100755 emf2png diff --git a/emf2pdf b/emf2pdf new file mode 100755 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 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" -- 2.25.1