Skip to content

Commit

Permalink
refactor: Enhance dual PDF page rendering configuration
Browse files Browse the repository at this point in the history
- Support configurable page order in dual page generation
- Improve flexibility of side-by-side PDF rendering logic
  • Loading branch information
awwaawwa committed Feb 21, 2025
1 parent 981f6dd commit cecde9a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions babeldoc/document_il/backend/pdf_creater.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,20 @@ def write(self, translation_config: TranslationConfig) -> TranslateResult:
dual_page = dual.new_page(width=total_width, height=max_height)

# Define rectangles for left and right sides
rect_left = pymupdf.Rect(0, 0, orig_page.rect.width, max_height)
rect_right = pymupdf.Rect(
orig_page.rect.width,
0,
total_width,
max_height,
left_width = (
orig_page.rect.width
if not translation_config.dual_translate_first
else trans_page.rect.width
)
rect_left = pymupdf.Rect(0, 0, left_width, max_height)
rect_right = pymupdf.Rect(left_width, 0, total_width, max_height)

# Show original page on left and translated on right
# Show pages according to dual_translate_first setting
if translation_config.dual_translate_first:
# Show translated page on left and original on right
rect_left, rect_right = rect_right, rect_left

# Show original page on left and translated on right (default)
dual_page.show_pdf_page(
rect_left,
original_pdf,
Expand Down

0 comments on commit cecde9a

Please sign in to comment.