Last active
January 8, 2017 18:57
-
-
Save riggaroo/1f84b1ba920f5bb5db51c98236101d95 to your computer and use it in GitHub Desktop.
Script for creating book dash books from PDF for android app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/local/bin/bash | |
# Prerequistes: You need to install imagemagick and pdfimages for this script to work | |
# Usage - ./convert_book.sh pdf_name.pdf | |
# output - zip file with images and bookdetails.json file | |
# This script assumes the normal structure of a book dash book and wont work for bigger books or books with different formatting to the standard book dash book | |
# it is always advised to check the output zipped file to ensure its correct | |
folderName=$(basename "$1") | |
folderName="${folderName%.*}" | |
echo $folderName | |
echo "Creating folder for book" | |
mkdir $folderName | |
mkdir $folderName/images | |
convert -colorspace rgb -density 120 -background white -alpha remove $1 -scene 1 $folderName/images/Page_%02d.jpg | |
for i in {03..17}; | |
do | |
convert $folderName/images/Page_${i}.jpg -crop 50x100% -delete 1 +repage -set filename:original %t $folderName/images/%[filename:original]a.jpg | |
convert $folderName/images/Page_${i}.jpg -flop -crop 50x100% -flop -delete 1 +repage -set filename:original %t $folderName/images/%[filename:original]b.jpg | |
convert $folderName/images/Page_${i}a.jpg -scale 700x700 $folderName/images/Page_${i}a.jpg | |
rm $folderName/images/Page_${i}.jpg | |
done | |
imagesToSplit=`ls $folderName/images/*.jpg` | |
for i in ${imagesToSplit}; | |
do | |
convert ${i} -scale 700x700 {i} | |
done | |
#create Bookdetails.json | |
bookDescriptonJson='{ | |
"pages": [ | |
{ | |
"pageNumber": 0, | |
"image": "/images/Page_01.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 1, | |
"image": "/images/Page_03a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 2, | |
"image": "/images/Page_03b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 3, | |
"image": "/images/Page_04a.jpg", | |
"audio": null, | |
"text": "" | |
}, | |
{ | |
"pageNumber": 4, | |
"image": "/images/Page_04b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 5, | |
"image": "/images/Page_05a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 6, | |
"image": "/images/Page_05b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 7, | |
"image": "images/Page_06a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 8, | |
"image": "/images/Page_06b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 9, | |
"image": "/images/Page_07a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 10, | |
"image": "/images/Page_07b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 11, | |
"image": "/images/Page_08a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 12, | |
"image": "/images/Page_08b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 13, | |
"image": "/images/Page_09a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 14, | |
"image": "/images/Page_09b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 15, | |
"image": "/images/Page_10a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 16, | |
"image": "/images/Page_10b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 17, | |
"image": "/images/Page_11a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 18, | |
"image": "/images/Page_11b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 19, | |
"image": "/images/Page_12a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 20, | |
"image": "/images/Page_12b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 21, | |
"image": "/images/Page_13a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 22, | |
"image": "/images/Page_13b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 23, | |
"image": "/images/Page_14a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 24, | |
"image": "/images/Page_14b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 25, | |
"image": "/images/Page_15a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 26, | |
"image": "/images/Page_15b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 27, | |
"image": "/images/Page_16a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 28, | |
"image": "/images/Page_16b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 29, | |
"image": "/images/Page_17a.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 30, | |
"image": "/images/Page_17b.jpg", | |
"audio": null, | |
"text": null | |
}, | |
{ | |
"pageNumber": 31, | |
"image": "/images/Page_18.jpg", | |
"audio": null, | |
"text": null | |
} | |
] | |
}' | |
echo "Creating bookdetails.json" | |
echo $bookDescriptonJson > $folderName/bookdetails.json | |
echo "Zipping up folder" | |
zip -r $folderName $folderName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment