22

I know from sources I do not remember anymore, that an epub file is a valid zip file containing (among other files) chapters as *.xhtml files, a manifest file content.opf and a table of contents file toc.ncx.

  • What is the file and directory structure of an unpacked epub?
  • Which files must be there (with fixed names?) and are there optional files?
  • What information is stored in the single files?

I am asking for a very basic epub file, so the version should not matter, but assume epub2 in case it makes a difference for you.

PS: I will probably ask for the content and structure of those files later, but for now I only want to know about which files are mandatory or optional and an overview what they contain, to keep the question more specific and answers short.

13

EPUB is an open format so you can find the standard specifications online. Wikipedia has a good article on the EPUB format.

If you want a brief description of the characteristics you just mentioned you can find in this article here.

Directory structure:

EpubFolderYouWant
   META-INF
      container.xml
   mimetype
   content.opf
   toc.ncx

Needed files:

mimetype
container.xml
content.opf
toc.ncx

And which information is contained in each file is described in the above mentioned article.

  • 1
    I have hundreds of EPUB files that do not have an content.opf file nor a toc.ncx. I am pretty sure those are not needed. – Anthon Dec 20 '13 at 15:22
  • 2
    @Anthon They are not needed for personal use but some retailers require a standard and use IDPF as the base of said standard, as posted above, so in a way the .opf is required but .ncx file is required for ePub 2.0. – DᴀʀᴛʜVᴀᴅᴇʀ Dec 20 '13 at 15:33
  • @Matt_2.0 I might miss something but I only see the need for a file with id="ncx", that might be often have a path toc.ncx but AFAIK any path can be specified in the href of that item. Relying on the extended navigation center to be in toc.ncx is as dangerous and unnecessary as relying on "the" opf file to be called content.opf. That some retailers use specific names and container.xml contents to accommodate their software or their work-flow does, IMHO, not make make that an EPUB standard the OP asked about. – Anthon Dec 20 '13 at 15:48
  • 1
    I think I am miss understanding your comment but an .opf file or a .ncx file can be titled anything as long as they are present. A .ncx file, per ePub 2.0 complacency requires it to be present to be validated. To be a valid ePub 3.0 or 2.0 .opf with a correct mimetype; doctype, <metadata>, <manifest> and <spine> must be present within the .opf file and the .ncx was replaced with the toc.xhtml but the .ncx is optional. – DᴀʀᴛʜVᴀᴅᴇʀ Dec 20 '13 at 16:14
7

The files and directory structure of the EPUB files is specified in the OCF (OpenContainerFormat). There are two versions are most interesting: 2.0.1 and 3.0.1. Both specify only one required file in a specific subdirectory, and that is:

META-INF/container.xml

There are some optional files that can go in that directory as well (signatures.xml, encrytpion.xml, metadata.xml, rights.xml) and a file named manifest.xml is allowed there as well.

The container.xml refers to the full path of one or more files, which names are essentially free and the directory structure as well.

Of course some programs generate EPUB files always with the same structure. That is why it might seem that you need a content.opf in the root of the EPUB (zip) file structure, but that is only a valid name in any particular EPUB if and only if it is named in a <rootfile> element in the container.xml.

The contents file (with references to the individual) HTML files which together form the e-book could be:

TOC/TableOfContents.opf

and the HTML files could be

LOTR/The_Fellowship_of_the_Ring.htm
LOTR/The_Two_Towers.htm
LOTR/The_Return_of_the_King.htm

as long as the paths of files, specified internally starting from container.xml are correct.

As Mark pointed out a mimetype file needs to be present. Actually according to the 2.0.1 spec (page 7, bottom) that file has to be the first file in the EPUB file's ZIP structure.

The only names in the root directory reserved by the 2.0.1 are mimetype and META-INF. The use of a specific folder (LOTR in the example) is recommended (to prevent collisions when there are multiple renditions), but not required.

  • The OCF also requires the file mimetype in the root as far as I can see – Mark Dec 22 '13 at 23:19
-1

An EPUB file is just a zip file. Copy mybook.epub to mybook.zip, and use your favorite zip tool to open the zip file. You should see some XHTML files and images somewhere in there, along with an OPF file, manifest, and some other control files. Windows 7+ natively treats zip files as a folder.

XHTML is similar to HTML but is more strict, and the bold and italic tags are different.

Below is a screen shot of a test2.epub I copied to test2.zip. The screenshot only shows the root dir of the epub. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.