Recreating your NotesPlus notebooks from backup

When I bought my iPad (thanks to you!) I started to use the very good NotesPlus app. It's really good and -amongst other things- it lets you annotate your PDFs.
After someone stole my iPad they also took my notes from me. Hopefully NotesPlus includes an option to automatically backup your notes to Dropbox.

Fortunately, the backup format that the app uses on Dropbox is pretty simple: it stores the background PDF you've used and a SVG file per each page with your annotations (and a lot of metadata I'm deliberately ignoring).
I've created a simple bash script for Linux/OSX (anywhere you've got BASH+ImageMagick, really) that uses the wonderful ImageMagick to extract the pages of the PDF one by one, overlay the SVG over it and then convert everything into a single PDF file once again.

Obviously it only covers one of the many use cases for NotesPlus, but it did the trick for me.
I leave it here in case it's ever useful to anybody:
#!/bin/bash

# Clear environment, just in case
export DYLD_LIBRARY_PATH=""
export LD_LIBRARY_PATH=""
# Determine my running dir
MYDIR=$(dirname $0)
cd "$MYDIR"
MYDIR="$(pwd)"
# This'll save us a lot of headaches
SAVEIFS=$IFS
IFS=$(echo -en "\n\b") 

# Iterate on all the notebooks found
for NOTEBOOK in $(ls | sort -n); do
    if [ -d "$NOTEBOOK" ]; then
        echo "Processing '$NOTEBOOK'"
        echo "=========================="
        cd "$NOTEBOOK"
        FILES=""
        # Do this thing for each page found
        for PAGE in $(ls | sort -n); do
            # Make sure the directory's name is an integer
            expr "$PAGE" + 1 &> /dev/null
            RETVAL=$?
            if [ -d "$PAGE" -a "$RETVAL" -eq 0 ]; then
                cd "$PAGE"
                echo "$PAGE"
                # The number of the page-1
                PAGE_1=$(expr $PAGE - 1)
                # Make the background of the SVG file transparent
                sed -i '' 's/fill:#FFFFFF;  stroke-width:2.0;/fill:#FFFFFF;  fill-opacity: 0;  stroke-width:2.0;/g' page.svg
                # Convert the background and the foregroung to PNGs
                convert -antialias -background transparent -resize 826x1169 page.svg page.png
                convert -density 400 -resize 826x1169 ../background.pdf[$PAGE_1] background.png
                # Compose an output PNG from the background+foreground
                convert -flatten background.png page.png $PAGE.jpg
                FILES="$FILES $PAGE/$PAGE.jpg"
                # Remove unneeded files
                rm -f background.png page.png
                cd "$MYDIR/$NOTEBOOK"
            fi
        done

        cd "$MYDIR/$NOTEBOOK"
        
        if ! [ -z "$FILES" ]; then
            echo "Creating final PDF for $(pwd)"
            IFS=$SAVEIFS
            convert -compress JPEG -adjoin -limit area 1 $FILES "$NOTEBOOK".pdf
            IFS=$(echo -en "\n\b")
        fi
    fi
    cd "$MYDIR"
done
Obviously, you must install ImageMagick on your system if you haven't already done so.

0 komentar:

Post a Comment

Blog Archive