#!/bin/bash

# Requires imagemagick and poppler-utils
# Configuration required to /etc/Image-magick-N/policy.xml
# add:  <policy domain="coder" rights="read | write" pattern="PDF" />



APP_PATH=$( cd $(dirname $0) && pwd)
PDF_FILENAME="Arduino-comic-fr.pdf" 

set -eou --pipefail

cd "$APP_PATH"

for f in $(cd svg && ls *svg); do 
  echo "Converting file $f..."
  convert -density 200 svg/$f pdf/${f/svg/pdf}
done

echo "Consolidating PDF files..."
pdfunite pdf/* "$PDF_FILENAME"

echo "Successfully updated $PDF_FILENAME"

