feat: add translated PDF export with layout preservation

Adds the ability to download translated documents as PDF files while
preserving the original document layout. Key changes:

- Add apply_translations() function to merge translation JSON with UnifiedDocument
- Add generate_translated_pdf() method to PDFGeneratorService
- Add POST /api/v2/translate/{task_id}/pdf endpoint
- Add downloadTranslatedPdf() method and PDF button in frontend
- Add comprehensive unit tests (52 tests: merge, PDF generation, API endpoints)
- Archive add-translated-pdf-export proposal

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-02 12:33:31 +08:00
parent 8d9b69ba93
commit a07aad96b3
15 changed files with 2663 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
# Change: Add Translated PDF Export
## Why
The current translation feature produces JSON output files (`{filename}_translated_{lang}.json`) but does not support generating translated PDFs. Users need to download translated documents in PDF format with the original layout preserved but with translated text content. This is essential for document localization workflows where the final deliverable must be a properly formatted PDF.
## What Changes
- **PDF Generator**: Add translation parameter support to `PDFGeneratorService`
- **Translation Merger**: Create logic to merge translation JSON with UnifiedDocument
- **API Endpoint**: Add `POST /api/v2/translate/{task_id}/pdf` endpoint
- **Frontend UI**: Add "Download Translated PDF" button in TaskDetailPage
- **Batch Translation Enhancement**: Improve batch response parsing for edge cases
## Impact
- **Affected specs**: `translation`, `result-export`
- **Affected code**:
- `backend/app/services/pdf_generator_service.py` - Add translation rendering
- `backend/app/services/translation_service.py` - Add PDF generation integration
- `backend/app/routers/translate.py` - Add PDF download endpoint
- `frontend/src/pages/TaskDetailPage.tsx` - Add PDF download button
- `frontend/src/services/apiV2.ts` - Add PDF download API method
## Non-Goals
- Editing translated text before PDF export (future feature)
- Supporting formats other than PDF (Excel, Word)
- Font substitution for different target languages