feat: unify Direct Track PDF rendering and simplify export options
Backend changes: - Apply background image + invisible text layer to all Direct Track PDFs - Add CHART to regions_to_avoid for text extraction - Improve visual fidelity for native PDFs and Office documents Frontend changes: - Remove JSON, UnifiedDocument, Markdown download buttons - Simplify to 2-column layout with only Layout PDF and Reflow PDF - Remove translation JSON download and Layout PDF option - Keep only Reflow PDF for translated document downloads - Clean up unused imports (FileJson, Database, FileOutput) Archives two OpenSpec proposals: - unify-direct-track-pdf-rendering - simplify-frontend-export-options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -139,3 +139,45 @@ The system SHALL convert PyMuPDF results to UnifiedDocument with correct table c
|
||||
- **AND** extract tables with cell boundaries, content, and merge info
|
||||
- **AND** include only meaningful images in output
|
||||
|
||||
### Requirement: Direct Track Background Image Rendering
|
||||
|
||||
The system SHALL render Direct Track PDF output using a full-page background image with an invisible text overlay to preserve visual fidelity while maintaining text extractability.
|
||||
|
||||
#### Scenario: Render Direct Track PDF with background image
|
||||
- **WHEN** generating Layout PDF for a Direct Track document
|
||||
- **THEN** the system SHALL render each source PDF page as a full-page background image at 2x resolution
|
||||
- **AND** overlay invisible text elements using PDF Text Rendering Mode 3
|
||||
- **AND** the invisible text SHALL be positioned at original coordinates for accurate selection
|
||||
|
||||
#### Scenario: Handle Office documents (PPT, DOC, XLS)
|
||||
- **WHEN** processing an Office document converted to PDF
|
||||
- **THEN** the system SHALL use the same background image + invisible text approach
|
||||
- **AND** preserve all visual elements including vector graphics, gradients, and complex layouts
|
||||
- **AND** the converted PDF in result directory SHALL be used as background source
|
||||
|
||||
#### Scenario: Handle native editable PDFs
|
||||
- **WHEN** processing a native PDF through Direct Track
|
||||
- **THEN** the system SHALL use the source PDF for background rendering
|
||||
- **AND** apply the same invisible text overlay approach
|
||||
- **AND** chart regions SHALL be excluded from the text layer
|
||||
|
||||
### Requirement: Chart Region Text Exclusion
|
||||
|
||||
The system SHALL exclude text elements within chart regions from the invisible text layer to prevent duplicate content and unnecessary translation.
|
||||
|
||||
#### Scenario: Detect chart regions
|
||||
- **WHEN** classifying page elements for Direct Track
|
||||
- **THEN** the system SHALL identify elements with type CHART
|
||||
- **AND** add chart bounding boxes to regions_to_avoid list
|
||||
|
||||
#### Scenario: Exclude chart-internal text from invisible layer
|
||||
- **WHEN** rendering invisible text layer
|
||||
- **THEN** the system SHALL skip text elements whose bounding boxes overlap with chart regions
|
||||
- **AND** chart axis labels, legends, and data labels SHALL NOT be in the invisible text layer
|
||||
- **AND** these texts remain visible in the background image
|
||||
|
||||
#### Scenario: Chart text not available for translation
|
||||
- **WHEN** extracting text for translation from a Direct Track document
|
||||
- **THEN** chart-internal text SHALL NOT be included in translatable elements
|
||||
- **AND** this is expected behavior as chart labels typically don't require translation
|
||||
|
||||
|
||||
@@ -4,31 +4,27 @@
|
||||
TBD - created by archiving change fix-v2-api-ui-issues. Update Purpose after archive.
|
||||
## Requirements
|
||||
### Requirement: Export Interface
|
||||
The Export page SHALL support downloading OCR results in multiple formats using V2 task APIs, with processing track information and enhanced structure data.
|
||||
|
||||
#### Scenario: Export page uses V2 download endpoints
|
||||
- **WHEN** user selects a format and clicks export button
|
||||
- **THEN** frontend SHALL call V2 endpoint `/api/v2/tasks/{task_id}/download/{format}`
|
||||
- **AND** frontend SHALL NOT call V1 `/api/v2/export` endpoint (which returns 404)
|
||||
- **AND** file SHALL download successfully
|
||||
The Export interface in TaskDetailPage SHALL provide streamlined download options focusing on PDF formats.
|
||||
|
||||
#### Scenario: Export supports multiple formats
|
||||
- **WHEN** user exports a completed task
|
||||
- **THEN** system SHALL support downloading as TXT, JSON, Excel, Markdown, and PDF
|
||||
- **AND** each format SHALL use correct V2 download endpoint
|
||||
- **AND** downloaded files SHALL contain task OCR results
|
||||
#### Scenario: Download options for completed tasks
|
||||
- **WHEN** viewing a completed task in TaskDetailPage
|
||||
- **THEN** the download section SHALL display only two buttons: "版面 PDF" and "流式 PDF"
|
||||
- **AND** JSON, UnifiedDocument, and Markdown download buttons SHALL NOT be displayed
|
||||
- **AND** the download grid SHALL use a 2-column layout
|
||||
|
||||
#### Scenario: Export includes processing track metadata
|
||||
- **WHEN** user exports a task processed through dual-track system
|
||||
- **THEN** exported JSON SHALL include "processing_track" field indicating "ocr" or "direct"
|
||||
- **AND** SHALL include "processing_metadata" with track-specific information
|
||||
- **AND** SHALL maintain backward compatibility for clients not expecting these fields
|
||||
#### Scenario: Translation download options
|
||||
- **WHEN** viewing completed translations in TaskDetailPage
|
||||
- **THEN** each translation item SHALL display only a "流式 PDF" download button
|
||||
- **AND** translation JSON download button SHALL NOT be displayed
|
||||
- **AND** Layout PDF option for translations SHALL NOT be displayed
|
||||
- **AND** delete translation button SHALL remain available
|
||||
|
||||
#### Scenario: Export UnifiedDocument format
|
||||
- **WHEN** user requests JSON export with unified=true parameter
|
||||
- **THEN** system SHALL return UnifiedDocument structure
|
||||
- **AND** include complete element hierarchy with coordinates
|
||||
- **AND** preserve all PP-StructureV3 element types for OCR track
|
||||
#### Scenario: Backend API remains unchanged
|
||||
- **WHEN** external clients call download endpoints directly
|
||||
- **THEN** JSON, Markdown, and UnifiedDocument endpoints SHALL still function
|
||||
- **AND** translated Layout PDF endpoint SHALL still function
|
||||
- **AND** no backend changes are required for this frontend simplification
|
||||
|
||||
### Requirement: Multi-Task Export Selection
|
||||
The Export page SHALL allow users to select and export multiple tasks.
|
||||
@@ -59,13 +55,15 @@ Export settings (format, thresholds, templates) SHALL apply consistently to V2 t
|
||||
- **AND** template SHALL be passed to V2 `/tasks/{id}/download/pdf` endpoint
|
||||
|
||||
### Requirement: Enhanced PDF Export with Layout Preservation
|
||||
The PDF export SHALL accurately preserve document layout from both OCR and direct extraction tracks with correct coordinate transformation and multi-page support.
|
||||
|
||||
The PDF export SHALL accurately preserve document layout from both OCR and direct extraction tracks with correct coordinate transformation and multi-page support. For Direct Track, a background image rendering approach SHALL be used for visual fidelity.
|
||||
|
||||
#### Scenario: Export PDF from direct extraction track
|
||||
- **WHEN** exporting PDF from a direct-extraction processed document
|
||||
- **THEN** the PDF SHALL maintain exact text positioning from source
|
||||
- **AND** preserve original fonts and styles where possible
|
||||
- **AND** include extracted images at correct positions
|
||||
- **THEN** the system SHALL render source PDF pages as full-page background images at 2x resolution
|
||||
- **AND** overlay invisible text elements using PDF Text Rendering Mode 3
|
||||
- **AND** text SHALL remain selectable and searchable despite being invisible
|
||||
- **AND** visual output SHALL match source document exactly
|
||||
|
||||
#### Scenario: Export PDF from OCR track with full structure
|
||||
- **WHEN** exporting PDF from OCR-processed document
|
||||
@@ -78,20 +76,18 @@ The PDF export SHALL accurately preserve document layout from both OCR and direc
|
||||
- **THEN** system SHALL use explicit page dimensions from OCR results (not inferred from bounding boxes)
|
||||
- **AND** correctly transform Y-axis coordinates from top-left (OCR) to bottom-left (PDF/ReportLab) origin
|
||||
- **AND** prevent vertical flipping or position misalignment errors
|
||||
- **AND** handle page size variations accurately
|
||||
|
||||
#### Scenario: Support multi-page documents with varying dimensions
|
||||
- **WHEN** generating PDF from multi-page document with mixed orientations
|
||||
- **THEN** system SHALL apply correct page size for each page independently
|
||||
- **AND** support both portrait and landscape pages in same document
|
||||
- **AND** NOT use first page dimensions for all subsequent pages
|
||||
- **AND** call setPageSize() for each new page before rendering content
|
||||
#### Scenario: Direct Track PDF file size increase
|
||||
- **WHEN** generating Layout PDF for Direct Track documents
|
||||
- **THEN** the system SHALL accept increased file size due to embedded page images
|
||||
- **AND** approximately 1-2 MB per page at 2x resolution is expected
|
||||
- **AND** this trade-off is accepted for improved visual fidelity
|
||||
|
||||
#### Scenario: Single-page layout verification
|
||||
- **WHEN** user exports OCR-processed single-page document (e.g., img1.png)
|
||||
- **THEN** generated PDF text positions SHALL match original image coordinates
|
||||
- **AND** top-aligned text (e.g., headers) SHALL appear at correct vertical position
|
||||
- **AND** no content SHALL be vertically flipped or offset from expected position
|
||||
#### Scenario: Chart elements excluded from text layer
|
||||
- **WHEN** generating Layout PDF containing charts
|
||||
- **THEN** the system SHALL NOT include chart-internal text in the invisible text layer
|
||||
- **AND** chart visuals SHALL be preserved in the background image
|
||||
- **AND** chart text SHALL NOT be available for text selection or translation
|
||||
|
||||
### Requirement: Structure Data Export
|
||||
The system SHALL provide export formats that preserve document structure for downstream processing.
|
||||
|
||||
@@ -257,3 +257,48 @@ The system SHALL provide a service to merge translation data with UnifiedDocumen
|
||||
- **THEN** the system creates a modified copy
|
||||
- **AND** original UnifiedDocument remains unchanged
|
||||
|
||||
### Requirement: Translation Output as Reflow PDF
|
||||
|
||||
The system SHALL generate translated documents as reflow-layout PDFs with real visible text, separate from the Layout PDF which uses background images.
|
||||
|
||||
#### Scenario: Generate translated PDF with reflow layout
|
||||
- **WHEN** translation is completed for a document
|
||||
- **THEN** the system SHALL generate a new PDF with translated text
|
||||
- **AND** the translated PDF SHALL use reflow layout (not background image)
|
||||
- **AND** text SHALL be real visible text, not invisible overlay
|
||||
- **AND** page breaks SHALL correspond to original document pages
|
||||
|
||||
#### Scenario: Maintain page correspondence in translated output
|
||||
- **WHEN** generating translated PDF
|
||||
- **THEN** content from original page 1 SHALL appear in translated page 1
|
||||
- **AND** content from original page 2 SHALL appear in translated page 2
|
||||
- **AND** each page may have different content length but maintains page boundaries
|
||||
|
||||
#### Scenario: Chart text excluded from translation
|
||||
- **WHEN** extracting text for translation from Direct Track documents
|
||||
- **THEN** text elements within chart regions SHALL NOT be included
|
||||
- **AND** chart labels, axis text, and legends SHALL remain untranslated
|
||||
- **AND** this is expected behavior documented for users
|
||||
|
||||
### Requirement: Dual PDF Output Concept
|
||||
|
||||
The system SHALL maintain clear separation between Layout PDF (preview) and Translated PDF (output).
|
||||
|
||||
#### Scenario: Layout PDF for preview
|
||||
- **WHEN** user views a processed document before translation
|
||||
- **THEN** the Layout PDF SHALL be displayed
|
||||
- **AND** Layout PDF preserves exact visual appearance of source
|
||||
- **AND** text is invisible overlay for extraction purposes only
|
||||
|
||||
#### Scenario: Translated PDF for final output
|
||||
- **WHEN** user requests translated document
|
||||
- **THEN** the Translated PDF SHALL be generated
|
||||
- **AND** Translated PDF uses reflow layout with visible translated text
|
||||
- **AND** original visual styling is not preserved (text-focused output)
|
||||
|
||||
#### Scenario: Both PDFs available after translation
|
||||
- **WHEN** translation is completed
|
||||
- **THEN** both Layout PDF and Translated PDF SHALL be available for download
|
||||
- **AND** user can choose which version to download
|
||||
- **AND** Layout PDF remains unchanged after translation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user