Files
OCR/openspec/changes/archive/2025-12-02-add-translated-pdf-export/tasks.md
egg a07aad96b3 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>
2025-12-02 12:33:31 +08:00

1.5 KiB

Tasks: Add Translated PDF Export

1. Backend - Translation Merger Service

  • 1.1 Create apply_translations() function in translation_service.py
  • 1.2 Implement table cell translation merging logic
  • 1.3 Add unit tests for translation merging

2. Backend - PDF Generator Enhancement

  • 2.1 Add generate_translated_pdf() method to PDFGeneratorService
  • 2.2 Load translation JSON and merge with UnifiedDocument
  • 2.3 Handle missing translations gracefully (fallback to original)
  • 2.4 Add unit tests for translated PDF generation

3. Backend - API Endpoint

  • 3.1 Add POST /api/v2/translate/{task_id}/pdf endpoint in translate.py
  • 3.2 Validate task exists and has completed translation
  • 3.3 Return appropriate errors (404 if no translation, 400 if task not complete)
  • 3.4 Add endpoint tests

4. Frontend - UI Integration

  • 4.1 Add downloadTranslatedPdf() method to apiV2.ts
  • 4.2 Add "Download Translated PDF" button in TaskDetailPage.tsx
  • 4.3 Show button only when translation status is "completed"
  • 4.4 Add loading state during PDF generation

5. Testing & Validation

  • 5.1 End-to-end test: translate document then download PDF
  • 5.2 Test with Direct track document
  • 5.3 Test with OCR track document
  • 5.4 Test with document containing tables

6. Documentation

  • 6.1 Update API documentation with new endpoint
  • 6.2 Add usage example in README if applicable