Stirling-PDF/app
Balázs Szücs 97f3b88222
feat(pdf-EPUB): add PDF to EPUB/AZW3 conversion functionality via Calibre (#4947)
# Description of Changes

This PR introduces a new conversion tool allowing users to convert PDF
documents into EPUB format. This is particularly useful for reading
documents on e-readers (like Kindles or Kobos) where standard PDFs often
suffer from fixed formatting and unreadable text sizes.

The implementation leverages the existing **Calibre** integration
(`ebook-convert`) to produce reflowable e-books with specific
optimizations for layout and chapter structure.

**Backend Implementation**
* Added `ConvertPDFToEpubController` to handle the conversion workflow.
* Created `ConvertPdfToEpubRequest` to support new conversion parameters
(Device profile and Chapter detection).
* Integrated standard Stirling-PDF temporary file management and process
execution patterns.

**Frontend & UI**
* Added a new view `pdf-to-epub.html` containing the upload form and
configuration options.
* Updated `navElements.html` and `messages.properties` to expose the
tool in the navigation menu under the "Convert" group.
* Minor cleanup of HTML formatting in the existing `ebook-to-pdf`
template for consistency.

**Configuration & Testing**
* Registered the `pdf-to-epub` endpoint in `EndpointConfiguration`,
placing it under the **Calibre** dependency group.
* Added comprehensive unit tests covering command generation, parameter
handling, and temporary file cleanup.


The conversion process utilizes specific calibre, `ebook-convert` flags
to ensure high-quality output:

* **Heuristic Processing** (`--enable-heuristics`): Automatically
detects and fixes common PDF scanning issues, such as broken lines,
hyphens at line ends, and inconsistent paragraph spacing.
* **CSS Filtering** (`--filter-css`): Strips hardcoded styling (font
families, fixed margins, colors) from the PDF. This ensures the
resulting EPUB respects the user's e-reader settings (font size, dark
mode, etc.).
* **Smart Chapter Detection** (`--chapter`): Optionally uses an XPath
expression (`//h:*[re:test(., '\\s*Chapter\\s+', 'i')]`) to detect
headers and insert proper page breaks in the EPUB structure.
* **Device Optimization Profiles**:
* **Tablet/Phone:** Uses the default profile to maintain image
resolution and color.
* **Kindle/E-Ink:** Uses a specific profile to resize images and
optimize contrast for grayscale screens.



<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [X] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [X] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [X] I have performed a self-review of my own code
- [X] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [X] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
2025-11-25 10:02:50 +00:00
..
common refactor(common): remove unused temp directory & HTML unzip helpers, prune imports (#4857) 2025-11-25 09:54:31 +00:00
core feat(pdf-EPUB): add PDF to EPUB/AZW3 conversion functionality via Calibre (#4947) 2025-11-25 10:02:50 +00:00
proprietary build(deps): bump io.swagger.core.v3:swagger-core-jakarta from 2.2.40 to 2.2.41 (#4979) 2025-11-25 09:43:55 +00:00
allowed-licenses.json feat(cbr-to-pdf,pdf-to-cbr): add PDF to/from CBR conversion with ebook optimization option (#4581) 2025-10-04 11:15:23 +01:00