EPUB/PDF eBook Generator from markdown

Setup

# Create conda environment
conda create -n book python=3.12 -y
conda activate book

# Install dependencies
pip install -r requirements.txt

# Install Chinese fonts (for PDF)
sudo apt-get install -y fonts-noto-cjk fonts-noto-cjk-extra

Convert Flow

Usage

conda activate book

# Set source directory
SOURCE_DIR="../book2"
OUTPUT_EPUB="../book2.epub"
OUTPUT_PDF="../book2.pdf"

# Create temp directory
rm -rf _tmp && mkdir -p _tmp

# Convert Markdown to HTML
python convert_md_to_html.py -i $SOURCE_DIR -o _tmp

# Copy images
python copy_jpg_files.py -i $SOURCE_DIR -o _tmp

# Generate EPUB
python create_epub_from_html.py -i _tmp -o $OUTPUT_EPUB

# Generate PDF
python create_pdf_from_html.py -i _tmp -o $OUTPUT_PDF

Example Code