bookPagePairs

fun bookPagePairs(pageCount: Int): List<List<Int>>

Computes the row layout for PdfPageLayout.TwoPageBook given a page count: a list of rows, each holding the zero-based page indices shown on that row.

The cover (index 0) is always alone so the remaining pages fall on natural verso/recto spreads (1-2, 3-4, … zero-based → 2-3, 4-5, … one-based). A trailing odd page is alone on the final row. A document with a single page yields one single-page row.

Pure logic with no Compose dependency so it is unit-testable on the JVM.

Examples (page indices, zero-based):

  • 1[[0]]

  • 2[[0], [1]]

  • 3[[0], [1, 2]]

  • 5[[0], [1, 2], [3, 4]]

  • 6[[0], [1, 2], [3, 4], [5]]