OPF

From MobileRead
Jump to: navigation, search

OPF is the open packaging format that is defined by idpf. Version 2 and version 3 are the internal file metadata used in ePub. Some use it as an alternate name for the version 1 standard which was officially called Open eBook. MOBI, LIT, and IMP all use a version 1 OPF (.opf) in their source.

Contents

[edit] Structure

The OPF file can be located anywhere in the ePub file structure and can be named whatever you wish. In ePub there is a folder called META-INF that must always be present. Inside there must be a file call container.xml. The content of that container file points to the OPF file. It might look like:

<?xml version="1.0"?>
<container version="1.0" 
  xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
  <rootfiles>
   <rootfile full-path="Ops/content.opf" 
    media-type="application/oebps-package+xml"/>
  </rootfiles>
</container>

[edit] Specification

The Open Packaging Format (OPF) Specification, defines the mechanism by which the various components of an OPS publication are tied together and provides additional structure and semantics to the electronic publication.

Specifically, OPF:

  • Describes and references all components of the electronic publication (e.g. markup files, images, navigation structures).
  • Provides publication-level metadata. Specifically it should include dublin core formatted data with information about the eBook such as author and title.
  • Specifies the linear reading-order of the publication.
  • Provides fallback information to use when unsupported extensions to OPS are employed.
  • Provides a mechanism to specify a declarative table of contents (the NCX).
  • May provide pointers to additional optional elements such as embedded fonts.

Version 3 can contain version 2 data for backward compatibility but a version 3 reader will ignore all data not supported in version 3.

[edit] Example version 2

See ePub OPF section for one example. For an example of Version 1.2 see Open eBook Package File. Here is another 2.01 example:

<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" 
   unique-identifier="BookId">
 <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"  
     xmlns:opf="http://www.idpf.org/2007/opf">
   <dc:title>Harvard Classics Shelf Of Fiction, Vol III</dc:title>
   <dc:creator opf:file-as="(Editor), Neilson William Allan" 
     opf:role="aut">Neilson, William Allan (Editor)</dc:creator>
   <dc:subject>Novel</dc:subject>
   <dc:description>A Sentimental Journey through France and Italy by 
       Laurence Stene (a travelog novel) and Pride and Pejudice by Jane 
       Austin (Novel of manners, a satire) with bibliographic record, 
       criticisms and interpretations.</dc:description>
   <dc:publisher>Generally the publisher of eBook version.</dc:publisher>
   <dc:date>2013-12-24</dc:date>
   <dc:identifier id="BookId">AWP-77552DCD-7724-4F66-
      B1B6-07A94130BBBE</dc:identifier>
   <dc:language>en</dc:language>
   <dc:rights>public domain source first published 1917</dc:rights>
   <meta name="cover" content="cover"/>
 </metadata>
 <manifest>
  <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
  <item id="style" href="style.css" media-type="text/css"/>
  <item id="coverstyle" href="cover.css" media-type="text/css"/>
  <item id="id001" href="001.html" media-type="application/xhtml+xml"/>
  <item id="id002" href="002.html" media-type="application/xhtml+xml"/>
  <item id="cover" href="images/cover.jpg" media-type="image/jpeg"/>
  <item id="img1" href="images/img1.jpg" media-type="image/jpeg"/>
 </manifest>
 <spine toc="ncx">
  <itemref idref="id001" linear="no"/>
  <itemref idref="id002"/>
 </spine>
 <guide>
  <reference type="cover" title="Cover" href="001.html"/>
 </guide>
</package>

[edit] Example version 3

<package version="3.0" unique-identifier="pub-id" xmlns="http://www.idpf.org/2007/opf">
  <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:identifier id="pub-id">urn:uuid:A1B0D67E-2E81-4DF5-9E67-A64CBE366809</dc:identifier>
      <meta refines="#pub-id" property="identifier-type" scheme="xsd:string">uuid</meta>
    <dc:identifier id="isbn-id">urn:isbn:9780101010101</dc:identifier>
      <meta refines="#isbn-id" property="identifier-type" scheme="onix:codelist5">15</meta>
    <dc:source id="src-id">urn:isbn:9780375704024</dc:source>
      <meta refines="#src-id" property="identifier-type" scheme="onix:codelist5">15</meta>
    <dc:title id="title">Norwegian Wood</dc:title>
      <meta refines="#title" property="title-type">main</meta>
    <dc:language>en</dc:language>
    <dc:creator id="creator">Haruki Murakami</dc:creator>
      <meta refines="#creator" property="role" scheme="marc:relators" id="role">aut</meta>
      <meta refines="#creator" property="alternate-script" xml:lang="ja">村上 春樹</meta>
      <meta refines="#creator" property="file-as">Murakami, Haruki</meta>
      <meta property="dcterms:modified">2011-01-01T12:00:00Z</meta>
  </metadata>
  <manifest>
   <item id="item1" 
         href="chap1_docbook.xml" 
         media-type="application/docbook+xml" 
         fallback="fall1"/>
   <item id="fall1" 
         href="chap1.xml" 
         media-type="application/z3986-auth+xml" 
         fallback="fall2" />
   <item id="fall2" 
         href="chap1.xhtml" 
         media-type="application/xhtml+xml"/> 
   <item id="nav" 
         href="nav.xhtml" 
         properties="nav"
         media-type="application/xhtml+xml"/>
   <item id="intro" 
         href="intro.xhtml" 
         media-type="application/xhtml+xml"/>
   <item id="c1" 
         href="chap1.xhtml" 
         media-type="application/xhtml+xml"/>
   <item id="c1-answerkey" 
         href="chap1-answerkey.xhtml" 
         media-type="application/xhtml+xml"/>
   <item id="c2" 
         href="chap2.xhtml" 
         media-type="application/xhtml+xml"/> 
   <item id="notes" 
         href="notes.xhtml" 
         media-type="application/xhtml+xml"/>
   <item id="cover" 
         href="./images/cover.svg" 
         properties="cover-image"
         media-type="image/svg+xml"/>
   <item id="f1" 
         href="./images/fig1.jpg" 
         media-type="image/jpeg"/>
   <item id="f2" 
         href="./images/fig2.jpg" 
         media-type="image/jpeg"/>
   <item id="css" 
         href="./style/book.css" 
         media-type="text/css"/>   
   <item id="pls" 
         href="./speech/dict.pls" 
         media-type="application/pls+xml"/>
  </manifest>
  <spine page-progression-direction="ltr">
   <itemref idref="intro"/>
   <itemref idref="c1"/>
   <itemref idref="c1-answerkey" linear="no"/>
   <itemref idref="c2"/>
   <itemref idref="c2-answerkey" linear="no"/>
   <itemref idref="c3"/>
   <itemref idref="c3-answerkey" linear="no"/>
   <itemref idref="notes" linear="no"/>
  </spine>
</package>

[edit] Mobi specific

Mobi and the newer Kindle AZW and KF8 formats need special entries in the OPF for the TOC and Cover. You need to add the "TOC" entry in the GUIDE section of the OPF in order for the TOC option to be made available.

<guide>
  <reference href="Text/Frontmatter.html#coverpage" type="cover"/>
  <reference href="Text/Frontmatter.html#coverpage" title="Start here" 
     type="other.start"/>
  <reference href="Text/Frontmatter.html#TOC" title="Table of Contents" 
     type="toc"/>
</guide>

The OPF file can be used to create an eBook using MobiPocket Creator or KindleGen simply by using it as the starting point for the compiler. It will find the other files necessary by parsing this file.

[edit] Unique id

The web site http://www.famkruithof.net/uuid/uuidgen can provide a unique id for an eBook as needed in the OPF.

Personal tools
Namespaces

Variants
Actions
Navigation
MobileRead Networks
Toolbox