https://github.com/witekbobrowski/epubkit
๐ Simple EPUB Parser in Swift
https://github.com/witekbobrowski/epubkit
cocoapods epub hacktoberfest ios library macos parser spm swift swift-library swift-package-manager tvos
Last synced: 3 months ago
JSON representation
๐ Simple EPUB Parser in Swift
- Host: GitHub
- URL: https://github.com/witekbobrowski/epubkit
- Owner: witekbobrowski
- License: mit
- Created: 2017-06-13T09:23:09.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-06-19T13:57:36.000Z (7 months ago)
- Last Synced: 2025-10-21T10:53:14.599Z (3 months ago)
- Topics: cocoapods, epub, hacktoberfest, ios, library, macos, parser, spm, swift, swift-library, swift-package-manager, tvos
- Language: Swift
- Homepage:
- Size: 3.44 MB
- Stars: 263
- Watchers: 7
- Forks: 36
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

A powerful and modern Swift library for parsing EPUB documents
EPUBKit provides a comprehensive solution for parsing and extracting information from EPUB files in Swift. Built with modern Swift practices and designed for reliability, it supports both EPUB 2 and EPUB 3 specifications while maintaining a clean, intuitive API.
## Features
- ๐ **Complete EPUB Support**: Full parsing of EPUB 2 and EPUB 3 documents
- ๐๏ธ **Modern Swift**: Built with Swift 6+, leveraging modern language features
- ๐ **Rich Metadata**: Extract comprehensive Dublin Core metadata
- ๐๏ธ **Manifest Parsing**: Access all publication resources with media type detection
- ๐ **Reading Order**: Parse spine for linear reading progression
- ๐งญ **Navigation**: Extract table of contents and navigation structure
- ๐งช **Thoroughly Tested**: Comprehensive test suite built with Swift Testing
- ๐ฏ **Thread Safe**: Designed for concurrent parsing operations
## Installation
### Swift Package Manager
Add EPUBKit to your project via Xcode or by adding it to your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/witekbobrowski/EPUBKit.git", from: "1.0.0")
]
```
### CocoaPods
```ruby
pod 'EPUBKit'
```
## Quick Start
### Basic Usage
```swift
import EPUBKit
// Parse an EPUB file
guard let epubURL = Bundle.main.url(forResource: "book", withExtension: "epub"),
let document = EPUBDocument(url: epubURL) else {
print("Failed to load EPUB")
return
}
// Access document metadata
print("Title: \(document.title)")
print("Author: \(document.author)")
print("Publisher: \(document.publisher)")
print("Language: \(document.language)")
// Access document structure
print("Chapters: \(document.spine.items.count)")
print("Resources: \(document.manifest.items.count)")
```
### Working with Document Components
```swift
// Access metadata details
if let creator = document.metadata.creator {
print("Author: \(creator.name)")
print("Role: \(creator.role)")
print("File as: \(creator.fileAs)")
}
// Iterate through spine items (reading order)
for spineItem in document.spine.items {
if let manifestItem = document.manifest.items[spineItem.idref] {
print("Chapter: \(manifestItem.path)")
print("Media Type: \(manifestItem.mediaType)")
}
}
// Access table of contents
func printTOC(_ toc: EPUBTableOfContents, level: Int = 0) {
let indent = String(repeating: " ", count: level)
print("\(indent)- \(toc.label)")
for child in toc.children {
printTOC(child, level: level + 1)
}
}
printTOC(document.tableOfContents)
```
## EPUB Specification Support
EPUBKit supports the EPUB specification standards:
- โ
**EPUB 3.3** - Full support for modern EPUB files
- โ
**EPUB 2.0** - Backward compatibility with older EPUB files
- โ
**Dublin Core Metadata** - Complete metadata extraction
- โ
**OCF (Open Container Format)** - Proper ZIP archive handling
- โ
**NCX Navigation** - Table of contents parsing
- โ
**Media Type Detection** - Automatic resource type identification
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
EPUBKit is available under the MIT license. See the [LICENSE](LICENSE) file for more info.