From 04f399d40e8b707ad4687addf915e25f50fc2425 Mon Sep 17 00:00:00 2001 From: Christopher Spinrath Date: Mon, 4 Dec 2017 16:07:58 +0100 Subject: [PATCH] =?UTF-8?q?fcw2pdf:=20Konvertierungsskript=20f=C3=BCr=20.f?= =?UTF-8?q?cw=20zu=20.pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Das Skript ermöglicht es .fcw Dateien, wie sie von SMART Technologies Meeting Pro abgespeichert werden, in das pdf-Format zu exportieren. --- fcw2pdf/fcw2pdf.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 fcw2pdf/fcw2pdf.sh diff --git a/fcw2pdf/fcw2pdf.sh b/fcw2pdf/fcw2pdf.sh new file mode 100755 index 0000000..c78dffe --- /dev/null +++ b/fcw2pdf/fcw2pdf.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# fcw2pdf.sh: a simple fcw to PDF converter script. +# Copyright 2017 Christopher Spinrath + +# fcw2pdf.sh is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# fcw2pdf.sh is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with fcw2pdf.sh. If not, see . + +set -e + +INPUT_FILE=$1 + +if [ "x$1" == "x" ]; then + echo "Usage: fcw2pdf.sh []" + exit 1 +fi + +INPUT_BASENAME="$(basename "$INPUT_FILE" ".fcw")" +shift + +OUTPUT_FILE=${1:-"${INPUT_BASENAME}.pdf"} + +WORKDIR="$(mktemp -d)" +function cleanup { + rm -Rf "$WORKDIR" +} +trap cleanup EXIT + +cp "$INPUT_FILE" "$WORKDIR/in.zip" +pushd "$WORKDIR" > /dev/null +unzip "in.zip" > /dev/null + +#We could just go with $(ls *.svg) but then the files may be in the wrong order. +#Hence, let's look up the files in the correct order in the manifest file. +MANIFEST_FILE=imsmanifest.xml +PAGE_FILE_QUERY='//resources/resource[@identifier="pages"]/file/@href' +PAGE_FILE_QUERY_RES=$(xmllint --html --xpath "$PAGE_FILE_QUERY" "$MANIFEST_FILE" 2> /dev/null) + +#xmllint's return format is crap; clean it up +PAGE_FILES=$(echo "$PAGE_FILE_QUERY_RES" | tr "[:space:]" "\n" | cut -d\" -f2 | grep -v '^$') + +PDF_FILES="" +for PAGE_FILE in $PAGE_FILES; do + PAGE_BASENAME="$(basename "$PAGE_FILE" ".svg")" + PAGE_PDF="$PAGE_BASENAME.pdf" + PDF_FILES="$PDF_FILES $PAGE_PDF" + echo "Converting $PAGE_BASENAME" + #convert -density 90 -define pdf:fit-page=A4 "$PAGE_FILE" "$PAGE_PDF" + #pass input via stdin, otherwise cairosvg seems to be unable to open included image files + cairosvg -o "$PAGE_PDF" - < "$PAGE_FILE" +done + +pdfunite $PDF_FILES out.pdf + +popd > /dev/null +cp "$WORKDIR/out.pdf" "$OUTPUT_FILE"