Skip to content

pdftopdf: fix back pages rotated 180° in long-edge duplex (#263) - #265

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
princemittalr:fix/pdftopdf-duplex-back-page-rotation
Oct 20, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
princemittalr:fix/pdftopdf-duplex-back-page-rotation

Conversation

@princemittalr

Copy link
Copy Markdown
Contributor

Fixes #263

Problem:
The hardcoded sheet_back = "rotated" in cfFilterPDFToPDF() was causing prepare_documents() to apply a 180° rotation transform to every back-side page when printing two-sided-long-edge. This made page 2, 4, etc. come out upside down.

Root cause:
Back-side orientation is already handled downstream by cfGetBackSideOrientation() in ghostscript.c, pdftoraster.c, pwgtoraster.c, pclmtoraster.c and rastertopwg.c. For PDF output that function always returns "normal". The old QPDF-based pdftopdf had no back-side transform at this stage.

The bug only became visible after commit 1973c4a (print-scaling=auto default, #237) stopped ordinary jobs from taking the fast-copy path that bypassed the transform.

Fix:
Change sheet_back from "rotated" to "normal".

Testing:

Built successfully against PDFio 1.6.4
The one-line change matches the fix suggested in issue #263 by the reporter
Landscape auto-rotation (#237) is unaffected by this change

Note: Not tested on a printer that genuinely requires a rotated back side. Maintainer review on that case is welcome.

@claudiodtbarros claudiodtbarros left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: duplex back-side orientation fix

Changing sheet_back from rotated to normal addresses the duplicate transformation identified in #263. The documented reproductions cover driverless queues, manufacturer PPDs, PDF and raster output, and a printer requiring a rotated back side. Based on that evidence and the validation below, the fix looks good to me.

Validation performed on c1690952c0536e3b4702b74739d0bdb618c6994a:

  • Successfully ran ./autogen.sh, ./configure --disable-mutool --disable-static, make -j2, and make check.
  • All 10 tests passed. The optional mutool integration was disabled because mutool was unavailable.
  • Confirmed all 15 CI checks passed, including Build & Test on x86_64, arm64, armv7, and riscv64, along with CodeQL and cppcheck.

Non-blocking follow-up: The existing test suite does not automatically verify back-side orientation. A targeted regression test would be useful once a suitable test harness is available.

The validation above applies to the original commit. The author has since reported rebasing onto current master at 7616418, with all 15 CI checks passing again; I have not repeated the local validation on that revision.

The N²-copy issue tracked in #271 is separate and should not block this fix.

The hardcoded sheet_back="rotated" was causing prepare_documents() to
apply a 180-degree rotation transform to every back-side page when
printing two-sided-long-edge. This is wrong: back-side orientation is
already handled downstream by cfGetBackSideOrientation() in
ghostscript.c, pdftoraster.c, pwgtoraster.c, pclmtoraster.c and
rastertopwg.c. For PDF output that function always returns "normal".

The old QPDF-based pdftopdf had no back-side transform. The bug only
became visible after commit 1973c4a (print-scaling=auto default, #237)
stopped ordinary jobs from taking the fast-copy path that bypassed
the transform.

Fixes: #263
@princemittalr
princemittalr force-pushed the fix/pdftopdf-duplex-back-page-rotation branch from c169095 to 7616418 Compare October 18, 2026 06:06
@princemittalr

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. I’ve rebased onto current master (the changed line is unchanged, head is now 7616418) and all 15 checks pass again. Agreed that back-side orientation needs a regression test; I’d prefer to add it in a follow-up once there’s a suitable harness, to keep this fix minimal. Maintainers: if anyone has a printer that needs the rotated back side, I’d welcome that check.

@YangtseSu

Copy link
Copy Markdown

Tested on hardware with https://aur.archlinux.org/packages/libcupsfilters-duplexfix (libcupsfilters 2.2.1.r32.gd49e9284 with only this change applied):

  • Printer: Pantum M7100DN (IPP Everywhere/AirPrint, urf-supported contains DM1), tested over a driverless queue (ipp(s)://…/ipp/print) and a vendor PostScript queue (socket://…:9100).
  • Long-edge duplex jobs printed from WPS Office: back side upright on both queues. With the distribution's unpatched library the same jobs print with the back side upside down.
  • Short edge, simplex and the PPD-only Duplex= path: unchanged.
  • Duplex flag in the generated image/urf stream (byte 14): unchanged (0x03 long edge, 0x02 short edge, 0x01 simplex).
  • make check: 14 pass, 1 skip, 0 fail.

@princemittalr

Copy link
Copy Markdown
Contributor Author

@tillkamppeter, a short status summary in case it helps with merging:

  • Reviewed and locally validated by @claudiodtbarros. All 15 checks pass on the rebased head (7616418), with no conflicts.
  • The case I hadn't tested, a printer that really needs a rotated back side, has been confirmed on hardware by @fenix0xf in pdftopdf: back pages upside down in long-edge duplex #263 (HP M479, DM3, *cupsBackSide: Rotated): long-edge duplex is correct with this change for both PDF and image/urf output.
  • Also confirmed on paper with Brother, Canon, Xerox and Pantum printers, on both driverless and vendor-PPD queues. Arch Linux is already shipping this patch in libcupsfilters (pkgrel 2).

I'm happy to add a regression test for back-side orientation in a follow-up, or to make any change you'd like here. Thanks!

@tillkamppeter
tillkamppeter merged commit c4d5dba into OpenPrinting:master Oct 20, 2026
15 checks passed
@tillkamppeter

Copy link
Copy Markdown
Member

I'm happy to add a regression test for back-side orientation in a follow-up, or to make any change you'd like here. Thanks!

Please do and post it in a new PR.

@princemittalr
princemittalr deleted the fix/pdftopdf-duplex-back-page-rotation branch October 20, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pdftopdf: back pages upside down in long-edge duplex

4 participants