https://github.com/taylor-eos/epub-margin-remover
Automatically change margins of EPUB files
https://github.com/taylor-eos/epub-margin-remover
Last synced: about 1 year ago
JSON representation
Automatically change margins of EPUB files
- Host: GitHub
- URL: https://github.com/taylor-eos/epub-margin-remover
- Owner: Taylor-eOS
- Created: 2024-09-06T06:05:41.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-17T09:04:36.000Z (about 1 year ago)
- Last Synced: 2025-06-13T19:01:54.783Z (about 1 year ago)
- Language: Python
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EPUB CSS Margin and Padding Remover
This is a Python script to process EPUB files by removing or resetting all CSS margin and padding properties within the EPUB's CSS files. This tool is useful for users who want consistent formatting across their EPUB files, in order to not waste screen real estate on an eReader.
Warning: This script was generated by a beginner with a chatbot, and proper functionality is not guranteed. Back up your original files in case problems emerge.
## Features
- **Batch Processing**: Automatically processes all EPUB files in a folder.
- **Customizable**: You can modify the script to change the margin and padding values.
- **Non-destructive**: Creates a new processed EPUB without altering the original file.
## Requirements
- Python
- Standard Python libraries: `os`, `zipfile`, `re`, `shutil`
- `ebooklib`
Requirements can be installed via requirements.txt
## Installation
1. **Clone the Repository**
```bash
git clone https://github.com/Taylor-eOS/epub-margins
cd epub-margins
```
Or just download the `.py` file.
2. **Create a Virtual Environment**
```bash
python -m venv epub-margins
cd epub-margins
source bin/activate #On Windows: epub-margins\Scripts\activate
```
## Usage
1. **Place EPUB Files**
Copy all the EPUB files you want to process into the folder `input_files`.
2. **Run the Script**
```bash
python reduce_all_margins.py
```
3. **Processed Files**
The processed EPUB files will be saved in the `processed_epubs` directory and tell you whether the process succeeded.
Error messages about inability to add custom fields do not prevent the process, but just tell you those fields don't get added.
## How It Works
The script performs the following steps for each EPUB file:
1. **Extracts the EPUB**: Unzips the EPUB file into a temporary directory.
2. **Processes CSS Files**: Searches for all `.css` files and replaces margin and padding properties with `0 !important`.
3. **Repackages the EPUB**: Zips the processed files back into an EPUB format. (Hopefully now into a proper format.)
4. **Cleanup**: Removes the temporary directory used for processing.
## Customization
- **Changing Margin and Padding Values**
If you want to set different values for margins and padding, modify the following variables at the top of the script:
```python
NEW_MARGIN = "0 !important"
NEW_PADDING = "0 !important"
```
## Troubleshooting
- **No EPUB Files Found**
If you receive a "No EPUB files found" message, ensure that your EPUB files are in the same directory as the script.
- **Encoding Issues**
If you encounter encoding errors, you may need to adjust the file reading/writing encoding in the script.