Files
OCR/openspec/changes/archive/2025-12-02-add-translated-pdf-export/specs/result-export/spec.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

2.1 KiB

ADDED Requirements

Requirement: Translated PDF Export API

The system SHALL expose an API endpoint for downloading translated documents as PDF files.

Scenario: Download translated PDF via API

  • GIVEN a task with completed translation to English
  • WHEN POST request to /api/v2/translate/{task_id}/pdf?lang=en
  • THEN system returns PDF file with translated content
  • AND Content-Type is application/pdf
  • AND Content-Disposition suggests filename like {task_id}_translated_en.pdf

Scenario: Download translated PDF with layout preservation

  • WHEN user downloads translated PDF
  • THEN the PDF maintains original document layout
  • AND text positions match original document coordinates
  • AND images and tables appear at original positions

Scenario: Invalid language parameter

  • GIVEN a task with translation only to English
  • WHEN user requests PDF with lang=ja (Japanese)
  • THEN system returns 404 Not Found
  • AND response includes available languages in error message

Scenario: Task not found

  • GIVEN non-existent task_id
  • WHEN user requests translated PDF
  • THEN system returns 404 Not Found

Requirement: Frontend Translated PDF Download

The frontend SHALL provide UI controls for downloading translated PDFs.

Scenario: Show download button when translation complete

  • GIVEN a task with translation status "completed"
  • WHEN user views TaskDetailPage
  • THEN page displays "Download Translated PDF" button
  • AND button shows target language (e.g., "Download Translated PDF (English)")

Scenario: Hide download button when no translation

  • GIVEN a task without any completed translations
  • WHEN user views TaskDetailPage
  • THEN "Download Translated PDF" button is not shown

Scenario: Download progress indication

  • GIVEN user clicks "Download Translated PDF" button
  • WHEN PDF generation is in progress
  • THEN button shows loading state
  • AND prevents double-click
  • WHEN download completes
  • THEN browser downloads PDF file
  • AND button returns to normal state