DIM SHARED Id$
'The unique identifier used for our book, to be created automagically.
'We'll need some content to use for our book.
'For this, we're going to store some information in a few diffent arrays.
'The first array will be for the Chapters (or Pages) for the book.
'the next array will be for the information in those chapters.
'I'm making these redimable at this point so that someone could alter them to suit their needs as required.
'Now, let's toss some actual information into these Chapters.
'This information just names our chapters and helps set the order by which we'd go to them.
Chapters(0) = "Title Page"
Chapters(1) = "Chapter One"
Chapters(2) = "Chapter Two"
'And since we have a the chapters, let's toss something in them so they're not just blank...
Content(0) = "Steve's Epub Demo Book!"
Content(1) = "This is the Steve Demo for Epub creation!"
Content
(2) = "If you study it carefully, you'll see that it's not actually that hard to create or use EPUB files." + CHR$(13) + CHR$(10) + "This page is a quick demo of how we'd write more than a single line onto a page, and this is also quite a long line of text itself so that it will hopefully auto-wrap and auto-format itself to illustrate that we don't usually have to worry about such things manually -- that should be the job of our E-reader!"
'Some optional content we can toss into our book if we want.
'I'm going to include it here, but it can be stripped out if wanted.
DIM SHARED Author$: Author$
= "Steve McNeill" DIM SHARED Rights$: Rights$
= "Public Domain" DIM SHARED Publisher$: Publisher$
= "Nobody, Nowhere"
'So now we can actually make the book
MakeEpub "Steve Book" 'notice I didn't actually add the .epub extension here. We just need the book title
'First we check to make the main folders for our book
'and the basic files which define our folder structure
result = MakeFolders(book$)
'then we have to create our content file
MakeContent book$
MakeToC book$
MakeXPGT book$
MakeCSS book$
MakeChapters book$
'And here we write our actual content to our files.
PRINT #1, "<!DOCTYPE html PUBLIC ";
CHR$(34);
"-//W3C//DTD XHTML 1.1//EN";
CHR$(34);
"" PRINT #1, " ";
CHR$(34);
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
CHR$(34);
">" PRINT #1, "<html xmlns=";
CHR$(34);
"http://www.w3.org/1999/xhtml";
CHR$(34);
">" PRINT #1, " <title>Chapter 1</title>" PRINT #1, " <link rel=";
CHR$(34);
"stylesheet";
CHR$(34);
" href=";
CHR$(34);
"../Styles/stylesheet.css";
CHR$(34);
" type=";
CHR$(34);
"text/css";
CHR$(34);
" />" PRINT #1, " <link rel=";
CHR$(34);
"stylesheet";
CHR$(34);
" type=";
CHR$(34);
"application/vnd.adobe-page-template+xml";
CHR$(34);
" href=";
CHR$(34);
"../Styles/page-template.xpgt";
CHR$(34);
" />" PRINT #1, " <h3 id=";
CHR$(34);
"heading_id_2";
CHR$(34);
">"; Chapters
(i
);
"</h3>" PRINT #1, " <p>"; Content
(i
);
"</p>"
'Nothing more than a style sheet to format our pages and such.
'I'm just going to make this one about as simple as we can and center our stuff on the page.
PRINT #1, "/* Style Sheet */" PRINT #1, "/* This defines styles and classes used in the book */" PRINT #1, "body { margin-left: 5%; margin-right: 5%; margin-top: 5%; margin-bottom: 5%; text-align: justify; }" PRINT #1, "pre { font-size: x-small; }" PRINT #1, "h1 { text-align: center; }" PRINT #1, "h2 { text-align: center; }" PRINT #1, "h3 { text-align: center; }" PRINT #1, "h4 { text-align: center; }" PRINT #1, "h5 { text-align: center; }" PRINT #1, "h6 { text-align: center; }" PRINT #1, " text-align:center;" PRINT #1, " margin-top:0px;" PRINT #1, " margin-bottom:0px;" PRINT #1, " padding:0px;" PRINT #1, ".center {text-align: center;}" PRINT #1, ".smcap {font-variant: small-caps;}" PRINT #1, ".u {text-decoration: underline;}" PRINT #1, ".bold {font-weight: bold;}"
'page-template.xpgt
'This file isn't part of the IDPF spec, but Adobe Digital Editions uses it for formatting
'and setting column settings and whatnot.
'You don't need this file at all, but your book will look nicer in Digital Editions if you include it.
'Other readers should just ignore it.
PRINT #1, "<ade:template xmlns=";
CHR$(34);
"http://www.w3.org/1999/xhtml";
CHR$(34);
" xmlns:ade=";
CHR$(34);
"http://ns.adobe.com/2006/ade";
CHR$(34);
"" PRINT #1, " xmlns:fo=";
CHR$(34);
"http://www.w3.org/1999/XSL/Format";
CHR$(34);
">" PRINT #1, " <fo:layout-master-set>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"single_column";
CHR$(34);
">" PRINT #1, " <fo:region-body margin-bottom=";
CHR$(34);
"3pt";
CHR$(34);
" margin-top=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-left=";
CHR$(34);
"3pt";
CHR$(34);
" margin-right=";
CHR$(34);
"3pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"single_column_head";
CHR$(34);
">" PRINT #1, " <fo:region-before extent=";
CHR$(34);
"8.3em";
CHR$(34);
"/>" PRINT #1, " <fo:region-body margin-bottom=";
CHR$(34);
"3pt";
CHR$(34);
" margin-top=";
CHR$(34);
"6em";
CHR$(34);
" margin-left=";
CHR$(34);
"3pt";
CHR$(34);
" margin-right=";
CHR$(34);
"3pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"two_column";
CHR$(34);
" margin-bottom=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-top=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-left=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-right=";
CHR$(34);
"0.5em";
CHR$(34);
">" PRINT #1, " <fo:region-body column-count=";
CHR$(34);
"2";
CHR$(34);
" column-gap=";
CHR$(34);
"10pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"two_column_head";
CHR$(34);
" margin-bottom=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-left=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-right=";
CHR$(34);
"0.5em";
CHR$(34);
">" PRINT #1, " <fo:region-before extent=";
CHR$(34);
"8.3em";
CHR$(34);
"/>" PRINT #1, " <fo:region-body column-count=";
CHR$(34);
"2";
CHR$(34);
" margin-top=";
CHR$(34);
"6em";
CHR$(34);
" column-gap=";
CHR$(34);
"10pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"three_column";
CHR$(34);
" margin-bottom=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-top=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-left=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-right=";
CHR$(34);
"0.5em";
CHR$(34);
">" PRINT #1, " <fo:region-body column-count=";
CHR$(34);
"3";
CHR$(34);
" column-gap=";
CHR$(34);
"10pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:simple-page-master master-name=";
CHR$(34);
"three_column_head";
CHR$(34);
" margin-bottom=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-top=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-left=";
CHR$(34);
"0.5em";
CHR$(34);
" margin-right=";
CHR$(34);
"0.5em";
CHR$(34);
">" PRINT #1, " <fo:region-before extent=";
CHR$(34);
"8.3em";
CHR$(34);
"/>" PRINT #1, " <fo:region-body column-count=";
CHR$(34);
"3";
CHR$(34);
" margin-top=";
CHR$(34);
"6em";
CHR$(34);
" column-gap=";
CHR$(34);
"10pt";
CHR$(34);
"/>" PRINT #1, " </fo:simple-page-master>" PRINT #1, " <fo:page-sequence-master>" PRINT #1, " <fo:repeatable-page-master-alternatives>" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"three_column_head";
CHR$(34);
" page-position=";
CHR$(34);
"first";
CHR$(34);
" ade:min-page-width=";
CHR$(34);
"80em";
CHR$(34);
"/>" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"three_column";
CHR$(34);
" ade:min-page-width=";
CHR$(34);
"80em";
CHR$(34);
"/>" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"two_column_head";
CHR$(34);
" page-position=";
CHR$(34);
"first";
CHR$(34);
" ade:min-page-width=";
CHR$(34);
"50em";
CHR$(34);
"/>" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"two_column";
CHR$(34);
" ade:min-page-width=";
CHR$(34);
"50em";
CHR$(34);
"/>" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"single_column_head";
CHR$(34);
" page-position=";
CHR$(34);
"first";
CHR$(34);
" />" PRINT #1, " <fo:conditional-page-master-reference master-reference=";
CHR$(34);
"single_column";
CHR$(34);
"/>" PRINT #1, " </fo:repeatable-page-master-alternatives>" PRINT #1, " </fo:page-sequence-master>" PRINT #1, " </fo:layout-master-set>" PRINT #1, " <ade:styling-rule selector=";
CHR$(34);
".title_box";
CHR$(34);
" display=";
CHR$(34);
"adobe-other-region";
CHR$(34);
" adobe-region=";
CHR$(34);
"xsl-region-before";
CHR$(34);
"/>" PRINT #1, " </ade:style>" PRINT #1, "</ade:template>"
'this is the table of Contents for our book.
'Note that not all e-readers will use (or even look for) this file.
'For those that do, it makes us a nice little table of contents at the front of our book
'for ease of navigation and jumping to different chapters.
PRINT #1, "<ncx xmlns=";
CHR$(34);
"http://www.daisy.org/z3986/2005/ncx/";
CHR$(34);
" version=";
CHR$(34);
"2005-1";
CHR$(34);
">" PRINT #1, " <meta name=";
CHR$(34);
"dtb:totalPageCount";
CHR$(34);
" content=";
CHR$(34);
"0";
CHR$(34);
"/>" PRINT #1, " <meta name=";
CHR$(34);
"dtb:maxPageNumber";
CHR$(34);
" content=";
CHR$(34);
"0";
CHR$(34);
"/>" PRINT #1, " <text>"; book$;
"</text>" PRINT #1, " <text>"; Chapters
(i
);
"</text>" PRINT #1, " <content src=";
CHR$(34);
"Text/"; Chapters
(i
);
".xhtml";
CHR$(34);
"/>"
'This file gives a list of all files in the .epub container, defines the order of files,
'and stores meta data (author, genre, publisher, etc.) information.
PRINT #1, "<package xmlns=";
CHR$(34);
"http://www.idpf.org/2007/opf";
CHR$(34);
" unique-identifier=";
CHR$(34);
"BookID";
CHR$(34);
" version=";
CHR$(34);
"2.0";
CHR$(34);
" >" PRINT #1, " <metadata xmlns:dc=";
CHR$(34);
"http://purl.org/dc/elements/1.1/";
CHR$(34);
" xmlns:opf=";
CHR$(34);
"http://www.idpf.org/2007/opf";
CHR$(34);
">" PRINT #1, " <dc:title>"; book$;
"</dc:title>" PRINT #1, " <dc:language>"; Language$;
"</dc:language>" 'PRINT #1, " <dc:rights>"; Rights$; "</dc:rights>"
'PRINT #1, " <dc:creator opf:role="; CHR$(34); "aut"; CHR$(34); ">"; Author$; "</dc:creator>"
'PRINT #1, " <dc:publisher>"; Publisher$; "</dc:publisher>"
'Now for the next part here, each book needs to have an unique identifier.
'To keep this simple, I'm going to name these books after QB64 with a date and time included
PRINT #1, " <dc:identifier id=";
CHR$(34);
"BookID";
CHR$(34);
" opf:scheme=";
CHR$(34);
"UUID";
CHR$(34);
">"; Id$;
"</dc:identifier>"
'Next comes the manifest. This is just a listing of the files in the .epub container, and their file type.
'Each item is also assigned an item ID that's used in the spine section of content.opf.
'This list does not have to be in any particular order.
'(But you'll be happier if it is.)
'Also, see the section below on the NCX file for more information on the id attribute.
'And now we identify the types of files which we're using in the book
PRINT #1, " <item id=";
CHR$(34);
"ncx";
CHR$(34);
" href=";
CHR$(34);
"toc.ncx";
CHR$(34);
" media-type=";
CHR$(34);
"application/x-dtbncx+xml";
CHR$(34);
" />" PRINT #1, " <item id=";
CHR$(34);
"style";
CHR$(34);
" href=";
CHR$(34);
"Styles/stylesheet.css";
CHR$(34);
" media-type=";
CHR$(34);
"text/css";
CHR$(34);
" />" PRINT #1, " <item id=";
CHR$(34);
"pagetemplate";
CHR$(34);
" href=";
CHR$(34);
"Styles/page-template.xpgt";
CHR$(34);
" media-type=";
CHR$(34);
"application/vnd.adobe-page-template+xml";
CHR$(34);
" />" PRINT #1, " <item id=";
CHR$(34); Chapters
(i
);
CHR$(34);
" href=";
CHR$(34);
"Text/"; Chapters
(i
);
".xhtml";
CHR$(34);
" media-type=";
CHR$(34);
"application/xhtml+xml";
CHR$(34);
" />" 'If we included any images (which should be PNG format and thus not easily exported in QB64-GL edition yet
'They would basically be included as the following format
' <item id="imgl" href="images/sample.png" media-type="image/png" />
'Since we've now identified the page types, let's tell whatever E-Reader we're using
'the proper order to read the pages/chapters in.
'The spine section lists the reading order of the contents.
'The spine doesn't have to list every file in the manifest, just the reading order.
'For example, if the manifest lists images, they do not have to be listed in the spine, and in fact, can't be.
'Only content (i.e. the XHTML files) can be listed here.
PRINT #1, " <itemref idref=";
CHR$(34); Chapters
(i
);
CHR$(34);
" />" 'And at this point we should now have our table of contents and such written so we now know the proper order
'to read our book in. ;)
'Returns a 0 if we fail, -1 if we succeed.
'This should create our main folder structure, and write the basic files needed for EPUB support.
'This will create the mimetype and container.xml files for us since they shouldn't change
'and are mainly used to help our OS know where and what type of folders we're using for EPUB format.
PRINT "Warning: Directory already exists. Using this name will overwrite or alter existing files inside this folder. Do you wish to proceed? (Y/N)" p$ = mainfolder$ + "\"
PRINT #1, "application/epub+zip" PRINT #1, "<container version=";
CHR$(34);
"1.0";
CHR$(34);
" xmlns=";
CHR$(34);
"urn:oasis:names:tc:opendocument:xmlns:container";
CHR$(34);
">" PRINT #1, " <rootfile full-path=";
CHR$(34);
"OEBPS/content.opf";
CHR$(34);
" media-type=";
CHR$(34);
"application/oebps-package+xml";
CHR$(34);
"/>" PRINT #1, " </rootfiles>" MakeFolders = -1