mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 19:10:47 +02:00
feat(conversion): add PDF to EPUB/AZW3 conversion support and settings (#5434)
# Description of Changes This pull request introduces support for converting PDF files to eBook formats (EPUB and AZW3) in the frontend. It adds new user interface options for PDF-to-eBook conversion, updates the conversion logic and parameters, and ensures the new formats are integrated into the conversion matrix and endpoints. The most important changes are grouped below: **PDF to eBook (EPUB/AZW3) Conversion Support** * Added a new `ConvertToEpubSettings` component that provides UI controls for PDF-to-eBook options, including chapter detection, target device selection, and output format. (`frontend/src/core/components/tools/convert/ConvertToEpubSettings.tsx`) * Updated `ConvertSettings` to render the new eBook options when converting from PDF to EPUB or AZW3, and set default values for these options. (`frontend/src/core/components/tools/convert/ConvertSettings.tsx`) * Extended the `ConvertParameters` interface and default parameters to include `epubOptions` for the new settings. (`frontend/src/core/hooks/tools/convert/useConvertParameters.ts`) **Conversion Logic and API Integration** * Updated the conversion endpoints, endpoint names, and conversion matrix to support PDF-to-EPUB/AZW3 conversions. (`frontend/src/core/constants/convertConstants.ts`) * Modified the conversion operation logic to handle `epubOptions` and ensure that PDF-to-eBook conversions process each file separately and send the correct options to the backend. (`frontend/src/core/hooks/tools/convert/useConvertOperation.ts`) **Localization and Tool Registry Updates** * Added localization strings for the new eBook conversion options. (`frontend/public/locales/en-GB/translation.toml`) * Registered the new PDF-to-eBook operation in the tool catalog and test helpers. (`frontend/src/core/data/useTranslatedToolRegistry.tsx`, `frontend/src/core/tests/helpers/conversionEndpointDiscovery.ts`) <img width="364" height="995" alt="image" src="https://github.com/user-attachments/assets/c54c50c0-1b86-4074-aef8-b038c6caeb49" /> <!-- 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) - [X] 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 <[email protected]> Co-authored-by: Anthony Stirling <[email protected]>
This commit is contained in:
co-authored by
Anthony Stirling
parent
e7b030e6b5
commit
b00bd760c8
@@ -37,6 +37,7 @@ export const CONVERSION_ENDPOINTS = {
|
||||
'cbr-pdf': '/api/v1/convert/cbr/pdf',
|
||||
'pdf-cbr': '/api/v1/convert/pdf/cbr',
|
||||
'ebook-pdf': '/api/v1/convert/ebook/pdf',
|
||||
'pdf-epub': '/api/v1/convert/pdf/epub',
|
||||
'pdf-text-editor': '/api/v1/convert/pdf/text-editor',
|
||||
'text-editor-pdf': '/api/v1/convert/text-editor/pdf'
|
||||
} as const;
|
||||
@@ -61,6 +62,7 @@ export const ENDPOINT_NAMES = {
|
||||
'ebook-pdf': 'ebook-to-pdf',
|
||||
'cbr-pdf': 'cbr-to-pdf',
|
||||
'pdf-cbr': 'pdf-to-cbr',
|
||||
'pdf-epub': 'pdf-to-epub',
|
||||
'pdf-text-editor': 'pdf-to-text-editor',
|
||||
'text-editor-pdf': 'text-editor-to-pdf'
|
||||
} as const;
|
||||
@@ -124,13 +126,15 @@ export const TO_FORMAT_OPTIONS = [
|
||||
{ value: 'webp', label: 'WEBP', group: 'Image' },
|
||||
{ value: 'html', label: 'HTML', group: 'Web' },
|
||||
{ value: 'xml', label: 'XML', group: 'Web' },
|
||||
{ value: 'epub', label: 'EPUB', group: 'eBook' },
|
||||
{ value: 'azw3', label: 'AZW3', group: 'eBook' },
|
||||
];
|
||||
|
||||
// Conversion matrix - what each source format can convert to
|
||||
export const CONVERSION_MATRIX: Record<string, string[]> = {
|
||||
'any': ['pdf'], // Mixed files always convert to PDF
|
||||
'image': ['pdf'], // Multiple images always convert to PDF
|
||||
'pdf': ['png', 'jpg', 'gif', 'tiff', 'bmp', 'webp', 'docx', 'odt', 'pptx', 'odp', 'csv', 'txt', 'rtf', 'md', 'html', 'xml', 'pdfa', 'cbz', 'cbr'],
|
||||
'pdf': ['png', 'jpg', 'gif', 'tiff', 'bmp', 'webp', 'docx', 'odt', 'pptx', 'odp', 'csv', 'txt', 'rtf', 'md', 'html', 'xml', 'pdfa', 'cbz', 'cbr', 'epub', 'azw3'],
|
||||
'cbz': ['pdf'],
|
||||
'docx': ['pdf'], 'doc': ['pdf'], 'odt': ['pdf'],
|
||||
'xlsx': ['pdf'], 'xls': ['pdf'], 'ods': ['pdf'],
|
||||
@@ -159,7 +163,8 @@ export const EXTENSION_TO_ENDPOINT: Record<string, Record<string, string>> = {
|
||||
'html': 'pdf-to-html', 'xml': 'pdf-to-xml',
|
||||
'pdfa': 'pdf-to-pdfa',
|
||||
'cbr': 'pdf-to-cbr',
|
||||
'cbz': 'pdf-to-cbz'
|
||||
'cbz': 'pdf-to-cbz',
|
||||
'epub': 'pdf-to-epub', 'azw3': 'pdf-to-epub'
|
||||
},
|
||||
'cbz': { 'pdf': 'cbz-to-pdf' },
|
||||
'docx': { 'pdf': 'file-to-pdf' }, 'doc': { 'pdf': 'file-to-pdf' }, 'odt': { 'pdf': 'file-to-pdf' },
|
||||
|
||||
Reference in New Issue
Block a user