| Dynamically create a FlipBook using ASP |
|
This chapter describes how you can create FlipViewer® books dynamically by linking them to your database
using the ASP scripting language. For this section, we will be using active server pages to do our work for us. The OPF files can be output by
your ASP server.
|
| |
|
In this first lesson we will learn how to read jpeg or html files existing in a directory and create an OPF file
that FlipViewer® can open to view these files...
|
| |
Firstly let me show you how the first part of the opf can be created.
We start as usual by interfacing with the DB(in this case MS Access 2000) and use a DSNless connection to
do so(you can also use DSN to connect):
|
| |
Set conn =
Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & Server.MapPath("opf.mdb")
conn.Open DSNtemp
sqltemp="select * from fileinfo"
set rstemp=conn.execute(sqltemp)
'setup the file for writing to.
whichFN=server.mappath("example.opf")
Set fstemp = server.CreateObject("Scripting.FileSystemObject")
Set filetemp = fstemp.CreateTextFile(whichFN, true)
' true = file can be over-written if it exists
' false = file CANNOT be over-written if it exists
filetemp.WriteLine("<package unique-identifier=""unspecified"">")
filetemp.WriteLine("<metadata><x-metadata>")
filetemp.WriteLine("<meta name=""page_inset""
content=""top: 0.03 bottom: 0.05 inner: 0.06 outer: 0.04""/>")
filetemp.WriteLine("<meta name=""centerfold""
content=""no""/>")
filetemp.WriteLine("<meta name=""openbook""
content=""no""/>")
filetemp.WriteLine("<meta name=""book_binder""
content=""numrings:0 ringtype:None""/>")
filetemp.WriteLine("</x-metadata></metadata><manifest>")
filetemp.WriteLine("<item id=""cover""
href=""files/cvFront.flp"" media-type=""application/x-flp""/>")
|
|
| |
|
The above code would take care of the first part of generating our OPF. After this, the other items in the
manifest of the OPF have to be written out to the file as well. This is where data is extracted from the Access file
and constructed as pages in the book. In this example, the front and back covers are in default files. A loop is
used to read the item location fom the database and number the items with the autonumber also obtained from the
database. The loop code is as such :
|
| |
do while not
rstemp.eof
manifest_line="<item id=""" & rstemp("itemnum")
& """ href=""" & rstemp("opflocation")
&_ """ media-type=""application/x-flp""/>"
filetemp.WriteLine(manifest_line)
rstemp.movenext loop
'this is to write out the back cover as well
as to start off the spine declarations.
filetemp.WriteLine("<item id=""back""
href=""files/cvBack.flp"" media-type=""application/x-flp""/>")
filetemp.WriteLine("</manifest>")
filetemp.WriteLine("<spine>")
filetemp.WriteLine("<itemref pageside=""right""
centerfold=""no"" index=""""
idref=""cover""/>")
|
|
| |
|
Another loop follows this line of code similiar to the above loop. This loop first returns
to the beginning of the recordset to read the autonumbers. Then it will number the spine items. As the loop is
reading from the same recordset, there is no need for it to visit the database again.
|
| |
rstemp.movefirst
do while not rstemp.eof
spine_line="<itemref centerfold=""no""
idref=""" & rstemp("itemnum") & """/>"
filetemp.WriteLine(spine_line)
rstemp.movenext
loop
|
|
| |
|
After the items
in the spine have been written out, the end tags can then be written
as follows and we have our OPF all nice and done, hot and baking for
people to browse!
|
| |
filetemp.WriteLine("<itemref
pageside=""left"" centerfold=""no""
index=""no"" idref=""back""/>")
filetemp.WriteLine("/spine>")
filetemp.WriteLine("/package>")
filetemp.Close
set filetemp=nothing
set conn=nothing
|
|
| |
|
The complete source code and example database file can be obtained
here
in zip format.
|
| |
|
If you have any further questions, please email us at:
webmaster@FlipViewer®.com
|
| |
| >> Back to Content
|