|
| 1 | +# Getting started |
| 2 | + |
| 3 | +The Readium Kotlin toolkit enables you to develop reading apps for Android and ChromeOS. It provides built-in support for multiple publication formats such as EPUB, PDF, audiobooks, and comics. |
| 4 | + |
| 5 | +:warning: Readium offers only low-level tools. You are responsible for creating a user interface for reading and managing books, as well as a data layer to store the user's publications. The Test App is an example of such integration. |
| 6 | + |
| 7 | +## Design principles |
| 8 | + |
| 9 | +The toolkit has been designed following these core tenets: |
| 10 | + |
| 11 | +* **Modular**: It is divided into separate modules that can be used independently. |
| 12 | +* **Extensible**: Integrators should be able to support a custom DRM, publication format or inject their own stylesheets without modifying the toolkit itself. |
| 13 | +* **Opiniated**: We adhere to open standards but sometimes interpret them for practicality. |
| 14 | + |
| 15 | +## Modules |
| 16 | + |
| 17 | +### Main modules |
| 18 | + |
| 19 | +* `readium-shared` contains shared `Publication` models and utilities. |
| 20 | +* `readium-streamer` parses publication files (e.g. an EPUB) into a `Publication` object. |
| 21 | +* [`readium-navigator` renders the content of a publication](navigator/navigator.md). |
| 22 | + * [`readium-navigator-media-audio` renders audiobooks](navigator/media-navigator.md) |
| 23 | + * [`readium-navigator-media-tts` renders publication with a text-to-speech engine](tts.md) |
| 24 | + |
| 25 | +### Specialized packages |
| 26 | + |
| 27 | +* `readium-opds` parses [OPDS catalog feeds](https://opds.io) (both OPDS 1 and 2). |
| 28 | +* [`readium-lcp` downloads and decrypts LCP-protected publications](lcp.md). |
| 29 | + |
| 30 | +### Adapters to third-party dependencies |
| 31 | + |
| 32 | +* `readium-adapter-exoplayer` provides an [ExoPlayer](https://exoplayer.dev) adapter for the [`AudioNavigator`](navigator/media-navigator.md). |
| 33 | +* [`readium-adapter-pdfium`](../../readium/adapters/pdfium/README.md) provides a [Pdfium](https://github.com/barteksc/AndroidPdfViewer) adapter for the [PDF Navigator](pdf.md). |
| 34 | +* [`readium-adapter-pspdfkit`](../../readium/adapters/pspdfkit/README.md) provides a [PSPDFKit](https://pspdfkit.com) adapter for the [PDF Navigator](pdf.md). |
| 35 | + |
| 36 | +## Overview of the shared models (`readium-shared`) |
| 37 | + |
| 38 | +The Readium toolkit provides models used as exchange types between packages. |
| 39 | + |
| 40 | +### Publication models |
| 41 | + |
| 42 | +#### Publication |
| 43 | + |
| 44 | +`Publication` and its sub-components represent a single publication – ebook, audiobook or comic. It is loosely based on the [Readium Web Publication Manifest](https://readium.org/webpub-manifest/). |
| 45 | + |
| 46 | +A `Publication` instance: |
| 47 | + |
| 48 | +* holds the metadata of a publication, such as its author or table of contents, |
| 49 | +* allows to read the contents of a publication, e.g. XHTML or audio resources, |
| 50 | +* provides additional services, for example content extraction or text search. |
| 51 | + |
| 52 | +#### Link |
| 53 | + |
| 54 | +A [`Link` object](https://readium.org/webpub-manifest/#24-the-link-object) holds a pointer (URL) to a resource or service along with additional metadata, such as its media type or title. |
| 55 | + |
| 56 | +The `Publication` contains several `Link` collections, for example: |
| 57 | + |
| 58 | +* `readingOrder` lists the publication resources arranged in the order they should be read. |
| 59 | +* `resources` contains secondary resources necessary for rendering the `readingOrder`, such as an image or a font file. |
| 60 | +* `tableOfContents` represents the table of contents as a tree of `Link` objects. |
| 61 | +* `links` exposes additional resources, such as a canonical link to the manifest or a search web service. |
| 62 | + |
| 63 | +#### Locator |
| 64 | + |
| 65 | +A [`Locator` object](https://readium.org/architecture/models/locators/) represents a precise location in a publication resource in a format that can be stored and shared across reading systems. It is more accurate than a `Link` and contains additional information about the location, e.g. progression percentage, position or textual context. |
| 66 | + |
| 67 | +`Locator` objects are used for various features, including: |
| 68 | + |
| 69 | +* reporting the current progression in the publication |
| 70 | +* saving bookmarks, highlights and annotations |
| 71 | +* navigating search results |
| 72 | + |
| 73 | +### Data models |
| 74 | + |
| 75 | +#### Asset |
| 76 | + |
| 77 | +An `Asset` represents a single file or package and provides access to its content. There are two types of `Asset`: |
| 78 | + |
| 79 | +* `ContainerAsset` for packages which contains several resources, such as a ZIP archive. |
| 80 | +* `ResourceAsset` for accessing a single resource, such as a JSON or PDF file. |
| 81 | + |
| 82 | +`Asset` instances are obtained through an `AssetRetriever`. |
| 83 | + |
| 84 | +You can use the `asset.format` to identify the media type and capabilities of the asset. |
| 85 | + |
| 86 | +```kotlin |
| 87 | +if (asset.format.conformsTo(Specification.Lcp)) { |
| 88 | + // The asset is protected with LCP. |
| 89 | +} |
| 90 | +if (asset.format.conformsTo(Specification.Epub)) { |
| 91 | + // The asset represent an EPUB publication. |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +#### Resource |
| 96 | + |
| 97 | +A `Resource` provides read access to a single resource, such as a file or an entry in an archive. |
| 98 | + |
| 99 | +`Resource` instances are usually created by a `ResourceFactory`. The toolkit ships with various implementations supporting different data access protocols such as local files, HTTP, Android Content Providers, etc. |
| 100 | + |
| 101 | +#### Container |
| 102 | + |
| 103 | +A `Container<Resource>` provides read access to a collection of resources. `Container` instances representing an archive are usually created by an `ArchiveOpener`. The toolkit ships with a `ZipArchiveOpener` supporting local and remote ZIP files. |
| 104 | + |
| 105 | +`Publication` objects internally use a `Container<Resource>` to expose its content. |
| 106 | + |
| 107 | +## Opening a publication (`readium-streamer`) |
| 108 | + |
| 109 | +To retrieve a `Publication` object from a publication file like an EPUB or audiobook, you can use an `AssetRetriever` and `PublicationOpener`. |
| 110 | + |
| 111 | +```kotlin |
| 112 | +// Instantiate the required components. |
| 113 | +val httpClient = DefaultHttpClient() |
| 114 | +val assetRetriever = AssetRetriever( |
| 115 | + contentResolver = context.contentResolver, |
| 116 | + httpClient = httpClient |
| 117 | +) |
| 118 | +val publicationOpener = PublicationOpener( |
| 119 | + publicationParser = DefaultPublicationParser( |
| 120 | + context, |
| 121 | + httpClient = httpClient, |
| 122 | + assetRetriever = assetRetriever, |
| 123 | + pdfFactory = PdfiumDocumentFactory(context) |
| 124 | + ) |
| 125 | +) |
| 126 | + |
| 127 | +// Retrieve an `Asset` to access the file content. |
| 128 | +val url = File("/path/to/book.epub").toUrl() |
| 129 | +val asset = assetRetriever.retrieve(url) |
| 130 | + .getOrElse { /* Failed to retrieve the Asset */ } |
| 131 | + |
| 132 | +// Open a `Publication` from the `Asset`. |
| 133 | +val publication = publicationOpener.open(asset, allowUserInteraction = true) |
| 134 | + .getOrElse { /* Failed to access or parse the publication */ } |
| 135 | + |
| 136 | +print("Opened ${publication.metadata.title}") |
| 137 | +``` |
| 138 | + |
| 139 | +The `allowUserInteraction` parameter is useful when supporting a DRM like Readium LCP. It indicates if the toolkit can prompt the user for credentials when the publication is protected. |
| 140 | + |
| 141 | +[See the dedicated user guide for more information](open-publication.md). |
| 142 | + |
| 143 | +## Accessing the metadata of a publication |
| 144 | + |
| 145 | +After opening a publication, you may want to read its metadata to insert a new entity into your bookshelf database, for instance. The `publication.metadata` object contains everything you need, including `title`, `authors` and the `published` date. |
| 146 | + |
| 147 | +You can retrieve the publication cover using `publication.cover()`. |
| 148 | + |
| 149 | +## Rendering the publication on the screen (`readium-navigator`) |
| 150 | + |
| 151 | +You can use a Readium navigator to present the publication to the user. The `Navigator` renders resources on the screen and offers APIs and user interactions for navigating the contents. |
| 152 | + |
| 153 | +Please refer to the [Navigator guide](navigator/navigator.md) for more information. |
0 commit comments