I'm fairly certain the current version is all HTML (ours is Flash but it's a couple of versions old). I've reworked the script assuming you'd be running it on a Mac instead of Linux, and that you would run it on the same machine Flip PDF Professional is installed on. It assumes the webroot of your web server is mounted on the Mac.
We have flipbooks for different customers in different directories. So our webroot looks like this:
Code:
[FONT=courier new]<webroot>
|
+---Initech/
| |
| +---flipbook1/
| |
| +---flipbook2/
|[/FONT]
[FONT=courier new] +---SoylentCorp/[/FONT]
[FONT=courier new] |
+---flipbook1/
|
+---flipbook2/[/FONT]
The flipbooks are accessed at "ourserver.com/Initech/flipbook1," "ourserver.com/Initech/flipbook2," "ourserver.com/SoylentCorp/flipbook1," etc. The bash script is designed to support this structure.
If you want to make new flipbooks for both Initech and SoylentCorp at the same time, you would create a directory on your desktop and inside it create two directories named "Initech" and "SoylentCorp." Inside each of those directories you would place the PDF files "flipbook1.pdf" and "flipbook2.pdf." You then must place a "settings.txt" file inside both "Initech" and "SoylentCorp." The "settings.txt" file contains the settings for the flipbook software which determine its myriad presentation settings. You can get it by using the software interactively and saving the settings to a file. The only difference between the "settings.txt" file and a settings file you save out of the flipbook software is the first line. We add a line at the beginning that is either "Spread" or "Neat" - these are different template engines for the software that have their own unique options. The settings files you can import and export out of the software do not capture which template are used - they are only applicable to one "template." The script we run needs to know this, so an extra line is added to the settings file to tell it how to proceed. If this doesn't make sense, it probably will once you get the software. There are options other than "Spread" and "Neat," but those are the only two we're using.
Once the file and directory structure you've created is ready to go, rename the directory you created on your desktop to "flipbook" - this is what the script is constantly watching for. It is important to not name it "flipbook" at the beginning, since that can start the processing before you've placed all of the files in it. Once it is finished, it is renamed to "flipbook.FINISHED." You need to get rid of this directory or rename it to something else before you have the script run again.
Here's the script:
Code:
[COLOR=#008080]#!/bin/bash[/COLOR]
[COLOR=#FF8C00]# set the directory where input files will be watched for[/COLOR]
INPUTDIR=/Users/Somebody/Desktop/flipbook
[COLOR=#FF8C00]# set the directory the input directory will be renamed to when processing is complete[/COLOR]
INPUTDIRFINISHED=/Users/Somebody/Desktop/flipbook.FINISHED
[COLOR=#FF8C00]# set the directory where the web server's root directory is mounted[/COLOR]
WEBROOT=/Volumes/webroot/
[COLOR=#FF8C00]# set bash's field separator so files with spaces in their names will work[/COLOR]
IFS=$(echo -en "\n\b")
[COLOR=#FF8C00]# repeat forever[/COLOR]
while [[ 1 ]]; do
[COLOR=#FF8C00] # if the input directory and web root directory both exist[/COLOR]
if [[ -d $INPUTDIR && -d $WEBROOT ]]; then
[COLOR=#FF8C00] # change the working directory to the input directory[/COLOR]
cd $INPUTDIR
[COLOR=#FF8C00] # iterate over every directory that exists within the input directory[/COLOR]
for D in $(find . -maxdepth 1 -type d); do
[COLOR=#FF8C00] # change the working directory to the current subdirectory[/COLOR]
cd "$D"
[COLOR=#FF8C00] # remove any AppleDouble files (probably only needed when this is running on Linux)[/COLOR]
rm ._*
[COLOR=#FF8C00] # iterate over every pdf file that exists in the current directory[/COLOR]
for F in $(find . -maxdepth 1 -type f -iname '*.pdf'); do
[COLOR=#FF8C00] # set BASENAME to the name of the PDF file without the .pdf extension[/COLOR]
BASENAME="${F%.*}"
[COLOR=#FF8C00] # set SETTINGSSPECIFIC to the name of the file with settings for this specific PDF[/COLOR]
SETTINGSSPECIFIC="$BASENAME.txt"
[COLOR=#FF8C00] # if the SETTINGSSPECIFIC file exists[/COLOR]
if [[ -f "$SETTINGSSPECIFIC" ]]; then
[COLOR=#FF8C00] # set the settings file we'll use to the SETTINGSSPECIFIC file[/COLOR]
SETTINGSFILE="$SETTINGSSPECIFIC"
else
[COLOR=#FF8C00] # if the generic settings file exists[/COLOR]
if [[ -f "settings.txt" ]]; then
[COLOR=#FF8C00] # set the settings file we'll use to the generic settings file[/COLOR]
SETTINGSFILE=settings.txt
else
[COLOR=#FF8C00] # skip over this file (since we don't have a settings file for it)[/COLOR]
continue
fi
fi
[COLOR=#FF8C00] # set TEMPLATENAME to the first line of the settings file[/COLOR]
TEMPLATENAME=$(head -n 1 "$SETTINGSFILE")
[COLOR=#FF8C00] # if TEMPLATENAME isn't either "spread" or "neat"[/COLOR]
if [[ "$TEMPLATENAME" != "Spread" && "$TEMPLATENAME" != "Neat" ]]; then
[COLOR=#FF8C00] # skip over this PDF file (since it has a template type we didn't expect)[/COLOR]
continue
fi
[COLOR=#FF8C00] # copy all lines except the first line of the settings file to "settings.tmp" in the root of the input directory[/COLOR]
tail -n +2 "$SETTINGSFILE" > $INPUTDIR/settings.tmp
[COLOR=#FF8C00] # move the PDF file to the root of the input directory and name it "inputfile"[/COLOR]
mv "$F" $INPUTDIR/inputfile
[COLOR=#FF8C00] # create a directory for the output files of the flipbook software[/COLOR]
mkdir $INPUTDIR/outputdir
[COLOR=#FF8C00] # invoke the flipbook software with quality of 3, and tell it to make a mobile version in addition to the desktop version[/COLOR]
/Applications/FlipPDFProfessional.app/Contents/MacOS/FPCMD -f $INPUTDIR/inputfile -o $INPUTDIR/outputdir -n index.html -s $TEMPLATENAME#$INPUTDIR/settings.tmp -q 3 -m Y -d ""
[COLOR=#FF8C00] # remove the "settings.tmp" file[/COLOR]
rm $INPUTDIR/settings.tmp
[COLOR=#FF8C00] # move the PDF file back[/COLOR]
mv $INPUTDIR/inputfile "$F"
[COLOR=#FF8C00] # rename the output directory to the basename of the PDF file[/COLOR]
mv $INPUTDIR/outputdir "$BASENAME"
[COLOR=#FF8C00] # in each of the index.html files (should be two - desktop and mobile), remove the lines that set the document title to "Demo." This may not be necessary in newer versions of Flip PDF Professional[/COLOR]
find "$BASENAME" -name index.html -exec sed -i 's/<title>Demo<\/title>//g' '{}' \;
[COLOR=#FF8C00] # create the parent directory on the webroot if it doesn't exist[/COLOR]
mkdir "$WEBROOT/$D"
[COLOR=#FF8C00] # move the flibbook directory into the parent directory[/COLOR]
mv "$BASENAME" "/System/www/$D"
done
done
fi
[COLOR=#FF8C00] # change the working directory to the home directory[/COLOR]
cd ~
[COLOR=#FF8C00] # rename the input directory[/COLOR]
mv $INPUTDIR $INPUTDIRFINISHED
[COLOR=#FF8C00] # wait one minute[/COLOR]
sleep 60
done
I commented every line to explain what's happening. If you get a good code editor like TextMate or Komodo Edit (both free) to view the script it will colorize the syntax and make it easier to read.
If you don't mind having to invoke it manually when you want it run and having a terminal window show up on your screen, you can save the script with a filename ending in ".command" and then just double-click it when you want to run it. If you want it to start up with your Mac and always run in the background, you can set it up to be run by launchd. See stackoverflow.com/questions/32160108/ for that process (be sure to read the answer as well as the question).
If your web server is not on your local network, you'll probably need to send files via FTP. The script can be modified to do that. You'd probably want to have it look for a text file inside your "flipbook" directory containing the FTP password rather than coding it into the script, otherwise anyone who gained access to the script would be able to gain access to your web server files.
The script also allows for file-level control of the settings. If you wanted to use different settings for a particular PDF named "flipbook3.pdf," you would create a settings file named "flipbook3.txt" which would override the "settings.txt" file. Here is what the file structure would look like:
Code:
[FONT=courier new].../Desktop/flipbook/
|
+---Initech/
| |
| +---settings.txt
| |
| +---flipbook1.pdf [I][COLOR=#B22222]flipbook created in webroot/Initech/flipbook1 using settings.txt[/COLOR][/I]
| |
| +---flipbook2.pdf [I][COLOR=#B22222]flipbook created in webroot/Initech/flipbook2 using settings.txt[/COLOR][/I]
|
+---SoylentCorp/
|
+---settings.txt
|
+---flipbook1.pdf [I][COLOR=#B22222]flipbook created in webroot/SoylentCorp/flipbook1 using settings.txt[/COLOR][/I]
|
+---flipbook2.pdf [I][COLOR=#B22222]flipbook created in webroot/SoylentCorp/flipbook2 using settings.txt[/COLOR][/I]
|
+---[COLOR=#FF8C00]flipbook3.txt[/COLOR]
|
+---flipbook3.pdf [/FONT][COLOR=#B22222][I][FONT=courier new]flipbook created in webroot/SoylentCorp/flipbook3 using [/FONT][/I][/COLOR][COLOR=#FF8C00][I][FONT=courier new]flipbook3.txt[/FONT][/I][/COLOR]