Skip to content

(Feature) Add Duplex sort / collate documents (Fixes #220)#752

Open
r0ckarong wants to merge 6 commits into
alam00000:mainfrom
r0ckarong:duplex-pr-clean
Open

(Feature) Add Duplex sort / collate documents (Fixes #220)#752
r0ckarong wants to merge 6 commits into
alam00000:mainfrom
r0ckarong:duplex-pr-clean

Conversation

@r0ckarong

@r0ckarong r0ckarong commented Jun 16, 2026

Copy link
Copy Markdown

Description

image

The new tool takes a PDF that contains the contents of a duplex scan (all front sides, all back sides) and sorts them into the correct "per document" order. It also allows saving the respective documents as separate files.

The tool also corrects the orientation of the scanned page block if the stack was inserted the wrong way on the second pass.

Fixes #220

Type of change

  • New feature (non-breaking change which adds functionality)

🧪 How Has This Been Tested?

Checklist:

  • Verified output manually
  • Tested with relevant sample documents or data
  • Wrote Vite Test Case (if applicable)

Expected Results:

  • Input document Front1, Front2, Front3, Back3, Back2, Back1 is moved into the correct order with Front1, Back1 ...

Actual Results:

  • Document is correctly re-ordered.
  • Document also separated "per document" PDF for Zip download.

Checklist:

  • I have signed the Contributor License Agreement (CLA) or my organization has signed the Corporate CLA
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

FRONT11_collated_grouped.zip
FRONT11_collated.pdf
FRONT11.pdf

Summary by CodeRabbit

Summary

  • New Features
    • Added Duplex Collate to the tools grid with a new duplex-collate page for front/back interleaving.
    • Supports configurable split point, back-block order, and optional grouped export.
    • Added English/German localization for the tool.
  • Documentation
    • Added a Duplex Collate documentation page and updated the tools sidebar/navigation.
  • Tests
    • Added unit tests for duplex page interleaving behavior.
  • Chores
    • Updated the pre-commit lint command and pinned the Node.js version.
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd39f8eb-2c7a-4871-a73a-7c862ea0eb2b

📥 Commits

Reviewing files that changed from the base of the PR and between feaa7dd and ad5811e.

📒 Files selected for processing (14)
  • .husky/pre-commit
  • .nvmrc
  • docs/.vitepress/config.mts
  • docs/tools/duplex-collate.md
  • docs/tools/index.md
  • pdf-merge-split.html
  • public/locales/de/tools.json
  • public/locales/en/tools.json
  • src/js/config/tools.ts
  • src/js/logic/duplex-collate-page.ts
  • src/js/main.ts
  • src/pages/duplex-collate.html
  • src/tests/duplex-collate.test.ts
  • tools.html
✅ Files skipped from review due to trivial changes (4)
  • .husky/pre-commit
  • .nvmrc
  • public/locales/de/tools.json
  • docs/tools/index.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • docs/.vitepress/config.mts
  • docs/tools/duplex-collate.md
  • src/js/main.ts
  • tools.html
  • public/locales/en/tools.json
  • src/tests/duplex-collate.test.ts
  • pdf-merge-split.html

📝 Walkthrough

Walkthrough

Adds a new "Duplex Collate" tool to BentoPDF that reorders ADF-scanned PDFs from block front/back order into interleaved reading order. The tool registers itself in the tool config, catalog pages, i18n locale files (en/de), and translation key map. A new duplex-collate.html page template provides the upload UI and options panel. duplex-collate-page.ts implements buildDuplexOrder and the full collation workflow, including single-PDF and grouped-ZIP outputs. Tests and VitePress documentation are also included.

Changes

Duplex Collate tool

Layer / File(s) Summary
Tool registration, i18n, and surface links
src/js/config/tools.ts, src/js/main.ts, public/locales/en/tools.json, public/locales/de/tools.json, tools.html, pdf-merge-split.html
Registers the Duplex Collate tool in the tool config and translation key map, adds duplexCollate name/subtitle strings to English and German locales, and adds tool cards/entries to the tools catalog and pdf-merge-split landing page.
Duplex Collate page HTML template
src/pages/duplex-collate.html
Defines the full page: head metadata, drop-zone upload card with odd-page warning banner, hidden duplex options panel (split-after-page input, back-order selector, auto-detect button, grouped export toggle with pages-per-document input), process button, and hidden processing/alert modals with ES module script wiring.
Client-side duplex collation logic
src/js/logic/duplex-collate-page.ts
Implements DOMContentLoaded event wiring, PDF upload/validation/password-load flow, filename helpers, UI visibility and odd-page banner helpers, exported buildDuplexOrder(totalPages, splitPoint, backOrder) that produces an interleaved page-index array, preview summary updates, PDF utility helpers (createPdfFromIndices, bytesToArrayBuffer), core processDuplexCollate workflow (single collated PDF or grouped ZIP with uneven-block confirmation), and resetState cleanup.
Tests and documentation
src/tests/duplex-collate.test.ts, docs/tools/duplex-collate.md, docs/.vitepress/config.mts, docs/tools/index.md
Adds four Vitest cases for buildDuplexOrder covering even/odd page counts and reverse/keep back-order modes, plus a new VitePress documentation page with sidebar and index entries.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DuplexCollatePage
    participant buildDuplexOrder
    participant pdfLib as pdf-lib
    participant JSZip

    User->>DuplexCollatePage: Upload PDF file
    DuplexCollatePage->>pdfLib: Load PDFDocument (with optional password)
    pdfLib-->>DuplexCollatePage: PDFDocument + pageCount
    DuplexCollatePage->>User: Show duplex options panel

    User->>DuplexCollatePage: Click "Collate PDF"
    DuplexCollatePage->>buildDuplexOrder: buildDuplexOrder(totalPages, splitPoint, backOrder)
    buildDuplexOrder-->>DuplexCollatePage: { order[], frontCount, backCount }

    alt front/back block sizes differ
        DuplexCollatePage->>User: Confirm uneven blocks
    end

    alt grouped export enabled
        loop per chunk
            DuplexCollatePage->>pdfLib: createPdfFromIndices(chunk)
            pdfLib-->>DuplexCollatePage: PDF bytes
            DuplexCollatePage->>JSZip: Add chunk PDF to archive
        end
        JSZip-->>DuplexCollatePage: ZIP blob
        DuplexCollatePage->>User: Download ZIP archive
    else single PDF
        DuplexCollatePage->>pdfLib: createPdfFromIndices(order)
        pdfLib-->>DuplexCollatePage: PDF bytes
        DuplexCollatePage->>User: Download collated PDF
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop hop, the scanner fed them all in line,
Front pages first, then backs in a great pile!
Now Duplex Collate weaves them intertwined,
front1, back1, front2 — oh how divine.
The bunny cheers: no more drag-and-drop toil,
Just click one button and watch the pages coil! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive The PR contains two minor out-of-scope changes unrelated to the Duplex Collate feature: updating .husky/pre-commit to use pinned Node.js version and adding .nvmrc version pin. These are infrastructure/tooling improvements not mentioned in issue #220. Consider moving the .husky/pre-commit and .nvmrc changes to a separate PR focused on dependency pinning to keep this feature-specific PR focused on the Duplex Collate implementation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature: adding a duplex sort/collate documents tool, which is directly aligned with the primary code change introducing the new Duplex Collate functionality across multiple files.
Description check ✅ Passed The description covers the key requirements from the template: it includes a summary with a visual screenshot, specifies the fix (Fixes #220), marks the type of change as a new feature, and provides testing details with expected and actual results, checklist verification, and example files.
Linked Issues check ✅ Passed The PR successfully implements all core requirements from issue #220: the Duplex Collate tool reorders duplex-scanned PDFs from (front1...frontN, back1...backN) into proper collated order (front1, back1, front2, back2...), with support for orientation correction and optional per-document separation into a ZIP archive.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@r0ckarong

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/tools/duplex-collate.md`:
- Around line 33-35: The current documentation for grouped mode on line 34
states it returns "one ZIP containing multiple PDFs" without clarifying the
behavior when only a single grouped chunk is produced. Update the grouped mode
description to explicitly note that a ZIP is returned only when multiple chunks
are created, but a single PDF is downloaded when the grouping results in only
one chunk. This will prevent user confusion about the output format based on the
actual chunking outcome.

In `@src/pages/duplex-collate.html`:
- Line 78: The HTMLHint linter is incorrectly flagging the `>` character in
valid Handlebars partial syntax `{{> navbar }}` as an unescaped spec character.
Add HTMLHint suppression comments above the affected lines (line 78 with the
navbar partial and line 268 with its similar partial reference) to tell HTMLHint
to ignore the spec-char-escape rule for these specific valid Handlebars
expressions, allowing the lint check to pass without blocking CI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 147b7565-a204-4126-8f72-7779dbb0ad3f

📥 Commits

Reviewing files that changed from the base of the PR and between 4b875a6 and f8e25d9.

📒 Files selected for processing (12)
  • docs/.vitepress/config.mts
  • docs/tools/duplex-collate.md
  • docs/tools/index.md
  • pdf-merge-split.html
  • public/locales/de/tools.json
  • public/locales/en/tools.json
  • src/js/config/tools.ts
  • src/js/logic/duplex-collate-page.ts
  • src/js/main.ts
  • src/pages/duplex-collate.html
  • src/tests/duplex-collate.test.ts
  • tools.html
Comment thread docs/tools/duplex-collate.md
Comment thread src/pages/duplex-collate.html
r0ckarong and others added 6 commits June 18, 2026 10:01
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Improve function-level documentation coverage for duplex collate page functions to satisfy documentation quality checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant