A fast, reliable command-line tool for converting EPUB files to PDF, written in Go.
- 📖 Full EPUB Support - Parses EPUB 2 and EPUB 3 formats
- 🎨 Preserves Styling - Maintains CSS styling and formatting
- 🖼️ Image Embedding - Embeds all images including covers as base64
- 📐 Flexible Page Sizes - A4, A5, A3, Letter, Legal, Tabloid
- 🔄 Orientation Options - Portrait or landscape mode
- ⚡ Fast Conversion - Uses headless Chrome for accurate rendering
- 🖥️ Cross-Platform - Works on Linux, macOS, and Windows
brew tap vib795/tap
brew install epub2pdfTo update to the latest version:
brew update
brew upgrade epub2pdfgo install github.com/vib795/epub2pdf@latestDownload the latest binary for your platform from the Releases page:
| Platform | Download |
|---|---|
| macOS (Apple Silicon) | epub2pdf_x.x.x_darwin_arm64.tar.gz |
| macOS (Intel) | epub2pdf_x.x.x_darwin_amd64.tar.gz |
| Linux (x64) | epub2pdf_x.x.x_linux_amd64.tar.gz |
| Linux (ARM64) | epub2pdf_x.x.x_linux_arm64.tar.gz |
| Windows (x64) | epub2pdf_x.x.x_windows_amd64.zip |
Extract and move to your PATH:
tar -xzf epub2pdf_*.tar.gz
sudo mv epub2pdf /usr/local/bin/git clone https://github.com/vib795/epub2pdf.git
cd epub2pdf
make build
sudo mv bin/epub2pdf /usr/local/bin/epub2pdf requires Chrome or Chromium for PDF rendering.
- macOS: Chrome is usually pre-installed, or run
brew install --cask chromium - Linux:
sudo apt install chromium-browserorsudo dnf install chromium - Windows: Download from google.com/chrome
# Convert EPUB to PDF (outputs book.pdf)
epub2pdf book.epub
# Specify output path
epub2pdf book.epub -o output.pdfepub2pdf [flags] <input.epub>
Flags:
-o, --output string Output PDF path (default: input name with .pdf)
-p, --page-size string Page size: A4, A5, Letter, Legal, Tabloid (default "A4")
-m, --margin float Page margin in inches (default 0.5)
-l, --landscape Use landscape orientation
--no-background Don't print background graphics
-s, --scale float Scale factor 0.1-2.0 (default 1.0)
-v, --verbose Verbose output
-h, --help Help for epub2pdf
# Convert with US Letter size
epub2pdf book.epub --page-size Letter
# Landscape orientation with custom margins
epub2pdf book.epub -l -m 0.75
# Scale down for smaller file size
epub2pdf book.epub -s 0.8
# Verbose output to see progress
epub2pdf book.epub -v# Display EPUB metadata without converting
epub2pdf info book.epubepub2pdf version- Parse EPUB: Opens the EPUB (ZIP archive), reads
container.xmlto find the OPF file - Extract Content: Parses the OPF manifest and spine to get chapters in reading order
- Embed Images: Converts all images to base64 data URIs for self-contained HTML
- Build HTML: Combines all chapters into a single styled HTML document
- Render PDF: Uses headless Chrome (via chromedp) to render HTML to PDF
epub2pdf/
├── main.go # Entry point
├── cmd/
│ ├── root.go # Main convert command
│ ├── info.go # Info subcommand
│ └── version.go # Version subcommand
├── internal/
│ ├── epub/
│ │ └── parser.go # EPUB parsing logic
│ └── converter/
│ └── converter.go # HTML to PDF conversion
├── go.mod
├── go.sum
├── Makefile
└── README.md
Make sure Chrome or Chromium is installed and accessible in your PATH.
Ensure your EPUB file contains valid image references. Run with -v for verbose output.
Use the scale option to reduce size: epub2pdf book.epub -s 0.8
MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
