Skip to content

fix(compress): stop Ghostscript from turning pages in pass A - #210

Merged
nelsonduarte merged 1 commit into
mainfrom
fix/compress-gs-no-autorotate
Oct 17, 2026
Merged

nelsonduarte merged 1 commit into
mainfrom
fix/compress-gs-no-autorotate

Conversation

@nelsonduarte

Copy link
Copy Markdown
Owner

Summary

Pass A of Compress runs Ghostscript pdfwrite with -dPDFSETTINGS and no AutoRotatePages switch, so gs turns pages by the direction of their text:

  • /ebook, the default level in PDFApps, implies /All: it applies one rotation, that of the document's dominant text, to every page.
  • /screen implies /PageByPage: it turns each page to the direction of its own text.

This changes the orientation the user sees. The fix passes -dAutoRotatePages=/None right after -dPDFSETTINGS, on every level.

Files: app/utils.py, tests/test_compress_gs_autorotate.py (new, 11 tests).

Measurements

gs 10.05.0 on Windows and gs 10.06.0 on WSL Ubuntu gave identical results.

Fixture Preset Without the switch With the switch
Page 1 horizontal text, page 2 text at 90 degrees /ebook both pages turned 90 degrees clockwise, page 1 on its side no page turned
Page 1 horizontal text, page 2 text at 90 degrees /screen page 1 left alone, page 2 turned no page turned
Page 1 stored with /Rotate 90 /ebook that page upside down no page turned

The code comment also lists gs 9.55.0 among the versions it was measured on; that version was not re-checked for this change.

Tests

  • 3 tests check the pass A argv on each level with a faked gs (no Ghostscript needed).
  • 8 tests run the real gs on four fixtures under /ebook and /screen, and are skipped when no gs is found.
  • All 11 pass with the switch and all 11 fail without it.
  • Full suite: 1049 passed, 2 skipped.

🤖 Generated with Claude Code

Pass A of Compress runs Ghostscript pdfwrite with -dPDFSETTINGS and no
AutoRotatePages switch, so gs turns pages by the direction of their
text. /ebook, the default level in PDFApps, implies /All: it applies one
rotation, that of the document's dominant text, to every page. /screen
implies /PageByPage: it turns each page to the direction of its own
text. Either way the user can get pages in an orientation the source
did not have.

Pass -dAutoRotatePages=/None right after -dPDFSETTINGS, on every level.

Measured with gs 10.05.0 on Windows and gs 10.06.0 on WSL Ubuntu, with
identical results on both:
- two pages, page 1 with horizontal text and page 2 with text at 90
  degrees: without the switch, /ebook turned both pages 90 degrees
  clockwise, leaving page 1 on its side, and /screen left page 1 alone
  and turned page 2;
- page 1 stored with /Rotate 90: without the switch, /ebook left that
  page upside down;
- with the switch, no page turned on either version or preset.

The code comment also lists gs 9.55.0 among the versions it was measured
on; that version was not re-checked for this change.

tests/test_compress_gs_autorotate.py adds 11 tests: 3 check the pass A
argv on each level with a faked gs, 8 run the real gs on four fixtures
under /ebook and /screen and are skipped when no gs is found. All 11
pass with the switch and all 11 fail without it. Full suite: 1049
passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nelsonduarte
nelsonduarte merged commit c89786d into main Oct 17, 2026
5 checks passed
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.

1 participant